1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-05 10:49:28 +02:00

Localize player

This commit is contained in:
Chocobozzz 2018-06-06 14:23:40 +02:00
parent 550a562cec
commit e945b184a0
No known key found for this signature in database
GPG key ID: 583A612D890159BE
23 changed files with 1049 additions and 61 deletions

View file

@ -0,0 +1,49 @@
import * as jsToXliff12 from 'xliff/jsToXliff12'
import { writeFile } from 'fs'
import { join } from 'path'
// First, the player
const playerSource = join(__dirname, '../../../client/src/locale/source/videojs_en_US.json')
const playerTarget = join(__dirname, '../../../client/src/locale/source/player_en_US.xml')
const videojs = require(playerSource)
const playerKeys = {
'Quality': 'Quality',
'Auto': 'Auto',
'Speed': 'Speed',
'peers': 'peers',
'Go to the video page': 'Go to the video page',
'Settings': 'Settings',
'Uses P2P, others may know you are watching this video.': 'Uses P2P, others may know you are watching this video.',
'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'
}
const obj = {
resources: {
namespace1: {}
}
}
for (const sourceObject of [ videojs, playerKeys ]) {
Object.keys(sourceObject).forEach(k => obj.resources.namespace1[ k ] = { source: sourceObject[ k ] })
}
jsToXliff12(obj, (err, res) => {
if (err) {
console.error(err)
process.exit(-1)
}
writeFile(playerTarget, res, err => {
if (err) {
console.error(err)
process.exit(-1)
}
process.exit(0)
})
})
// Then, the server strings

View file

@ -9,4 +9,8 @@ npm run ngx-extractor -- --locale "en-US" -i 'src/**/*.ts' -f xlf -o src/locale/
# Zanata does not support inner elements in <source>, so we hack these special elements
# This regex translate the Angular elements to special entities (that we will reconvert on pull)
#sed -i 's/<x id=\(.\+\?\)\/>/\&lt;x id=\1\/\&gt;/g' src/locale/source/messages_en_US.xml
perl -pi -e 's|<x id=(.+?)/>|&lt;x id=\1/&gt;|g' src/locale/source/messages_en_US.xml
perl -pi -e 's|<x id=(.+?)/>|&lt;x id=\1/&gt;|g' src/locale/source/messages_en_US.xml
# Add our strings too
cd ../
npm run i18n:create-custom-files

View file

@ -7,5 +7,7 @@ set -eu
#sed -i 's/\&lt;x id=\(.\+\?\)\/\&gt;/<x id=\1\/>/g' client/src/locale/target/*
for i in 1 2 3; do
perl -pi -e 's|&lt;x id=(.+?)/&gt;([^"])|<x id=\1/>\2|g' client/src/locale/target/*
done
perl -pi -e 's|&lt;x id=(.+?)/&gt;([^"])|<x id=\1/>\2|g' client/src/locale/target/*.xml
done
npm run i18n:xliff2json

42
scripts/i18n/xliff2json.ts Executable file
View file

@ -0,0 +1,42 @@
import * as xliff12ToJs from 'xliff/xliff12ToJs'
import { readFileSync, writeFile } from 'fs'
import { join } from 'path'
// First, the player
const playerSource = join(__dirname, '../../../client/src/locale/target/player_fr.xml')
const playerTarget = join(__dirname, '../../../client/src/locale/target/player_fr.json')
// Remove the two first lines our xliff module does not like
let playerFile = readFileSync(playerSource).toString()
playerFile = removeFirstLine(playerFile)
playerFile = removeFirstLine(playerFile)
xliff12ToJs(playerFile, (err, res) => {
if (err) {
console.error(err)
process.exit(-1)
}
const json = createJSONString(res)
writeFile(playerTarget, json, err => {
if (err) {
console.error(err)
process.exit(-1)
}
process.exit(0)
})
})
function removeFirstLine (str: string) {
return str.substring(str.indexOf('\n') + 1)
}
function createJSONString (obj: any) {
const res: any = {}
const strings = obj.resources['']
Object.keys(strings).forEach(k => res[k] = strings[k].target)
return JSON.stringify(res)
}

View file

@ -2,6 +2,11 @@
set -eu
# Copy locales
mkdir -p "./client/dist"
rm -r "./client/dist/locale"
cp -r "./client/src/locale/target" "./client/dist/locale"
NODE_ENV=test concurrently -k \
"npm run tsc -- --sourceMap && npm run nodemon -- --delay 2 --watch ./dist dist/server" \
"npm run tsc -- --sourceMap --preserveWatchOutput -w"