2021-06-26 22:02:00 +02:00
|
|
|
// SPDX-FileCopyrightText: 2021 Johannes Loher
|
|
|
|
// SPDX-FileCopyrightText: 2021 Oliver Rümpelein
|
|
|
|
// SPDX-FileCopyrightText: 2021 Gesina Schwalbe
|
|
|
|
// SPDX-FileCopyrightText: 2021 Siegfried Krug
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
2021-03-16 08:22:27 +01:00
|
|
|
import { DS4 } from "../config";
|
2021-07-07 19:22:35 +02:00
|
|
|
import { getGame } from "../helpers";
|
2021-03-16 08:22:27 +01:00
|
|
|
|
|
|
|
export default function registerForSetupHooks(): void {
|
|
|
|
Hooks.once("setup", () => {
|
|
|
|
localizeAndSortConfigObjects();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Localizes all objects in {@link DS4.i18n} and sorts them unless they are explicitly excluded.
|
|
|
|
*/
|
|
|
|
function localizeAndSortConfigObjects() {
|
|
|
|
const noSort = ["attributes", "traits", "combatValues", "creatureSizeCategories"];
|
|
|
|
|
|
|
|
const localizeObject = <T extends { [s: string]: string }>(obj: T, sort = true): T => {
|
|
|
|
const localized = Object.entries(obj).map(([key, value]) => {
|
2021-07-07 19:22:35 +02:00
|
|
|
return [key, getGame().i18n.localize(value)];
|
2021-03-16 08:22:27 +01:00
|
|
|
});
|
|
|
|
if (sort) localized.sort((a, b) => a[1].localeCompare(b[1]));
|
|
|
|
return Object.fromEntries(localized);
|
|
|
|
};
|
|
|
|
|
|
|
|
DS4.i18n = Object.fromEntries(
|
|
|
|
Object.entries(DS4.i18n).map(([key, value]) => {
|
|
|
|
return [key, localizeObject(value, !noSort.includes(key))];
|
|
|
|
}),
|
|
|
|
) as typeof DS4.i18n;
|
|
|
|
}
|