Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I18n #518

Merged
merged 3 commits into from
Apr 30, 2024
Merged

I18n #518

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/kitten-scientists/source/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"festival.hold": "Kittens begin holding a festival",
"filter.accelerate": "Tempus Fugit",
"filter.adore": "Adoring",
"filter.allKG": "All KG log entries.",
"filter.build": "Building",
"filter.craft": "Crafting",
"filter.disable": "Disabled {0} log messages",
Expand Down
1 change: 1 addition & 0 deletions packages/kitten-scientists/source/i18n/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"festival.hold": "小猫开始举办节日",
"filter.accelerate": "时间加速",
"filter.adore": "赞美群星",
"filter.allKG": "所有游戏日志",
"filter.build": "建筑",
"filter.craft": "工艺",
"filter.disable": "取消过滤 {0}",
Expand Down
4 changes: 3 additions & 1 deletion packages/kitten-scientists/source/ui/LogFilterSettingsUi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ export class LogFiltersSettingsUi extends SettingsSectionUi<LogFilterSettings> {

this.addChild(
new SettingsList(host, {
children: [new SettingListItem(host, "All KG log entries.", settings.disableKGLog)],
children: [
new SettingListItem(host, this._host.engine.i18n("filter.allKG"), settings.disableKGLog),
],
hasDisableAll: false,
hasEnableAll: false,
}),
Expand Down
15 changes: 14 additions & 1 deletion packages/kitten-scientists/source/ui/StateManagementUi.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { isNil } from "@oliversalzburg/js-utils/nil.js";
import { formatDistanceToNow } from "date-fns/formatDistanceToNow";
import { Locale, de, enUS, he, zhCN } from "date-fns/locale";
import { EngineState } from "../Engine.js";
import { UserScript } from "../UserScript.js";
import { Icons } from "../images/Icons.js";
import { SettingOptions } from "../settings/Settings.js";
import { StateSettings } from "../settings/StateSettings.js";
import { cerror } from "../tools/Log.js";
import { SavegameLoader } from "../tools/SavegameLoader.js";
Expand All @@ -26,8 +28,9 @@ export type StoredState = {
export class StateManagementUi extends SettingsPanel<StateSettings> {
readonly states = new Array<StoredState>();
readonly stateList: SettingsList;
readonly locale: Locale;

constructor(host: UserScript, settings: StateSettings) {
constructor(host: UserScript, settings: StateSettings, language: SettingOptions) {
const label = host.engine.i18n("state.title");
super(host, label, settings, {
settingItem: new LabelListItem(host, label, { icon: Icons.State }),
Expand All @@ -38,6 +41,15 @@ export class StateManagementUi extends SettingsPanel<StateSettings> {
hasDisableAll: false,
});

this.locale =
language.selected === "zh"
? zhCN
: language.selected === "he"
? he
: language.selected === "de"
? de
: enUS;

this.addChild(
new SettingsList(host, {
children: [
Expand Down Expand Up @@ -163,6 +175,7 @@ export class StateManagementUi extends SettingsPanel<StateSettings> {
this._host,
`${state.label ?? unlabeled} (${formatDistanceToNow(new Date(state.timestamp), {
addSuffix: true,
locale: this.locale,
})})`,
{ onClick: () => this.loadState(state.state), title: state.timestamp },
);
Expand Down
2 changes: 1 addition & 1 deletion packages/kitten-scientists/source/ui/UserInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class UserInterface extends UiComponent {
new TimeSettingsUi(this._host, engine.timeManager.settings),
new TimeControlSettingsUi(this._host, engine.timeControlManager.settings),
new LogFiltersSettingsUi(this._host, engine.settings.filters),
new StateManagementUi(this._host, engine.settings.states),
new StateManagementUi(this._host, engine.settings.states, engine.settings.language),
new InternalsUi(this._host, engine.settings),
];

Expand Down
13 changes: 13 additions & 0 deletions packages/kitten-scientists/source/ui/VillageSettingsUi.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { TranslatedString } from "../Engine.js";
import { SettingMax } from "../settings/Settings.js";
import { VillageSettings } from "../settings/VillageSettings.js";
import { UserScript } from "../UserScript.js";
Expand Down Expand Up @@ -130,6 +131,18 @@ export class VillageSettingsUi extends SettingsSectionUi<VillageSettings> {
);
listAddition.addChild(this._promoteLeader);

this.setting.electLeader.job.options.forEach(option => {
option.label = this._host.engine.i18n(
<TranslatedString<`$${string}`>>("$village.job." + option.value),
);
});

this.setting.electLeader.trait.options.forEach(option => {
option.label = this._host.engine.i18n(
<TranslatedString<`$${string}`>>("$village.trait." + option.value),
);
});

this._electLeader = new SettingListItem(
this._host,
this._host.engine.i18n("option.elect"),
Expand Down