]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - scripts/i18n/create-custom-files.ts
Add missing translations in embed template
[github/Chocobozzz/PeerTube.git] / scripts / i18n / create-custom-files.ts
1 import * as jsToXliff12 from 'xliff/jsToXliff12'
2 import { writeFile } from 'fs-extra'
3 import { join } from 'path'
4 import {
5 buildLanguages,
6 VIDEO_CATEGORIES,
7 VIDEO_IMPORT_STATES,
8 VIDEO_LICENCES,
9 VIDEO_PRIVACIES,
10 VIDEO_STATES
11 } from '../../server/initializers/constants'
12 import { values } from 'lodash'
13
14 type TranslationType = {
15 target: string
16 data: { [id: string]: string }
17 }
18
19 const videojs = require(join(__dirname, '../../../client/src/locale/source/videojs_en_US.json'))
20 const playerKeys = {
21 'Quality': 'Quality',
22 'Auto': 'Auto',
23 'Speed': 'Speed',
24 'Subtitles/CC': 'Subtitles/CC',
25 'peers': 'peers',
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'
32 }
33 const playerTranslations = {
34 target: join(__dirname, '../../../client/src/locale/source/player_en_US.xml'),
35 data: Object.assign({}, videojs, playerKeys)
36 }
37
38 // Server keys
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 .concat([
46 'This video does not exist.',
47 'We cannot fetch the video. Please try again later.',
48 'Sorry',
49 'This video is not available because the remote instance is not responding.'
50 ])
51 .forEach(v => serverKeys[v] = v)
52
53 // More keys
54 Object.assign(serverKeys, {
55 'Misc': 'Misc',
56 'Unknown': 'Unknown'
57 })
58
59 const serverTranslations = {
60 target: join(__dirname, '../../../client/src/locale/source/server_en_US.xml'),
61 data: serverKeys
62 }
63
64 // ISO 639 keys
65 const languageKeys: any = {}
66 const languages = buildLanguages()
67 Object.keys(languages).forEach(k => languageKeys[languages[k]] = languages[k])
68
69 const iso639Translations = {
70 target: join(__dirname, '../../../client/src/locale/source/iso639_en_US.xml'),
71 data: languageKeys
72 }
73
74 saveToXliffFile(playerTranslations, err => {
75 if (err) return handleError(err)
76
77 saveToXliffFile(serverTranslations, err => {
78 if (err) return handleError(err)
79
80 saveToXliffFile(iso639Translations, err => {
81 if (err) return handleError(err)
82
83 process.exit(0)
84 })
85 })
86 })
87
88 // Then, the server strings
89
90 function saveToXliffFile (jsonTranslations: TranslationType, cb: Function) {
91 const obj = {
92 resources: {
93 namespace1: {}
94 }
95 }
96 Object.keys(jsonTranslations.data).forEach(k => obj.resources.namespace1[ k ] = { source: jsonTranslations.data[ k ] })
97
98 jsToXliff12(obj, (err, res) => {
99 if (err) return cb(err)
100
101 writeFile(jsonTranslations.target, res, err => {
102 if (err) return cb(err)
103
104 return cb(null)
105 })
106 })
107 }
108
109 function handleError (err: any) {
110 console.error(err)
111 process.exit(-1)
112 }