create-custom-files.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. import { writeJSON } from 'fs-extra'
  2. import { values } from 'lodash'
  3. import { join } from 'path'
  4. import { registerTSPaths } from '../../server/helpers/register-ts-paths'
  5. import {
  6. buildLanguages,
  7. VIDEO_CATEGORIES,
  8. VIDEO_IMPORT_STATES,
  9. VIDEO_LICENCES,
  10. VIDEO_PLAYLIST_PRIVACIES,
  11. VIDEO_PLAYLIST_TYPES,
  12. VIDEO_PRIVACIES,
  13. VIDEO_STATES
  14. } from '../../server/initializers/constants'
  15. import { I18N_LOCALES } from '../../shared/core-utils/i18n'
  16. registerTSPaths()
  17. const videojs = require(join(__dirname, '../../../client/src/locale/videojs.en-US.json'))
  18. const playerKeys = {
  19. 'Quality': 'Quality',
  20. 'Auto': 'Auto',
  21. 'Speed': 'Speed',
  22. 'Subtitles/CC': 'Subtitles/CC',
  23. 'peers': 'peers',
  24. 'peer': 'peer',
  25. 'Go to the video page': 'Go to the video page',
  26. 'Settings': 'Settings',
  27. 'Watching this video may reveal your IP address to others.': 'Watching this video may reveal your IP address to others.',
  28. 'Copy the video URL': 'Copy the video URL',
  29. 'Copy the video URL at the current time': 'Copy the video URL at the current time',
  30. 'Copy embed code': 'Copy embed code',
  31. 'Copy magnet URI': 'Copy magnet URI',
  32. 'Total downloaded: ': 'Total downloaded: ',
  33. 'Total uploaded: ': 'Total uploaded: ',
  34. 'From servers: ': 'From servers: ',
  35. 'From peers: ': 'From peers: ',
  36. 'Normal mode': 'Normal mode',
  37. 'Theater mode': 'Theater mode'
  38. }
  39. Object.assign(playerKeys, videojs)
  40. // Server keys
  41. const serverKeys: any = {}
  42. values(VIDEO_CATEGORIES)
  43. .concat(values(VIDEO_LICENCES))
  44. .concat(values(VIDEO_PRIVACIES))
  45. .concat(values(VIDEO_STATES))
  46. .concat(values(VIDEO_IMPORT_STATES))
  47. .concat(values(VIDEO_PLAYLIST_PRIVACIES))
  48. .concat(values(VIDEO_PLAYLIST_TYPES))
  49. .concat([
  50. 'This video does not exist.',
  51. 'We cannot fetch the video. Please try again later.',
  52. 'Sorry',
  53. 'This video is not available because the remote instance is not responding.',
  54. 'This playlist does not exist',
  55. 'We cannot fetch the playlist. Please try again later.',
  56. 'Playlist: {1}',
  57. 'By {1}',
  58. 'Unavailable video'
  59. ])
  60. .forEach(v => { serverKeys[v] = v })
  61. // More keys
  62. Object.assign(serverKeys, {
  63. Misc: 'Misc',
  64. Unknown: 'Unknown'
  65. })
  66. // ISO 639 keys
  67. const languageKeys: any = {}
  68. const languages = buildLanguages()
  69. Object.keys(languages).forEach(k => { languageKeys[languages[k]] = languages[k] })
  70. Object.assign(serverKeys, languageKeys)
  71. writeAll().catch(err => {
  72. console.error(err)
  73. process.exit(-1)
  74. })
  75. async function writeAll () {
  76. const localePath = join(__dirname, '../../../client/src/locale')
  77. await writeJSON(join(localePath, 'player.en-US.json'), playerKeys, { spaces: 4 })
  78. await writeJSON(join(localePath, 'server.en-US.json'), serverKeys, { spaces: 4 })
  79. for (const key of Object.keys(I18N_LOCALES)) {
  80. const playerJsonPath = join(localePath, `player.${key}.json`)
  81. const translatedPlayer = require(playerJsonPath)
  82. const newTranslatedPlayer = Object.assign({}, playerKeys, translatedPlayer)
  83. await writeJSON(playerJsonPath, newTranslatedPlayer, { spaces: 4 })
  84. const serverJsonPath = join(localePath, `server.${key}.json`)
  85. const translatedServer = require(serverJsonPath)
  86. const newTranslatedServer = Object.assign({}, serverKeys, translatedServer)
  87. await writeJSON(serverJsonPath, newTranslatedServer, { spaces: 4 })
  88. }
  89. }