diff --git a/src/core/HMR.js b/src/core/HMR.js index e0a9f64..87bd632 100644 --- a/src/core/HMR.js +++ b/src/core/HMR.js @@ -1,8 +1,8 @@ /** * @typedef {{ - * "t18s:createLocale": { locale: string } - * "t18s:removeLocale": { locale: string } - * "t18s:invalidateLocale": { locale: string } + * "t18s:addDictionary": { locale: string, domain: string } + * "t18s:removeDictionary": { locale: string, domain: string } + * "t18s:reloadDictionary": { locale: string, domain: string } * }} HMREventMap */ diff --git a/src/core/MessageCatalogue.js b/src/core/MessageCatalogue.js index d06aa34..b42efa3 100644 --- a/src/core/MessageCatalogue.js +++ b/src/core/MessageCatalogue.js @@ -7,9 +7,9 @@ import { DoubleKeyedMap } from "./utils/DoubleKeyedMap.js"; * The valid events that may be emitted by a locale registry. * * @typedef {{ - * "locale_added": CustomEvent<{ locale: string, dictionary: Dictionary }>, - * "locale_removed": CustomEvent<{ locale: string }>, - * "locale_updated": CustomEvent<{ locale: string, dictionary: Dictionary }>, + * "dictionary_added": CustomEvent<{ locale: string, domain: string, dictionary: Dictionary }>, + * "dictionary_removed": CustomEvent<{ locale: string, domain:string }>, + * "dictionary_changed": CustomEvent<{ locale: string, domain: string, dictionary: Dictionary }>, * "changed": CustomEvent<{}>; * }} LocaleRegistryEventMap */ @@ -48,7 +48,7 @@ export class MessageCatalogue extends MessageCatalogueEventTarget { this.#files.set(locale, domain, filePath); this.#dictionaries.set(locale, domain, dictionary); - this.#dispatch("locale_added", { locale, dictionary }); + this.#dispatch("dictionary_added", { locale, domain, dictionary }); this.#dispatch("changed", {}); } @@ -61,7 +61,7 @@ export class MessageCatalogue extends MessageCatalogueEventTarget { this.#dictionaries.delete(locale, domain); this.#files.delete(locale, domain); - this.#dispatch("locale_removed", { locale }); + this.#dispatch("dictionary_removed", { locale, domain }); this.#dispatch("changed", {}); } @@ -77,7 +77,7 @@ export class MessageCatalogue extends MessageCatalogueEventTarget { throw new LocaleNotFoundException(locale); this.#dictionaries.set(locale, domain, dictionary); this.#dispatch("changed", {}); - this.#dispatch("locale_updated", { locale, dictionary }); + this.#dispatch("dictionary_changed", { locale, domain, dictionary }); } /** diff --git a/src/core/codegen/main.js b/src/core/codegen/main.js index 93394cd..ac67cd1 100644 --- a/src/core/codegen/main.js +++ b/src/core/codegen/main.js @@ -128,9 +128,8 @@ export function generateMainModuleCode(Catalogue, verbose) { } }); - if(import.meta.hot) { - - import.meta.hot.on("t18s:createLocale", async (data) => { + if(import.meta.hot) { + import.meta.hot.on("t18s:addDictionary", async (data) => { locales.update((locales) => [...locales, data.locale]); //Force-reload the module - Add a random query parameter to bust the cache @@ -142,7 +141,7 @@ export function generateMainModuleCode(Catalogue, verbose) { t.set(getMessage); //update the store }); - import.meta.hot.on("t18s:invalidateLocale", async (data) => { + import.meta.hot.on("t18s:reloadDictionary", async (data) => { //Force-reload the module - Add a random query parameter to bust the cache const newMessages = (await import(/* @vite-ignore */ "/@id/__x00__t18s-dictionary:" + data.locale + ":messages" + "?" + Math.random())).default; @@ -154,7 +153,7 @@ export function generateMainModuleCode(Catalogue, verbose) { t.set(getMessage); //update the store }); - import.meta.hot.on("t18s:removeLocale", async (data) => { + import.meta.hot.on("t18s:removeDictionary", async (data) => { ${ verbose ? 'console.info("[t18s] Removing locale " + data.locale);\n' diff --git a/src/core/index.js b/src/core/index.js index 2e35fda..7daacc4 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -55,17 +55,20 @@ export function t18sCore(pluginConfig) { const Catalogue = new MessageCatalogue(); Catalogue.addEventListener("changed", async () => await regenerateDTS()); - Catalogue.addEventListener("locale_added", (e) => { + Catalogue.addEventListener("dictionary_added", (e) => { reporter.localeCreated(e.detail.locale); - dispatch("t18s:createLocale", { locale: e.detail.locale }); + dispatch("t18s:addDictionary", { + locale: e.detail.locale, + domain: e.detail.domain, + }); }); - Catalogue.addEventListener("locale_removed", (e) => { + Catalogue.addEventListener("dictionary_removed", (e) => { reporter.localeDeleted(e.detail.locale); - dispatch("t18s:removeLocale", { locale: e.detail.locale }); + dispatch("t18s:removeDictionary", { locale: e.detail.locale, domain: e.detail.domain }); }); - Catalogue.addEventListener("locale_updated", (e) => { + Catalogue.addEventListener("dictionary_changed", (e) => { reporter.localeUpdated(e.detail.locale); - dispatch("t18s:invalidateLocale", { locale: e.detail.locale }); + dispatch("t18s:reloadDictionary", { locale: e.detail.locale, domain: e.detail.domain }); }); /** Handles interactions with translation files */