Skip to content

Commit 7292386

Browse files
Samk13SarahW91
andcommitted
feat(translations): add i18n support via i18next
* Add i18next integration and i18n config to package.json. * Add GitHub Actions workflows for Transifex i18n push/pull. * Mark UI strings as translatable in SearchBar, AutocompleteSearchBar, EmptyResults, Error, RangeFacet, ResultsPerPage, Sort, SortBy, SortOrder. * Extract translation template (translations.pot). * Generate PO files and compiled JSON for 30 locales. * re-lock Co-authored-by: Sarah Wiechers <sarah.wiechers@uni-muenster.de>
1 parent 9903418 commit 7292386

85 files changed

Lines changed: 5696 additions & 1090 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/i18n-pull.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
# Copyright (C) 2023 Graz University of Technology.
4+
#
5+
# React-Searchkit is free software; you can redistribute it and/or modify it
6+
# under the terms of the MIT License; see LICENSE file for more details.
7+
8+
name: i18n:pull translations
9+
on: workflow_dispatch # manually trigger
10+
11+
jobs:
12+
i18n-pull:
13+
uses: inveniosoftware/invenio-i18n/.github/workflows/i18n-pull-base.yml@master
14+
secrets: inherit

.github/workflows/i18n-push.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
# Copyright (C) 2023 Graz University of Technology.
4+
#
5+
# React-Searchkit is free software; you can redistribute it and/or modify it
6+
# under the terms of the MIT License; see LICENSE file for more details.
7+
8+
name: i18n:push translations
9+
on: workflow_dispatch # manually trigger
10+
11+
jobs:
12+
i18n-extract:
13+
uses: inveniosoftware/invenio-i18n/.github/workflows/i18n-push-base.yml@master
14+
with:
15+
extract-backend: false
16+
frontend-package-path: "./"
17+
secrets: inherit

.tx/config

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
# Copyright (C) 2019 CERN.
4+
# Copyright (C) 2019 Northwestern University.
5+
# Copyright (C) 2023 Graz University of Technology.
6+
#
7+
# React-Searchkit is free software; you can redistribute it and/or modify it
8+
# under the terms of the MIT License; see LICENSE file for more details.
9+
10+
# Translate JavaScript strings
11+
# 1) Navigate to the directory:
12+
# cd src/lib/translations/messages
13+
# 2) Install i18n dev dependencies
14+
# npm install
15+
# 3) Add a new language
16+
# npm run init_catalog lang <lang>
17+
# 4) Extract translation keys/values
18+
# $ npm run extract_messages
19+
# 5) Install the transifex-client
20+
# see: https://developers.transifex.com/docs/cli#transifex-client
21+
# 6) Push source (.pot) and translations (.po) to Transifex
22+
# Navigate to the root of the invenio_administration repository
23+
# $ tx push -s -t
24+
# 7) Pull translations for a single language from Transifex
25+
# $ tx pull -l <lang>
26+
# 8) Pull translations for all languages from Transifex
27+
# $ tx pull -a
28+
# 9) Compile .po files for all languages
29+
# $ npm run compile_catalog
30+
# 10) Convert .po file for a single language
31+
# $ npm run compile_catalog lang <lang>
32+
33+
[main]
34+
host = https://app.transifex.com
35+
36+
[o:inveniosoftware:p:invenio:r:react-searchkit-messages-ui]
37+
file_filter = src/lib/translations/messages/<lang>/messages.po
38+
source_file = src/lib/translations/translations.pot
39+
source_lang = en
40+
type = PO

i18next-scanner.config.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// This file is part of React-Searchkit
2+
// Copyright (C) 2021 Graz University of Technology.
3+
//
4+
// React-Searchkit is free software; you can redistribute it and/or modify it
5+
// under the terms of the MIT License; see LICENSE file for more details.
6+
7+
const { languages } = require("./package").config;
8+
9+
// list of func used to
10+
// mark the strings for translation
11+
const funcList = ["i18next.t"];
12+
13+
// list of extension to look for
14+
const extensions = [".js", ".jsx"];
15+
16+
module.exports = {
17+
options: {
18+
debug: true,
19+
removeUnusedKeys: true,
20+
browserLanguageDetection: true,
21+
func: {
22+
list: funcList,
23+
extensions: extensions,
24+
},
25+
//using Trans component
26+
trans: {
27+
component: "Trans",
28+
extensions: extensions,
29+
fallbackKey: function (ns, value) {
30+
return value;
31+
},
32+
},
33+
lngs: languages,
34+
ns: [
35+
// file name (.json)
36+
"translations",
37+
],
38+
defaultLng: "en",
39+
defaultNs: "translations",
40+
// @param {string} lng The language currently used.
41+
// @param {string} ns The namespace currently used.
42+
// @param {string} key The translation key.
43+
// @return {string} Returns a default value for the translation key.
44+
defaultValue: function (lng, ns, key) {
45+
if (lng === "en") {
46+
// Return key as the default value for English language
47+
return key;
48+
}
49+
return "";
50+
},
51+
resource: {
52+
// The path where resources get loaded from. Relative to current working directory.
53+
loadPath: "src/lib/translations/messages/{{lng}}/{{ns}}.json",
54+
55+
// The path to store resources.
56+
savePath: "src/lib/translations/messages/{{lng}}/{{ns}}.json",
57+
58+
jsonIndent: 2,
59+
lineEnding: "\n",
60+
},
61+
nsSeparator: false, // namespace separator
62+
63+
//Set to false to disable key separator
64+
// if you prefer having keys as the fallback for translation (e.g. gettext).
65+
keySeparator: false,
66+
},
67+
};

0 commit comments

Comments
 (0)