create-custom-files.ts 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. import { readJsonSync, writeJSON } from 'fs-extra/esm'
  2. import { join } from 'path'
  3. import { I18N_LOCALES, USER_ROLE_LABELS } from '@peertube/peertube-core-utils'
  4. import { root } from '@peertube/peertube-node-utils'
  5. import {
  6. ABUSE_STATES,
  7. buildLanguages,
  8. RUNNER_JOB_STATES,
  9. USER_EXPORT_STATES,
  10. USER_REGISTRATION_STATES,
  11. VIDEO_CATEGORIES,
  12. VIDEO_CHANNEL_SYNC_STATE,
  13. VIDEO_IMPORT_STATES,
  14. VIDEO_LICENCES,
  15. VIDEO_PLAYLIST_PRIVACIES,
  16. VIDEO_PLAYLIST_TYPES,
  17. VIDEO_PRIVACIES,
  18. USER_IMPORT_STATES,
  19. VIDEO_STATES
  20. } from '@peertube/peertube-server/core/initializers/constants.js'
  21. const videojs = readJsonSync(join(root(), 'client', 'src', 'locale', 'videojs.en-US.json'))
  22. const playerKeys = {
  23. 'Quality': 'Quality',
  24. 'Auto': 'Auto',
  25. 'Speed': 'Speed',
  26. 'Subtitles/CC': 'Subtitles/CC',
  27. 'peers': 'peers',
  28. 'peer': 'peer',
  29. 'Go to the video page': 'Go to the video page',
  30. 'Settings': 'Settings',
  31. 'Watching this video may reveal your IP address to others.': 'Watching this video may reveal your IP address to others.',
  32. 'Copy the video URL': 'Copy the video URL',
  33. 'Copy the video URL at the current time': 'Copy the video URL at the current time',
  34. 'Copy embed code': 'Copy embed code',
  35. 'Copy magnet URI': 'Copy magnet URI',
  36. 'Total downloaded: ': 'Total downloaded: ',
  37. 'Total uploaded: ': 'Total uploaded: ',
  38. 'From servers: ': 'From servers: ',
  39. 'From peers: ': 'From peers: ',
  40. 'Normal mode': 'Normal mode',
  41. 'Stats for nerds': 'Stats for nerds',
  42. 'Theater mode': 'Theater mode',
  43. 'Video UUID': 'Video UUID',
  44. 'Viewport / Frames': 'Viewport / Frames',
  45. 'Resolution': 'Resolution',
  46. 'Volume': 'Volume',
  47. 'Codecs': 'Codecs',
  48. 'Color': 'Color',
  49. 'Go back to the live': 'Go back to the live',
  50. 'Connection Speed': 'Connection Speed',
  51. 'Network Activity': 'Network Activity',
  52. 'Total Transfered': 'Total Transfered',
  53. 'Download Breakdown': 'Download Breakdown',
  54. 'Buffer Progress': 'Buffer Progress',
  55. 'Buffer State': 'Buffer State',
  56. 'Live Latency': 'Live Latency',
  57. 'P2P': 'P2P',
  58. '{1} seconds': '{1} seconds',
  59. 'enabled': 'enabled',
  60. 'Playlist: {1}': 'Playlist: {1}',
  61. 'disabled': 'disabled',
  62. ' off': ' off',
  63. 'Player mode': 'Player mode',
  64. 'Play in loop': 'Play in loop',
  65. 'This live is not currently streaming.': 'This live is not currently streaming.',
  66. 'This live has ended.': 'This live has ended.',
  67. 'The video failed to play, will try to fast forward.': 'The video failed to play, will try to fast forward.',
  68. '{1} / {2} dropped of {3}': '{1} / {2} dropped of {3}',
  69. ' (muted)': ' (muted)',
  70. '{1} from servers · {2} from peers': '{1} from servers · {2} from peers',
  71. 'Previous video': 'Previous video',
  72. 'Video page (new window)': 'Video page (new window)',
  73. 'Next video': 'Next video',
  74. 'This video is password protected': 'This video is password protected',
  75. 'You need a password to watch this video.': 'You need a password to watch this video.',
  76. 'Incorrect password, please enter a correct password': 'Incorrect password, please enter a correct password',
  77. 'Cancel': 'Cancel',
  78. 'Up Next': 'Up Next',
  79. 'Autoplay is suspended': 'Autoplay is suspended',
  80. '{1} (from edge: {2})': '{1} (from edge: {2})',
  81. 'Disable subtitles': 'Disable subtitles',
  82. 'Enable {1} subtitle': 'Enable {1} subtitle',
  83. '{1} (auto-generated)': '{1} (auto-generated)',
  84. 'Go back': 'Go back',
  85. 'Audio only': 'Audio only'
  86. }
  87. Object.assign(playerKeys, videojs)
  88. // Server keys
  89. const serverKeys: any = {}
  90. Object.values(VIDEO_CATEGORIES)
  91. .concat(Object.values(VIDEO_LICENCES))
  92. .concat(Object.values(VIDEO_PRIVACIES))
  93. .concat(Object.values(VIDEO_STATES))
  94. .concat(Object.values(VIDEO_IMPORT_STATES))
  95. .concat(Object.values(VIDEO_PLAYLIST_PRIVACIES))
  96. .concat(Object.values(VIDEO_PLAYLIST_TYPES))
  97. .concat(Object.values(USER_ROLE_LABELS))
  98. .concat(Object.values(VIDEO_CHANNEL_SYNC_STATE))
  99. .concat(Object.values(ABUSE_STATES))
  100. .concat(Object.values(USER_REGISTRATION_STATES))
  101. .concat(Object.values(RUNNER_JOB_STATES))
  102. .concat(Object.values(USER_EXPORT_STATES))
  103. .concat(Object.values(USER_IMPORT_STATES))
  104. .concat([
  105. 'This video does not exist.',
  106. 'We cannot fetch the video. Please try again later.',
  107. 'Sorry',
  108. 'This video is not available because the remote instance is not responding.',
  109. 'This playlist does not exist',
  110. 'We cannot fetch the playlist. Please try again later.',
  111. 'Playlist: {1}',
  112. 'By {1}',
  113. 'Unavailable video'
  114. ])
  115. .forEach(v => { serverKeys[v] = v })
  116. // More keys
  117. Object.assign(serverKeys, {
  118. Unknown: 'Unknown'
  119. })
  120. // ISO 639 keys
  121. const languageKeys: any = {}
  122. const languages = buildLanguages()
  123. Object.keys(languages).forEach(k => { languageKeys[languages[k]] = languages[k] })
  124. Object.assign(serverKeys, languageKeys)
  125. writeAll().catch(err => {
  126. console.error(err)
  127. process.exit(-1)
  128. })
  129. async function writeAll () {
  130. const localePath = join(root(), 'client', 'src', 'locale')
  131. await writeJSON(join(localePath, 'player.en-US.json'), playerKeys, { spaces: 4 })
  132. await writeJSON(join(localePath, 'server.en-US.json'), serverKeys, { spaces: 4 })
  133. for (const key of Object.keys(I18N_LOCALES)) {
  134. const playerJsonPath = join(localePath, `player.${key}.json`)
  135. const translatedPlayer = readJsonSync(playerJsonPath)
  136. const newTranslatedPlayer = Object.assign({}, playerKeys, translatedPlayer)
  137. await writeJSON(playerJsonPath, newTranslatedPlayer, { spaces: 4 })
  138. const serverJsonPath = join(localePath, `server.${key}.json`)
  139. const translatedServer = readJsonSync(serverJsonPath)
  140. const newTranslatedServer = Object.assign({}, serverKeys, translatedServer)
  141. await writeJSON(serverJsonPath, newTranslatedServer, { spaces: 4 })
  142. }
  143. }