summaryrefslogtreecommitdiff
path: root/src/i18n/i18n.ts
diff options
context:
space:
mode:
authorsana2dang <sana2dang@naver.com>2026-03-12 16:07:04 +0900
committersana2dang <sana2dang@naver.com>2026-03-12 16:07:04 +0900
commitf4e2769d069fcf87da5ec7f39e0d372903bdb810 (patch)
tree373af291caf42538b20d14a0ff943ed6c83e670c /src/i18n/i18n.ts
parent97a70cd68813f2174fe145ee79784e509d11a742 (diff)
downloaddecky-lsfg-vk-f4e2769d069fcf87da5ec7f39e0d372903bdb810.tar.gz
decky-lsfg-vk-f4e2769d069fcf87da5ec7f39e0d372903bdb810.zip
Apply i18n to all UI components with ko/ja translations
- Add src/i18n/i18n.ts translation engine (ported from SimpleDeckyTDP) - Add defaults/i18n/{ko,ja,template}.json with 80 translation keys - Add defaults/i18n/language_metadata.json and steam_language_map.json - Add scripts/build_i18n_json.sh to generate languages.json - Apply t() to all 10 components: Content, ConfigurationSection, FlatpaksModal, FpsMultiplierControl, InstallationButton, NerdStuffModal, ProfileManagement, SmartClipboardButton, FgmodClipboardButton, UsageInstructions Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'src/i18n/i18n.ts')
-rw-r--r--src/i18n/i18n.ts65
1 files changed, 65 insertions, 0 deletions
diff --git a/src/i18n/i18n.ts b/src/i18n/i18n.ts
new file mode 100644
index 0000000..83ed3da
--- /dev/null
+++ b/src/i18n/i18n.ts
@@ -0,0 +1,65 @@
+// languages.json build via CI build
+// to generate for localhost/dev, run `build_i18n_json.sh` script
+import * as languages from "./languages.json";
+
+function getLangs() {
+ const langs = languages.language_metadata;
+
+ Object.keys(languages).map((lang) => {
+ if (lang === "language_metadata" || lang == "steam_language_map") {
+ return;
+ }
+ const strs = languages[lang];
+ if (lang && strs && langs[lang]?.name) {
+ langs[lang].strings = strs;
+ }
+ });
+
+ return langs;
+}
+
+export const LANGS: {
+ [key: string]: {
+ name: string;
+ strings: {
+ [key: string]: string;
+ };
+ };
+} = getLangs();
+
+let cachedLang: string | undefined;
+
+export const getCurrentLanguage = (): string => {
+ if (cachedLang) return cachedLang;
+
+ const lang = window.LocalizationManager.m_rgLocalesToUse[0];
+ cachedLang = lang;
+ return lang;
+};
+
+export const getLanguageName = (lang?: string): string => {
+ const targetLang = lang || getCurrentLanguage();
+ return LANGS[targetLang]?.name || targetLang;
+};
+
+/**
+ * Translate a key to the current language
+ *
+ * @param key - Translation key
+ * @param originalString - Original text (fallback)
+ * @returns Translated string or original text if translation not found
+ *
+ * @example
+ * t('CONTENT_FPS_MULTIPLIER', 'FPS Multiplier')
+ */
+const t = (key: string, originalString: string): string => {
+ const lang = getCurrentLanguage();
+
+ // English always returns the original text
+ if (lang === "en") return originalString;
+
+ // Return translation if exists, otherwise return original text
+ return LANGS[lang]?.strings?.[key] ?? originalString;
+};
+
+export default t;