1 import * as jsToXliff12 from 'xliff/jsToXliff12'
2 import { writeFile } from 'fs'
3 import { join } from 'path'
4 import { buildLanguages, VIDEO_CATEGORIES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../server/initializers/constants'
5 import { values } from 'lodash'
7 type TranslationType = {
9 data: { [id: string]: string }
12 const videojs = require(join(__dirname, '../../../client/src/locale/source/videojs_en_US.json'))
17 'Subtitles/CC': 'Subtitles/CC',
19 'Go to the video page': 'Go to the video page',
20 'Settings': 'Settings',
21 'Uses P2P, others may know you are watching this video.': 'Uses P2P, others may know you are watching this video.',
22 'Copy the video URL': 'Copy the video URL',
23 'Copy the video URL at the current time': 'Copy the video URL at the current time',
24 'Copy embed code': 'Copy embed code'
26 const playerTranslations = {
27 target: join(__dirname, '../../../client/src/locale/source/player_en_US.xml'),
28 data: Object.assign({}, videojs, playerKeys)
32 const serverKeys: any = {}
33 values(VIDEO_CATEGORIES)
34 .concat(values(VIDEO_LICENCES))
35 .concat(values(VIDEO_PRIVACIES))
36 .forEach(v => serverKeys[v] = v)
39 Object.assign(serverKeys, {
44 const serverTranslations = {
45 target: join(__dirname, '../../../client/src/locale/source/server_en_US.xml'),
50 const languageKeys: any = {}
51 const languages = buildLanguages()
52 Object.keys(languages).forEach(k => languageKeys[languages[k]] = languages[k])
54 const iso639Translations = {
55 target: join(__dirname, '../../../client/src/locale/source/iso639_en_US.xml'),
59 saveToXliffFile(playerTranslations, err => {
60 if (err) return handleError(err)
62 saveToXliffFile(serverTranslations, err => {
63 if (err) return handleError(err)
65 saveToXliffFile(iso639Translations, err => {
66 if (err) return handleError(err)
73 // Then, the server strings
75 function saveToXliffFile (jsonTranslations: TranslationType, cb: Function) {
81 Object.keys(jsonTranslations.data).forEach(k => obj.resources.namespace1[ k ] = { source: jsonTranslations.data[ k ] })
83 jsToXliff12(obj, (err, res) => {
84 if (err) return cb(err)
86 writeFile(jsonTranslations.target, res, err => {
87 if (err) return cb(err)
94 function handleError (err: any) {