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',
26 'Go to the video page': 'Go to the video page',
27 'Settings': 'Settings',
28 'Uses P2P, others may know you are watching this video.': 'Uses P2P, others may know you are watching this video.',
29 'Copy the video URL': 'Copy the video URL',
30 'Copy the video URL at the current time': 'Copy the video URL at the current time',
31 'Copy embed code': 'Copy embed code'
33 const playerTranslations = {
34 target: join(__dirname, '../../../client/src/locale/source/player_en_US.xml'),
35 data: Object.assign({}, videojs, playerKeys)
39 const serverKeys: any = {}
40 values(VIDEO_CATEGORIES)
41 .concat(values(VIDEO_LICENCES))
42 .concat(values(VIDEO_PRIVACIES))
43 .concat(values(VIDEO_STATES))
44 .concat(values(VIDEO_IMPORT_STATES))
45 .forEach(v => serverKeys[v] = v)
48 Object.assign(serverKeys, {
53 const serverTranslations = {
54 target: join(__dirname, '../../../client/src/locale/source/server_en_US.xml'),
59 const languageKeys: any = {}
60 const languages = buildLanguages()
61 Object.keys(languages).forEach(k => languageKeys[languages[k]] = languages[k])
63 const iso639Translations = {
64 target: join(__dirname, '../../../client/src/locale/source/iso639_en_US.xml'),
68 saveToXliffFile(playerTranslations, err => {
69 if (err) return handleError(err)
71 saveToXliffFile(serverTranslations, err => {
72 if (err) return handleError(err)
74 saveToXliffFile(iso639Translations, err => {
75 if (err) return handleError(err)
82 // Then, the server strings
84 function saveToXliffFile (jsonTranslations: TranslationType, cb: Function) {
90 Object.keys(jsonTranslations.data).forEach(k => obj.resources.namespace1[ k ] = { source: jsonTranslations.data[ k ] })
92 jsToXliff12(obj, (err, res) => {
93 if (err) return cb(err)
95 writeFile(jsonTranslations.target, res, err => {
96 if (err) return cb(err)
103 function handleError (err: any) {