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'))
18 'Go to the video page': 'Go to the video page',
19 'Settings': 'Settings',
20 'Uses P2P, others may know you are watching this video.': 'Uses P2P, others may know you are watching this video.',
21 'Copy the video URL': 'Copy the video URL',
22 'Copy the video URL at the current time': 'Copy the video URL at the current time',
23 'Copy embed code': 'Copy embed code'
25 const playerTranslations = {
26 target: join(__dirname, '../../../client/src/locale/source/player_en_US.xml'),
27 data: Object.assign({}, videojs, playerKeys)
31 const serverKeys: any = {}
32 values(VIDEO_CATEGORIES)
33 .concat(values(VIDEO_LICENCES))
34 .concat(values(VIDEO_PRIVACIES))
35 .forEach(v => serverKeys[v] = v)
38 Object.assign(serverKeys, {
43 const serverTranslations = {
44 target: join(__dirname, '../../../client/src/locale/source/server_en_US.xml'),
49 const languageKeys: any = {}
50 const languages = buildLanguages()
51 Object.keys(languages).forEach(k => languageKeys[languages[k]] = languages[k])
53 const iso639Translations = {
54 target: join(__dirname, '../../../client/src/locale/source/iso639_en_US.xml'),
58 saveToXliffFile(playerTranslations, err => {
59 if (err) return handleError(err)
61 saveToXliffFile(serverTranslations, err => {
62 if (err) return handleError(err)
64 saveToXliffFile(iso639Translations, err => {
65 if (err) return handleError(err)
72 // Then, the server strings
74 function saveToXliffFile (jsonTranslations: TranslationType, cb: Function) {
80 Object.keys(jsonTranslations.data).forEach(k => obj.resources.namespace1[ k ] = { source: jsonTranslations.data[ k ] })
82 jsToXliff12(obj, (err, res) => {
83 if (err) return cb(err)
85 writeFile(jsonTranslations.target, res, err => {
86 if (err) return cb(err)
93 function handleError (err: any) {