-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
1,975 additions
and
1,012 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright (C) 2021 CERN. | ||
# Copyright (C) 2021 Graz University of Technology. | ||
# | ||
# React-Invenio-Deposit is free software; you can redistribute it and/or modify it | ||
# under the terms of the MIT License; see LICENSE file for more details. | ||
|
||
# | ||
# 1) Extract translation keys/values, | ||
# $ npm run i18n-scan | ||
# 2) Update .pot file, this file is pushed to transifex | ||
# $ npm run i18n-conv-json | ||
# 3) Convert/update .json from .po | ||
# $ npm run i18n-conv-po-all | ||
# 4) Install the transifex-client | ||
# $ pip install transifex-client | ||
# 5) Push source (.pot) and translations (.po) to Transifex | ||
# $ tx push -s -t | ||
# 6) Pull translations for a single language from Transifex | ||
# $ tx pull -l <lang> | ||
# 7) Pull translations for all languages from Transifex | ||
# $ tx pull -a | ||
|
||
[main] | ||
host = https://www.transifex.com | ||
|
||
[invenio.react-invenio-deposit-messages] | ||
file_filter = src/lib/translations/<lang>/messages.po | ||
source_file = src/lib/translations/translations.pot | ||
source_lang = en | ||
type = PO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// This file is part of React-Invenio-Deposit | ||
// Copyright (C) 2021 Graz University of Technology. | ||
// | ||
// React-Invenio-Deposit is free software; you can redistribute it and/or modify it | ||
// under the terms of the MIT License; see LICENSE file for more details. | ||
|
||
const { readFileSync, writeFileSync } = require('fs'); | ||
const { gettextToI18next } = require('i18next-conv'); | ||
const { languages } = require('./package').config; | ||
|
||
// it accepts the same options as the cli. | ||
// https://github.com/i18next/i18next-gettext-converter#options | ||
const options = {/* you options here */} | ||
|
||
function save(target) { | ||
return result => { | ||
writeFileSync(target, result); | ||
}; | ||
} | ||
|
||
for (lang of languages) { | ||
gettextToI18next(lang, readFileSync(`src/lib/translations/${lang}/messages.po`), options) | ||
.then(save(`src/lib/translations/${lang}/translations.json`)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// This file is part of React-Invenio-Deposit | ||
// Copyright (C) 2021 Graz University of Technology. | ||
// | ||
// React-Invenio-Deposit is free software; you can redistribute it and/or modify it | ||
// under the terms of the MIT License; see LICENSE file for more details. | ||
|
||
const fs = require('fs'); | ||
const chalk = require('chalk'); | ||
const { languages } = require('./package').config; | ||
|
||
// list of func used to | ||
// mark the strings for translation | ||
const funcList = ['i18next.t', 'i18n.t', 't']; | ||
|
||
module.exports = { | ||
options: { | ||
debug: true, | ||
browserLanguageDetection: true, | ||
func: { | ||
list: funcList, | ||
extensions: ['.js', '.jsx'] | ||
}, | ||
trans: false, // Enable for using Trans component | ||
lngs: languages, | ||
ns: [ | ||
// file name (.json) | ||
'translations', | ||
], | ||
defaultLng: 'en', | ||
defaultNs: 'translations', | ||
resource: { | ||
// The path where resources get loaded from. Relative to current working directory. | ||
loadPath: 'src/lib/translations/{{lng}}/{{ns}}.json', | ||
|
||
// The path to store resources. | ||
savePath: 'src/lib/translations/{{lng}}/{{ns}}.json', | ||
|
||
jsonIndent: 2, | ||
lineEnding: '\n' | ||
}, | ||
nsSeparator: false, // namespace separator | ||
|
||
//Set to false to disable key separator | ||
// if you prefer having keys as the fallback for translation (e.g. gettext). | ||
keySeparator: false, | ||
}, | ||
|
||
// func is provided | ||
// (if needed)for more custom extractions. | ||
transform: function customTransform(file, enc, done) { | ||
"use strict"; | ||
const parser = this.parser; | ||
const content = fs.readFileSync(file.path, enc); | ||
let count = 0; | ||
|
||
parser.parseFuncFromString(content, { list: funcList }, (key, options) => { | ||
parser.set(key, Object.assign({}, options, { | ||
nsSeparator: false, | ||
keySeparator: false | ||
})); | ||
++count; | ||
}); | ||
|
||
if (count > 0) { | ||
console.log(`i18next-scanner: count=${chalk.cyan(count)}, file=${chalk.yellow(JSON.stringify(file.relative))}`); | ||
} | ||
done(); | ||
} | ||
}; |
Oops, something went wrong.