1 import * as jsToXliff12 from 'xliff/jsToXliff12'
2 import { writeFile } from 'fs-extra'
3 import { join } from 'path'
11 } from '../../server/initializers/constants'
12 import { values } from 'lodash'
14 type TranslationType = {
16 data: { [id: string]: string }
19 const videojs = require(join(__dirname, '../../../client/src/locale/source/videojs_en_US.json'))
24 'Subtitles/CC': 'Subtitles/CC',
27 'Go to the video page': 'Go to the video page',
28 'Settings': 'Settings',
29 'Uses P2P, others may know you are watching this video.': 'Uses P2P, others may know you are watching this video.',
30 'Copy the video URL': 'Copy the video URL',
31 'Copy the video URL at the current time': 'Copy the video URL at the current time',
32 'Copy embed code': 'Copy embed code',
33 'Total downloaded: ': 'Total downloaded: ',
34 'Total uploaded: ': 'Total uploaded: '
36 const playerTranslations = {
37 target: join(__dirname, '../../../client/src/locale/source/player_en_US.xml'),
38 data: Object.assign({}, videojs, playerKeys)
42 const serverKeys: any = {}
43 values(VIDEO_CATEGORIES)
44 .concat(values(VIDEO_LICENCES))
45 .concat(values(VIDEO_PRIVACIES))
46 .concat(values(VIDEO_STATES))
47 .concat(values(VIDEO_IMPORT_STATES))
49 'This video does not exist.',
50 'We cannot fetch the video. Please try again later.',
52 'This video is not available because the remote instance is not responding.'
54 .forEach(v => serverKeys[v] = v)
57 Object.assign(serverKeys, {
62 const serverTranslations = {
63 target: join(__dirname, '../../../client/src/locale/source/server_en_US.xml'),
68 const languageKeys: any = {}
69 const languages = buildLanguages()
70 Object.keys(languages).forEach(k => languageKeys[languages[k]] = languages[k])
72 const iso639Translations = {
73 target: join(__dirname, '../../../client/src/locale/source/iso639_en_US.xml'),
77 saveToXliffFile(playerTranslations, err => {
78 if (err) return handleError(err)
80 saveToXliffFile(serverTranslations, err => {
81 if (err) return handleError(err)
83 saveToXliffFile(iso639Translations, err => {
84 if (err) return handleError(err)
91 // Then, the server strings
93 function saveToXliffFile (jsonTranslations: TranslationType, cb: Function) {
99 Object.keys(jsonTranslations.data).forEach(k => obj.resources.namespace1[ k ] = { source: jsonTranslations.data[ k ] })
101 jsToXliff12(obj, (err, res) => {
102 if (err) return cb(err)
104 writeFile(jsonTranslations.target, res, err => {
105 if (err) return cb(err)
112 function handleError (err: any) {