Skip to content

Commit

Permalink
get all our translated UIs into the translation list
Browse files Browse the repository at this point in the history
  • Loading branch information
obra committed Nov 18, 2024
1 parent 8fe3795 commit c2f0da3
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 34 deletions.
8 changes: 2 additions & 6 deletions src/api/focus/keymap/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ import { Base, USQwerty } from "./db/base";
import { constants } from "./db/constants";
import { withModifiers } from "./db/modifiers";

import enLangMap from "./cldr_languages/en";
import nlLangMap from "./cldr_languages/nl";
import { languageMaps } from "./language_maps";

global.chrysalis_keymapdb_instance = null;

Expand All @@ -39,10 +38,7 @@ class KeymapDB {
this.loadLayouts();
this.constants = constants;
this.supported_layouts = {};
this.layout_langs = {
en: enLangMap,
nl: nlLangMap,
};
this.layout_langs = languageMaps;
}

return global.chrysalis_keymapdb_instance;
Expand Down
11 changes: 11 additions & 0 deletions src/api/focus/keymap/language_maps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// This file is auto-generated. Do not edit manually.
export const languageMaps = {
"de": require("./cldr_languages/de.json"),
"en": require("./cldr_languages/en.json"),
"es": require("./cldr_languages/es.json"),
"fr": require("./cldr_languages/fr.json"),
"id": require("./cldr_languages/id.json"),
"nb-NO": require("./cldr_languages/nb_no.json"),
"nl": require("./cldr_languages/nl.json"),
"zh-Hans": require("./cldr_languages/zh_hans.json")
};
58 changes: 33 additions & 25 deletions src/renderer/i18n.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,43 @@
// -*- mode: js-jsx -*-
/* Chrysalis -- Kaleidoscope Command Center
* Copyright (C) 2018-2022 Keyboardio, Inc.
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import English from "@renderer/i18n/en";
import Dutch from "@renderer/i18n/nl";
// This file is auto-generated. Do not edit manually.
import de from "@renderer/i18n/de";
import en from "@renderer/i18n/en";
import es from "@renderer/i18n/es";
import fr from "@renderer/i18n/fr";
import id from "@renderer/i18n/id";
import nb_NO from "@renderer/i18n/nb-NO";
import nl from "@renderer/i18n/nl";
import zh_Hans from "@renderer/i18n/zh-Hans";
import i18n from "i18next";
import { initReactI18next } from "react-i18next";

const resources = {
en: {
messages: English,
"de": {

Check failure on line 14 in src/renderer/i18n.js

View workflow job for this annotation

GitHub Actions / Lint

Replace `"de"` with `de`
messages: de,
},
"en": {

Check failure on line 17 in src/renderer/i18n.js

View workflow job for this annotation

GitHub Actions / Lint

Replace `"en"` with `en`
messages: en,
},
"es": {

Check failure on line 20 in src/renderer/i18n.js

View workflow job for this annotation

GitHub Actions / Lint

Replace `"es"` with `es`
messages: es,
},
"fr": {

Check failure on line 23 in src/renderer/i18n.js

View workflow job for this annotation

GitHub Actions / Lint

Replace `"fr"` with `fr`
messages: fr,
},
"id": {

Check failure on line 26 in src/renderer/i18n.js

View workflow job for this annotation

GitHub Actions / Lint

Replace `"id"` with `id`
messages: id,
},
"nb-NO": {
messages: nb_NO,
},
"nl": {

Check failure on line 32 in src/renderer/i18n.js

View workflow job for this annotation

GitHub Actions / Lint

Replace `"nl"` with `nl`
messages: nl,
},
nl: {
messages: Dutch,
"zh-Hans": {
messages: zh_Hans,
},
};

i18n // eslint-disable-line import/no-named-as-default-member
i18n

Check warning on line 40 in src/renderer/i18n.js

View workflow job for this annotation

GitHub Actions / Lint

Caution: `i18n` also has a named export `use`. Check if you meant to write `import {use} from 'i18next'` instead

Check failure on line 40 in src/renderer/i18n.js

View workflow job for this annotation

GitHub Actions / Lint

Replace `⏎··.use(initReactI18next)⏎··` with `.use(initReactI18next)`
.use(initReactI18next)
.init({
react: {

Check failure on line 43 in src/renderer/i18n.js

View workflow job for this annotation

GitHub Actions / Lint

Delete `··`
Expand All @@ -51,7 +59,7 @@ i18n.refreshHardware = (device) => {
Object.keys(i18n.options.resources).forEach((code) => {
const key = "devices." + device?.info.vendor + "." + device?.info.product + ".updateInstructions";
const instructions = {
updateInstructions: i18n.exists(key) ? i18n.t(key) : undefined, // eslint-disable-line import/no-named-as-default-member
updateInstructions: i18n.exists(key) ? i18n.t(key) : undefined,

Check warning on line 62 in src/renderer/i18n.js

View workflow job for this annotation

GitHub Actions / Lint

Caution: `i18n` also has a named export `exists`. Check if you meant to write `import {exists} from 'i18next'` instead

Check warning on line 62 in src/renderer/i18n.js

View workflow job for this annotation

GitHub Actions / Lint

Caution: `i18n` also has a named export `t`. Check if you meant to write `import {t} from 'i18next'` instead
};
i18n.addResource(code, "messages", "hardware", instructions);
});
Expand Down
14 changes: 11 additions & 3 deletions src/renderer/screens/Preferences/ui/LookAndFeelPreferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,21 @@ function LookAndFeelPreferences(props) {
};

const languages = Object.keys(i18n.options.resources).map((code) => {
const t = i18n.getFixedT(code);
// Check if this specific language has the translation
const translation = i18n.t("this_translation_language", {
lng: code,
fallbackLng: [], // Empty array means no fallback for just this translation
});

// If we got back the translation key, it means translation is missing
if (translation === "this_translation_language") return null;

return (
<MenuItem value={code} key={code}>
{t("this_translation_language")}
{translation}
</MenuItem>
);
});
}).filter(Boolean);

const systemSvg = (
<svg width="120" height="73" viewBox="0 0 120 73" fill="none" xmlns="https://www.w3.org/2000/svg">
Expand Down

0 comments on commit c2f0da3

Please sign in to comment.