create-custom-files.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import * as jsToXliff12 from 'xliff/jsToXliff12'
  2. import { writeFile } from 'fs-extra'
  3. import { join } from 'path'
  4. import {
  5. buildLanguages,
  6. VIDEO_CATEGORIES,
  7. VIDEO_IMPORT_STATES,
  8. VIDEO_LICENCES, VIDEO_PLAYLIST_PRIVACIES, VIDEO_PLAYLIST_TYPES,
  9. VIDEO_PRIVACIES,
  10. VIDEO_STATES
  11. } from '../../server/initializers/constants'
  12. import { values } from 'lodash'
  13. type TranslationType = {
  14. target: string
  15. data: { [id: string]: string }
  16. }
  17. const videojs = require(join(__dirname, '../../../client/src/locale/source/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. 'Uses P2P, others may know you are watching this video.': 'Uses P2P, others may know you are watching this video.',
  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. }
  35. const playerTranslations = {
  36. target: join(__dirname, '../../../client/src/locale/source/player_en_US.xml'),
  37. data: Object.assign({}, videojs, playerKeys)
  38. }
  39. // Server keys
  40. const serverKeys: any = {}
  41. values(VIDEO_CATEGORIES)
  42. .concat(values(VIDEO_LICENCES))
  43. .concat(values(VIDEO_PRIVACIES))
  44. .concat(values(VIDEO_STATES))
  45. .concat(values(VIDEO_IMPORT_STATES))
  46. .concat(values(VIDEO_PLAYLIST_PRIVACIES))
  47. .concat(values(VIDEO_PLAYLIST_TYPES))
  48. .concat([
  49. 'This video does not exist.',
  50. 'We cannot fetch the video. Please try again later.',
  51. 'Sorry',
  52. 'This video is not available because the remote instance is not responding.'
  53. ])
  54. .forEach(v => serverKeys[v] = v)
  55. // More keys
  56. Object.assign(serverKeys, {
  57. 'Misc': 'Misc',
  58. 'Unknown': 'Unknown'
  59. })
  60. const serverTranslations = {
  61. target: join(__dirname, '../../../client/src/locale/source/server_en_US.xml'),
  62. data: serverKeys
  63. }
  64. // ISO 639 keys
  65. const languageKeys: any = {}
  66. const languages = buildLanguages()
  67. Object.keys(languages).forEach(k => languageKeys[languages[k]] = languages[k])
  68. const iso639Translations = {
  69. target: join(__dirname, '../../../client/src/locale/source/iso639_en_US.xml'),
  70. data: languageKeys
  71. }
  72. saveToXliffFile(playerTranslations, err => {
  73. if (err) return handleError(err)
  74. saveToXliffFile(serverTranslations, err => {
  75. if (err) return handleError(err)
  76. saveToXliffFile(iso639Translations, err => {
  77. if (err) return handleError(err)
  78. process.exit(0)
  79. })
  80. })
  81. })
  82. // Then, the server strings
  83. function saveToXliffFile (jsonTranslations: TranslationType, cb: Function) {
  84. const obj = {
  85. resources: {
  86. namespace1: {}
  87. }
  88. }
  89. Object.keys(jsonTranslations.data).forEach(k => obj.resources.namespace1[ k ] = { source: jsonTranslations.data[ k ] })
  90. jsToXliff12(obj, (err, res) => {
  91. if (err) return cb(err)
  92. writeFile(jsonTranslations.target, res, err => {
  93. if (err) return cb(err)
  94. return cb(null)
  95. })
  96. })
  97. }
  98. function handleError (err: any) {
  99. console.error(err)
  100. process.exit(-1)
  101. }