Skip to content

Commit

Permalink
feat(i18n): Time to Load stored state
Browse files Browse the repository at this point in the history
  • Loading branch information
hyx3179 authored and oliversalzburg committed Apr 30, 2024
1 parent 95bfa85 commit 00ae818
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
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

0 comments on commit 00ae818

Please sign in to comment.