1 import * as jsToXliff12 from 'xliff/jsToXliff12'
2 import { writeFile } from 'fs-extra'
3 import { join } from 'path'
8 VIDEO_LICENCES, VIDEO_PLAYLIST_PRIVACIES, VIDEO_PLAYLIST_TYPES,
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 'Copy magnet URI': 'Copy magnet URI',
34 'Total downloaded: ': 'Total downloaded: ',
35 'Total uploaded: ': 'Total uploaded: '
37 const playerTranslations = {
38 target: join(__dirname, '../../../client/src/locale/source/player_en_US.xml'),
39 data: Object.assign({}, videojs, playerKeys)
43 const serverKeys: any = {}
44 values(VIDEO_CATEGORIES)
45 .concat(values(VIDEO_LICENCES))
46 .concat(values(VIDEO_PRIVACIES))
47 .concat(values(VIDEO_STATES))
48 .concat(values(VIDEO_IMPORT_STATES))
49 .concat(values(VIDEO_PLAYLIST_PRIVACIES))
50 .concat(values(VIDEO_PLAYLIST_TYPES))
52 'This video does not exist.',
53 'We cannot fetch the video. Please try again later.',
55 'This video is not available because the remote instance is not responding.'
57 .forEach(v => serverKeys[v] = v)
60 Object.assign(serverKeys, {
65 const serverTranslations = {
66 target: join(__dirname, '../../../client/src/locale/source/server_en_US.xml'),
71 const languageKeys: any = {}
72 const languages = buildLanguages()
73 Object.keys(languages).forEach(k => languageKeys[languages[k]] = languages[k])
75 const iso639Translations = {
76 target: join(__dirname, '../../../client/src/locale/source/iso639_en_US.xml'),
80 saveToXliffFile(playerTranslations, err => {
81 if (err) return handleError(err)
83 saveToXliffFile(serverTranslations, err => {
84 if (err) return handleError(err)
86 saveToXliffFile(iso639Translations, err => {
87 if (err) return handleError(err)
94 // Then, the server strings
96 function saveToXliffFile (jsonTranslations: TranslationType, cb: Function) {
102 Object.keys(jsonTranslations.data).forEach(k => obj.resources.namespace1[ k ] = { source: jsonTranslations.data[ k ] })
104 jsToXliff12(obj, (err, res) => {
105 if (err) return cb(err)
107 writeFile(jsonTranslations.target, res, err => {
108 if (err) return cb(err)
115 function handleError (err: any) {