PeerTube/scripts/i18n/create-custom-files.ts

126 lines
4.1 KiB
TypeScript
Raw Normal View History

2019-11-07 09:45:14 +01:00
import { writeJSON } from 'fs-extra'
2020-08-14 09:32:20 +02:00
import { values } from 'lodash'
2018-06-06 14:23:40 +02:00
import { join } from 'path'
import { root } from '@shared/core-utils'
2018-08-03 10:26:47 +02:00
import {
buildLanguages,
VIDEO_CATEGORIES,
VIDEO_IMPORT_STATES,
2019-11-07 09:45:14 +01:00
VIDEO_LICENCES,
VIDEO_PLAYLIST_PRIVACIES,
VIDEO_PLAYLIST_TYPES,
2018-08-03 10:26:47 +02:00
VIDEO_PRIVACIES,
VIDEO_STATES
} from '../../server/initializers/constants'
2020-08-14 09:32:20 +02:00
import { I18N_LOCALES } from '../../shared/core-utils/i18n'
2018-06-06 14:23:40 +02:00
const videojs = require(join(root(), 'client', 'src', 'locale', 'videojs.en-US.json'))
2018-06-06 14:23:40 +02:00
const playerKeys = {
'Quality': 'Quality',
'Auto': 'Auto',
'Speed': 'Speed',
2018-07-13 18:21:19 +02:00
'Subtitles/CC': 'Subtitles/CC',
2018-06-06 14:23:40 +02:00
'peers': 'peers',
2019-01-29 08:37:25 +01:00
'peer': 'peer',
2018-06-06 14:23:40 +02:00
'Go to the video page': 'Go to the video page',
'Settings': 'Settings',
2020-07-20 17:05:08 +02:00
'Watching this video may reveal your IP address to others.': 'Watching this video may reveal your IP address to others.',
2018-06-06 14:23:40 +02:00
'Copy the video URL': 'Copy the video URL',
'Copy the video URL at the current time': 'Copy the video URL at the current time',
'Copy embed code': 'Copy embed code',
2019-02-15 10:57:59 +01:00
'Copy magnet URI': 'Copy magnet URI',
2019-01-29 08:37:25 +01:00
'Total downloaded: ': 'Total downloaded: ',
2020-11-09 16:29:58 +01:00
'Total uploaded: ': 'Total uploaded: ',
2020-12-04 16:37:21 +01:00
'From servers: ': 'From servers: ',
'From peers: ': 'From peers: ',
2020-11-09 16:29:58 +01:00
'Normal mode': 'Normal mode',
2021-04-27 15:50:29 +02:00
'Stats for nerds': 'Stats for nerds',
'Theater mode': 'Theater mode',
'Video UUID': 'Video UUID',
'Viewport / Frames': 'Viewport / Frames',
'Resolution': 'Resolution',
'Volume': 'Volume',
'Codecs': 'Codecs',
'Color': 'Color',
'Connection Speed': 'Connection Speed',
'Network Activity': 'Network Activity',
'Total Transfered': 'Total Transfered',
'Download Breakdown': 'Download Breakdown',
'Buffer Progress': 'Buffer Progress',
'Buffer State': 'Buffer State',
2021-04-28 09:07:57 +02:00
'Live Latency': 'Live Latency',
'P2P': 'P2P',
2022-01-12 15:07:21 +01:00
'{1} seconds': '{1} seconds',
'enabled': 'enabled',
2022-01-12 15:07:21 +01:00
'Playlist: {1}': 'Playlist: {1}',
'disabled': 'disabled',
2021-10-21 11:01:10 +02:00
' off': ' off',
2022-02-02 11:16:23 +01:00
'Player mode': 'Player mode',
2022-05-04 09:18:39 +02:00
'Play in loop': 'Play in loop',
'This live has not started yet.': 'This live has not started yet.',
'This live has ended.': 'This live has ended.',
2022-02-02 11:16:23 +01:00
'The video failed to play, will try to fast forward.': 'The video failed to play, will try to fast forward.'
2018-06-06 14:23:40 +02:00
}
2019-11-07 09:45:14 +01:00
Object.assign(playerKeys, videojs)
2018-06-06 14:23:40 +02:00
2018-06-06 16:46:42 +02:00
// Server keys
const serverKeys: any = {}
values(VIDEO_CATEGORIES)
.concat(values(VIDEO_LICENCES))
.concat(values(VIDEO_PRIVACIES))
2018-08-03 10:26:47 +02:00
.concat(values(VIDEO_STATES))
.concat(values(VIDEO_IMPORT_STATES))
2019-03-06 15:36:44 +01:00
.concat(values(VIDEO_PLAYLIST_PRIVACIES))
.concat(values(VIDEO_PLAYLIST_TYPES))
.concat([
'This video does not exist.',
'We cannot fetch the video. Please try again later.',
'Sorry',
2020-08-04 11:42:06 +02:00
'This video is not available because the remote instance is not responding.',
'This playlist does not exist',
2020-08-05 09:44:58 +02:00
'We cannot fetch the playlist. Please try again later.',
'Playlist: {1}',
'By {1}',
2020-11-09 16:29:58 +01:00
'Unavailable video'
])
2020-07-30 14:54:31 +02:00
.forEach(v => { serverKeys[v] = v })
2018-06-06 16:46:42 +02:00
// More keys
Object.assign(serverKeys, {
2020-07-30 14:54:31 +02:00
Misc: 'Misc',
Unknown: 'Unknown'
2018-06-06 16:46:42 +02:00
})
// ISO 639 keys
const languageKeys: any = {}
const languages = buildLanguages()
2020-07-30 14:54:31 +02:00
Object.keys(languages).forEach(k => { languageKeys[languages[k]] = languages[k] })
2019-11-07 09:45:14 +01:00
Object.assign(serverKeys, languageKeys)
2020-08-14 09:32:20 +02:00
writeAll().catch(err => {
2018-06-06 16:46:42 +02:00
console.error(err)
process.exit(-1)
2019-11-07 09:45:14 +01:00
})
2020-08-14 09:32:20 +02:00
async function writeAll () {
const localePath = join(root(), 'client', 'src', 'locale')
2020-08-14 09:32:20 +02:00
await writeJSON(join(localePath, 'player.en-US.json'), playerKeys, { spaces: 4 })
await writeJSON(join(localePath, 'server.en-US.json'), serverKeys, { spaces: 4 })
for (const key of Object.keys(I18N_LOCALES)) {
const playerJsonPath = join(localePath, `player.${key}.json`)
const translatedPlayer = require(playerJsonPath)
const newTranslatedPlayer = Object.assign({}, playerKeys, translatedPlayer)
await writeJSON(playerJsonPath, newTranslatedPlayer, { spaces: 4 })
const serverJsonPath = join(localePath, `server.${key}.json`)
const translatedServer = require(serverJsonPath)
const newTranslatedServer = Object.assign({}, serverKeys, translatedServer)
await writeJSON(serverJsonPath, newTranslatedServer, { spaces: 4 })
}
}