From c1fe94a630a88c4f7203d54f34985c109030791c Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Sat, 19 Aug 2023 15:32:48 +0200 Subject: translations --- resources/js/db.js | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 77 insertions(+), 1 deletion(-) (limited to 'resources/js/db.js') diff --git a/resources/js/db.js b/resources/js/db.js index 64b2e9b..648c54c 100644 --- a/resources/js/db.js +++ b/resources/js/db.js @@ -1,13 +1,74 @@ +/** + * @typedef {Object} DB_Evolution + * @property {string} path + * @property {string} monster_slug + * @property {string} at_level + * @property {string} item + */ + +// + const DB = { + /** + * @type {string[]} + */ allMonsters: [], + + /** + * @typedef {Object.} DB_Animation + * + * @type {DB_Animation} + */ allAnimations: {}, + + /** + * @type {string[]} + */ allItems: [], + + /** + * @typedef {Object} DB_Monster + * + * @type {Object.} + */ monsters: {}, + + /** + * @typedef {Object} DB_Shape + * + * @type {Object.} + */ shapes: {}, + + /** + * @typedef {Object} DB_Element + * + * @type {Object.} + */ elements: {}, + + /** + * @typedef {Object} DB_Technique + * + * @type {Object.} + */ techniques: {}, + + /** + * @typedef {Object} DB_StatusEffect + * + * @type {Object.} + */ statusEffects: {}, + + /** + * @typedef {Object} DB_Item + * + * @type {Object.} + */ items: {}, + + translations: {}, }; async function initializeDB () { @@ -20,6 +81,8 @@ async function initializeDB () { for (const element of Object.keys(ElementType)) { DB.elements[element] = await fetch(`/modules/tuxemon/mods/tuxemon/db/element/${element}.json`).then((response) => response.json()); } + + await fetchTranslation(Memory.state.language); } /** @@ -67,7 +130,7 @@ async function fetchStatusEffect (slug) { /** * @param {string} slug * - * @returns {Promise} + * @returns {Promise} */ async function fetchItem (slug) { if (! DB.items[slug]) { @@ -76,3 +139,16 @@ async function fetchItem (slug) { return new Item(slug); } + +/** + * @param {string} locale + * + * @returns {Promise} + */ +async function fetchTranslation (locale) { + if (! DB.translations[locale]) { + DB.translations[locale] = await fetch(`/db/i18n/${locale}.json`).then((response) => response.json()); + } + + return DB.translations[locale]; +} -- cgit v1.2.3