Skip to content

Commit

Permalink
Merge pull request #63 from mengmeet/i18next
Browse files Browse the repository at this point in the history
Update localization by i18next / 更新本地化库, 使用i18next实现
  • Loading branch information
honjow authored Mar 17, 2024
2 parents ff3c4d0 + cbad769 commit 62aa581
Show file tree
Hide file tree
Showing 9 changed files with 217 additions and 135 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"typescript": "^4.7.4"
},
"dependencies": {
"i18next": "^23.10.1",
"react-icons": "^4.4.0",
"typescript-json-serializer": "^4.2.0"
},
Expand Down
20 changes: 20 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/i18n/english.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,6 @@
"UNLIMITED_DESC": "No limit on GPU frequency, system default scheduling",
"FIXED_FREQ_DESC": "Fixed GPU frequency",
"RANGE_FREQ_DESC": "Set GPU frequency range",
"AUTO_FREQ_DESC": "Adaptive GPU frequency, forcibly turn off TDP limit, turn off Boost"
"AUTO_FREQ_DESC": "Adaptive GPU frequency, forcibly disabled TDP limit, disabled Boost",
"AUTO_FREQ_TDP_NOTIF": "GPU mode {{mode}}, TDP limit disabled"
}
60 changes: 44 additions & 16 deletions src/i18n/localization.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,49 @@
import { ServerAPI } from "decky-frontend-lib";
import { localizeMap, localizeStrEnum } from "./localizeMap";
import { defaultLocale, localizeMap, localizeStrEnum } from "./localizeMap";

import i18n, { Resource } from "i18next";

export class localizationManager {
private static language = "english"
//private has_language = false
public static async init(serverAPI: ServerAPI) {
await serverAPI!.callPluginMethod<{},string>("get_language",{}).then(res=>{
if (res.success){
//console.log("language = " + res.result);
this.language = res.result;
//this.has_language = true;
}
})
private static language = "english";

public static async init() {
const language =
(await SteamClient.Settings.GetCurrentLanguage()) || "english";
this.language = language;
console.log("Language: " + this.language);

const resources: Resource = Object.keys(localizeMap).reduce((acc, key) => {
acc[localizeMap[key].locale] = {
translation: localizeMap[key].strings,
};
return acc;
}, {});

i18n.init({
// resources: {
// "zh-CN": {
// translation: localizeMap["tchinese"].strings,
// }
// },
// lng:"zh-CN",
resources: resources,
lng: this.getLocale(), // 目标语言
fallbackLng: defaultLocale, // 回落语言
returnEmptyString: false, // 空字符串不返回, 使用回落语言
interpolation: {
escapeValue: false,
},
});
}
public static getString(defaultString:localizeStrEnum){
var str = localizeMap[this.language]?.strings?.[defaultString]??localizeMap["english"]?.strings?.[defaultString];
return str==""?localizeMap["english"]?.strings?.[defaultString]:str

private static getLocale() {
return localizeMap[this.language]?.locale ?? defaultLocale;
}
}

public static getString(defaultString: localizeStrEnum, variables?: Record<string, unknown>) {
// var str =
// localizeMap[this.language]?.strings?.[defaultString] ??
// localizeMap["english"]?.strings?.[defaultString];
// return str == "" ? localizeMap["english"]?.strings?.[defaultString] : str;
return i18n.t(defaultString, variables);
}
}
250 changes: 136 additions & 114 deletions src/i18n/localizeMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,126 +8,148 @@ import * as thai from "./thai.json";
import * as bulgarian from "./bulgarian.json";
import * as italian from "./italian.json";
import * as french from "./french.json";
export const localizeMap = {
schinese: {
label: '简体中文',
strings: schinese,
credit: ["yxx"],
},
tchinese: {
label: '繁體中文',
strings: tchinese,
credit: [],
},
english: {
label: 'English',
strings: english,
credit: [],
},
german: {
label: 'Deutsch',
strings: german,
credit: ["dctr"],
},
japanese: {
label: '日本語',
strings: japanese,
credit: [],
},
koreana: {
label: '한국어',
strings: koreana,
credit: [],
},
thai: {
label: 'ไทย',
strings: thai,
credit: [],
},
bulgarian: {
label: 'Български',
strings: bulgarian,
credit: [],
},
italian: {
label: 'Italiano',
strings: italian,
credit: [],
},
french: {
label: 'Français',
strings: french,
credit: [],
},

export interface LanguageProps {
label: string;
strings: any;
credit: string[];
locale: string;
}

export const defaultLanguage = "english";
export const defaultLocale = "en";
export const defaultMessages = english;

export const localizeMap: { [key: string]: LanguageProps } = {
schinese: {
label: "简体中文",
strings: schinese,
credit: ["yxx"],
locale: "zh-CN",
},
tchinese: {
label: "繁體中文",
strings: tchinese,
credit: [],
locale: "zh-TW",
},
english: {
label: "English",
strings: english,
credit: [],
locale: "en",
},
german: {
label: "Deutsch",
strings: german,
credit: ["dctr"],
locale: "de",
},
japanese: {
label: "日本語",
strings: japanese,
credit: [],
locale: "ja",
},
koreana: {
label: "한국어",
strings: koreana,
credit: [],
locale: "ko",
},
thai: {
label: "ไทย",
strings: thai,
credit: [],
locale: "th",
},
bulgarian: {
label: "Български",
strings: bulgarian,
credit: [],
locale: "bg",
},
italian: {
label: "Italiano",
strings: italian,
credit: [],
locale: "it",
},
french: {
label: "Français",
strings: french,
credit: [],
locale: "fr",
},
};

export enum localizeStrEnum {
TITEL_SETTINGS="TITEL_SETTINGS",
ENABLE_SETTINGS="ENABLE_SETTINGS",
USE_PERGAME_PROFILE="USE_PERGAME_PROFILE",
USING="USING",
DEFAULT="DEFAULT",
PROFILE="PROFILE",
CPU_BOOST="CPU_BOOST",
CPU_BOOST_DESC="CPU_BOOST_DESC",
SMT_DESC="SMT_DESC",
CPU_NUM="CPU_NUM",
CPU_NUM_DESC="CPU_NUM_DESC",
TDP="TDP",
TDP_DESC="TDP_DESC",
RYZENADJ_NOT_FOUND="RYZENADJ_NOT_FOUND",
WATTS="WATTS",
GPU_FREQMODE="GPU_FREQMODE",
UNLIMITED="UNLIMITED",
FIXED_FREQ="FIXED_FREQ",
RANGE_FREQ="RANGE_FREQ",
AUTO_FREQ="AUTO_FREQ",
GPU_FIX_FREQ="GPU_FIX_FREQ",
GPU_MIN_FREQ="GPU_MIN_FREQ",
GPU_MAX_FREQ="GPU_MAX_FREQ",
FAN_SPEED="FAN_SPEED",
CREATE_FAN_PROFILE="CREATE_FAN_PROFILE",
GRID_ALIG="GRID_ALIG",
FAN_MODE="FAN_MODE",
NOT_CONTROLLED="NOT_CONTROLLED",
FIXED="FIXED",
CURVE="CURVE",
SNAP_GRIDLINE="SNAP_GRIDLINE",
FAN_SPEED_PERCENT="FAN_SPEED_PERCENT",
SENSOR_TEMP="SENSOR_TEMP",
CREATE_FAN_PROFILE_TIP="CREATE_FAN_PROFILE_TIP",
SELECT_FAN_PROFILE_TIP="SELECT_FAN_PROFILE_TIP",
FAN_PROFILE_NAME="FAN_PROFILE_NAME",
USE="USE",
DELETE="DELETE",
CREATE="CREATE",
CANCEL="CANCEL",
CURENT_STAT="CURENT_STAT",
EDIT="EDIT",
SAVE="SAVE",
NATIVE_FREQ="NATIVE_FREQ",
TITEL_SETTINGS = "TITEL_SETTINGS",
ENABLE_SETTINGS = "ENABLE_SETTINGS",
USE_PERGAME_PROFILE = "USE_PERGAME_PROFILE",
USING = "USING",
DEFAULT = "DEFAULT",
PROFILE = "PROFILE",
CPU_BOOST = "CPU_BOOST",
CPU_BOOST_DESC = "CPU_BOOST_DESC",
SMT_DESC = "SMT_DESC",
CPU_NUM = "CPU_NUM",
CPU_NUM_DESC = "CPU_NUM_DESC",
TDP = "TDP",
TDP_DESC = "TDP_DESC",
RYZENADJ_NOT_FOUND = "RYZENADJ_NOT_FOUND",
WATTS = "WATTS",
GPU_FREQMODE = "GPU_FREQMODE",
UNLIMITED = "UNLIMITED",
FIXED_FREQ = "FIXED_FREQ",
RANGE_FREQ = "RANGE_FREQ",
AUTO_FREQ = "AUTO_FREQ",
GPU_FIX_FREQ = "GPU_FIX_FREQ",
GPU_MIN_FREQ = "GPU_MIN_FREQ",
GPU_MAX_FREQ = "GPU_MAX_FREQ",
FAN_SPEED = "FAN_SPEED",
CREATE_FAN_PROFILE = "CREATE_FAN_PROFILE",
GRID_ALIG = "GRID_ALIG",
FAN_MODE = "FAN_MODE",
NOT_CONTROLLED = "NOT_CONTROLLED",
FIXED = "FIXED",
CURVE = "CURVE",
SNAP_GRIDLINE = "SNAP_GRIDLINE",
FAN_SPEED_PERCENT = "FAN_SPEED_PERCENT",
SENSOR_TEMP = "SENSOR_TEMP",
CREATE_FAN_PROFILE_TIP = "CREATE_FAN_PROFILE_TIP",
SELECT_FAN_PROFILE_TIP = "SELECT_FAN_PROFILE_TIP",
FAN_PROFILE_NAME = "FAN_PROFILE_NAME",
USE = "USE",
DELETE = "DELETE",
CREATE = "CREATE",
CANCEL = "CANCEL",
CURENT_STAT = "CURENT_STAT",
EDIT = "EDIT",
SAVE = "SAVE",
NATIVE_FREQ = "NATIVE_FREQ",

MORE = "MORE",
REINSTALL_PLUGIN = "REINSTALL_PLUGIN",
UPDATE_PLUGIN = "UPDATE_PLUGIN",
INSTALLED_VERSION = "INSTALLED_VERSION",
LATEST_VERSION = "LATEST_VERSION",

MORE="MORE",
REINSTALL_PLUGIN = "REINSTALL_PLUGIN",
UPDATE_PLUGIN = "UPDATE_PLUGIN",
INSTALLED_VERSION = "INSTALLED_VERSION",
LATEST_VERSION = "LATEST_VERSION",

GPU_NATIVE_SLIDER="GPU_NATIVE_SLIDER",
GPU_NATIVE_SLIDER_DESC="GPU_NATIVE_SLIDER_DESC",
GPU_NATIVE_SLIDER = "GPU_NATIVE_SLIDER",
GPU_NATIVE_SLIDER_DESC = "GPU_NATIVE_SLIDER_DESC",

USE_PERACMODE_PROFILE="USE_PERACMODE_PROFILE",
AC_MODE="AC_MODE",
BAT_MODE="BAT_MODE",
USE_PERACMODE_PROFILE = "USE_PERACMODE_PROFILE",
AC_MODE = "AC_MODE",
BAT_MODE = "BAT_MODE",

CUSTOM_TDP_RANGE="CUSTOM_TDP_RANGE",
CUSTOM_TDP_RANGE = "CUSTOM_TDP_RANGE",

RESET_ALL="RESET_ALL",
RESET_ALL = "RESET_ALL",

NATIVE_FREQ_DESC="NATIVE_FREQ_DESC",
UNLIMITED_DESC="UNLIMITED_DESC",
FIXED_FREQ_DESC="FIXED_FREQ_DESC",
RANGE_FREQ_DESC="RANGE_FREQ_DESC",
AUTO_FREQ_DESC="AUTO_FREQ_DESC"
NATIVE_FREQ_DESC = "NATIVE_FREQ_DESC",
UNLIMITED_DESC = "UNLIMITED_DESC",
FIXED_FREQ_DESC = "FIXED_FREQ_DESC",
RANGE_FREQ_DESC = "RANGE_FREQ_DESC",
AUTO_FREQ_DESC = "AUTO_FREQ_DESC",
AUTO_FREQ_TDP_NOTIF = "AUTO_FREQ_TDP_NOTIF"
}

Loading

0 comments on commit 62aa581

Please sign in to comment.