Skip to content

Commit

Permalink
Translations: add jinja and js translations
Browse files Browse the repository at this point in the history
  • Loading branch information
Pineirin committed Feb 14, 2023
1 parent 7e4c2f0 commit a34b4cf
Show file tree
Hide file tree
Showing 48 changed files with 2,261 additions and 43 deletions.
33 changes: 33 additions & 0 deletions .tx/config
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,36 @@ file_filter = invenio_pages/translations/<lang>/LC_MESSAGES/messages.po
source_file = invenio_pages/translations/messages.pot
source_lang = en
type = PO

# Translate JavaScript strings
# 1) Navigate to the invenio_administration/assets/semantic-ui/translations/invenio_administration folder
# 2) Install i18n dev dependencies
# npm install
# 3) Add a new language
# npm run init_catalog lang <lang>
# 4) Extract translation keys/values
# $ npm run extract_messages
# 5) Update the ./messages/index.js file
# import TRANSLATE_<lang> from './<lang>/translations.json'
# export const translations = {
# ...rest,
# <lang>: { translation: TRANSLATE_<lang> }
# }
# 6) Install the transifex-client
# $ pip install transifex-client
# 7) Push source (.pot) and translations (.po) to Transifex
# $ tx push -s -t
# 8) Pull translations for a single language from Transifex
# $ tx pull -l <lang>
# 9) Pull translations for all languages from Transifex
# $ tx pull -a
# 10) Compile .po files for all languages
# $ npm run compile_catalog
# 11) Convert .po file for a single language
# $ npm run compile_catalog lang <lang>

[invenio.invenio-pages-messages-ui]
file_filter = invenio_pages/assets/semantic-ui/translations/invenio_pages/messages/<lang>/messages.po
source_file = invenio_pages/assets/semantic-ui/translations/invenio_pages/translations.pot
source_lang = en
type = PO
10 changes: 1 addition & 9 deletions babel.ini
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
# -*- coding: utf-8 -*-
#
# This file is part of Invenio.
# Copyright (C) 2015-2022 CERN.
# Copyright (C) 2015-2023 CERN.
#
# Invenio is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.

# Extraction from Python source files

[python: **.py]
encoding = utf-8

# Extraction from Jinja2 templates

[jinja2: **/templates/**.html]
encoding = utf-8

# Extraction from JavaScript files

[javascript: **.js]
encoding = utf-8
extract_messages = $._, jQuery._
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// This file is part of Invenio
//
// Invenio-pages is free software; you can redistribute it and/or modify it
// under the terms of the MIT License; see LICENSE file for more details.

// list of func used to
// mark the strings for translation
const { languages } = require("./package.json").config;

const funcList = ["i18next.t"];
const extensions = [".js", ".jsx"];

module.exports = {
options: {
debug: true,
removeUnusedKeys: true,
browserLanguageDetection: true,
func: {
list: funcList,
extensions: extensions,
},
//using Trans component
trans: {
component: "Trans",
extensions: extensions,
fallbackKey: function (ns, value) {
return value;
},
},
lngs: languages,
ns: [
// file name (.json)
"translations",
],
defaultLng: "en",
defaultNs: "translations",
// @param {string} lng The language currently used.
// @param {string} ns The namespace currently used.
// @param {string} key The translation key.
// @return {string} Returns a default value for the translation key.
defaultValue: function (lng, ns, key) {
if (lng === "en") {
// Return key as the default value for English language
return key;
}
return "";
},
resource: {
// The path where resources get loaded from. Relative to current working directory.
loadPath: "messages/{{lng}}/{{ns}}.json",

// The path to store resources.
savePath: "messages/{{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,
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// This file is part of Invenio
//
// Invenio-pages is free software; you can redistribute it and/or modify it
// under the terms of the MIT License; see LICENSE file for more details.

import i18n from "i18next";

import LanguageDetector from "i18next-browser-languagedetector";
import { translations } from "./messages";
import { initReactI18next } from "react-i18next";

const options = {
fallbackLng: "en", // fallback keys
returnEmptyString: false,
debug: process.env.NODE_ENV === "development",
resources: translations,
keySeparator: false,
nsSeparator: false,
// specify language detection order
detection: {
order: ["htmlTag"],
// cache user language off
caches: [],
},
react: {
// Set empty - to allow html tags convert to trans tags
// HTML TAG | Trans TAG
// <span> | <1>
transKeepBasicHtmlNodesFor: [],
},
};

const i18next = i18n.createInstance();
i18next.use(LanguageDetector).use(initReactI18next).init(options);

export { i18next };
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"Actions": ""
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"Actions": ""
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"Actions": ""
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"Actions": ""
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"Actions": ""
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"Actions": ""
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"Actions": ""
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"Actions": ""
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"Actions": "Actions"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"Actions": ""
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"Actions": ""
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"Actions": ""
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"Actions": ""
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"Actions": ""
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"Actions": ""
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"Actions": ""
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"Actions": ""
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import TRANSLATE_AF from "./af/translations.json";
import TRANSLATE_AR from "./ar/translations.json";
import TRANSLATE_BG from "./bg/translations.json";
import TRANSLATE_CA from "./ca/translations.json";
import TRANSLATE_CS from "./cs/translations.json";
import TRANSLATE_DA from "./da/translations.json";
import TRANSLATE_DE from "./de/translations.json";
import TRANSLATE_EL from "./el/translations.json";
import TRANSLATE_EN from "./en/translations.json";
import TRANSLATE_ES from "./es/translations.json";
import TRANSLATE_ET from "./et/translations.json";
import TRANSLATE_ET_EE from "./et_EE/translations.json";
import TRANSLATE_FA from "./fa/translations.json";
import TRANSLATE_FR from "./fr/translations.json";
import TRANSLATE_GL from "./gl/translations.json";
import TRANSLATE_HR from "./hr/translations.json";
import TRANSLATE_HU from "./hu/translations.json";
import TRANSLATE_IT from "./it/translations.json";
import TRANSLATE_JA from "./ja/translations.json";
import TRANSLATE_KA from "./ka/translations.json";
import TRANSLATE_LT from "./lt/translations.json";
import TRANSLATE_NO from "./no/translations.json";
import TRANSLATE_PL from "./pl/translations.json";
import TRANSLATE_PT from "./pt/translations.json";
import TRANSLATE_RO from "./ro/translations.json";
import TRANSLATE_RU from "./ru/translations.json";
import TRANSLATE_RW from "./rw/translations.json";
import TRANSLATE_SK from "./sk/translations.json";
import TRANSLATE_SV from "./sv/translations.json";
import TRANSLATE_TR from "./tr/translations.json";
import TRANSLATE_UK from "./uk/translations.json";
import TRANSLATE_ZH_CN from "./zh_CN/translations.json";
import TRANSLATE_ZH_TW from "./zh_TW/translations.json";

export const translations = {
af: { translation: TRANSLATE_AF },
ar: { translation: TRANSLATE_AR },
bg: { translation: TRANSLATE_BG },
ca: { translation: TRANSLATE_CA },
cs: { translation: TRANSLATE_CS },
da: { translation: TRANSLATE_DA },
de: { translation: TRANSLATE_DE },
el: { translation: TRANSLATE_EL },
en: { translation: TRANSLATE_EN },
es: { translation: TRANSLATE_ES },
et: { translation: TRANSLATE_ET },
et_EE: { translation: TRANSLATE_ET_EE },
fa: { translation: TRANSLATE_FA },
fr: { translation: TRANSLATE_FR },
gl: { translation: TRANSLATE_GL },
hr: { translation: TRANSLATE_HR },
hu: { translation: TRANSLATE_HU },
it: { translation: TRANSLATE_IT },
ja: { translation: TRANSLATE_JA },
ka: { translation: TRANSLATE_KA },
lt: { translation: TRANSLATE_LT },
no: { translation: TRANSLATE_NO },
pl: { translation: TRANSLATE_PL },
pt: { translation: TRANSLATE_PT },
ro: { translation: TRANSLATE_RO },
ru: { translation: TRANSLATE_RU },
rw: { translation: TRANSLATE_RW },
sk: { translation: TRANSLATE_SK },
sv: { translation: TRANSLATE_SV },
tr: { translation: TRANSLATE_TR },
uk: { translation: TRANSLATE_UK },
zh_CN: { translation: TRANSLATE_ZH_CN },
zh_TW: { translation: TRANSLATE_ZH_TW },
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"Actions": ""
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"Actions": ""
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"Actions": ""
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"Actions": ""
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"Actions": ""
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"Actions": ""
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"Actions": ""
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"Actions": ""
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"Actions": ""
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"Actions": ""
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"Actions": ""
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"Actions": ""
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"Actions": ""
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"Actions": ""
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"Actions": ""
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"Actions": ""
}
Loading

0 comments on commit a34b4cf

Please sign in to comment.