feat: ✨ get locales from settings
This commit is contained in:
parent
1b8539cc3a
commit
889ead5101
13 changed files with 35 additions and 43 deletions
|
|
@ -166,7 +166,10 @@ export default defineComponent({
|
|||
this.settings = useAppStore().data.settings();
|
||||
const { locale, availableLocales } = useI18n({ useScope: "global"});
|
||||
this.locale = locale.value;
|
||||
const localeSortArr = ["fr", "nl"];
|
||||
let localeSortArr = [] as Array<string>;
|
||||
window.ipcRendererObject.getJsonData().then((dataJson) => {
|
||||
localeSortArr = dataJson.settings.locales;
|
||||
});
|
||||
this.locales = availableLocales.sort((LocA, LocB) => localeSortArr.indexOf(LocA) - localeSortArr.indexOf(LocB)).map(localeStr => {
|
||||
return {
|
||||
iso: localeStr,
|
||||
|
|
|
|||
|
|
@ -69,7 +69,6 @@
|
|||
'btn ms-3 px-2 mx-0 shadow fw-bold': true,
|
||||
'btn-secondary': locale !== localeObject.iso,
|
||||
'btn-white bg-white': locale === localeObject.iso,
|
||||
'd-none': localeObject.show !== true,
|
||||
}"
|
||||
:title="localeObject.label"
|
||||
data-bs-toggle="tooltip"
|
||||
|
|
@ -97,7 +96,6 @@ type LocaleParams = {
|
|||
iso: string,
|
||||
flag: string,
|
||||
label: string,
|
||||
show: boolean,
|
||||
};
|
||||
|
||||
export default defineComponent({
|
||||
|
|
@ -154,13 +152,15 @@ export default defineComponent({
|
|||
this.settings = useAppStore().data.settings();
|
||||
const { locale, availableLocales } = useI18n({ useScope: "global"});
|
||||
this.locale = locale.value;
|
||||
const localeSortArr = ["fr", "en", "de", "es", "nl"];
|
||||
let localeSortArr = [] as Array<string>;
|
||||
window.ipcRendererObject.getJsonData().then((dataJson) => {
|
||||
localeSortArr = dataJson.settings.locales;
|
||||
});
|
||||
this.locales = availableLocales.sort((LocA, LocB) => localeSortArr.indexOf(LocA) - localeSortArr.indexOf(LocB)).map(localeStr => {
|
||||
return {
|
||||
iso: localeStr,
|
||||
flag: this.t("_flag", {}, localeStr),
|
||||
label: this.t("_lang", {}, localeStr),
|
||||
show: this.t("_show", {}, localeStr) === "true",
|
||||
};
|
||||
});
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,19 +1,18 @@
|
|||
import de from "./locales/de";
|
||||
import en from "./locales/en";
|
||||
import es from "./locales/es";
|
||||
import fr from "./locales/fr";
|
||||
import nl from "./locales/nl";
|
||||
export default defineI18nConfig(async () => {
|
||||
const dataJson = await window.ipcRendererObject.getJsonData();
|
||||
const localeCodes = dataJson.settings.locales;
|
||||
|
||||
export default defineI18nConfig(() => ({
|
||||
legacy: false,
|
||||
globalInjection: true,
|
||||
locale: "fr",
|
||||
fallbackLocale: "fr",
|
||||
messages: {
|
||||
fr,
|
||||
de,
|
||||
en,
|
||||
nl,
|
||||
es
|
||||
const messages: Record<string, any> = {};
|
||||
|
||||
for (const locale of localeCodes) {
|
||||
messages[locale] = (await import(`./locales/${locale}.ts`)).default;
|
||||
}
|
||||
}));
|
||||
|
||||
return {
|
||||
legacy: false,
|
||||
globalInjection: true,
|
||||
locale: "fr",
|
||||
fallbackLocale: "fr",
|
||||
messages,
|
||||
};
|
||||
});
|
||||
|
|
|
|||
10
index.d.ts
vendored
10
index.d.ts
vendored
|
|
@ -1,14 +1,12 @@
|
|||
export { };
|
||||
|
||||
import type { RouteLocation as NRouteLocation } from "vue-router";
|
||||
import type { ipcRendererObject, versions } from "./electron/preload";
|
||||
import type { RouteLocation as NRouteLocation } from "vue-router";
|
||||
import type { ipcRendererObject, versions } from "./electron/preload";
|
||||
|
||||
// * --- MODELS From JSON Schema
|
||||
|
||||
type Locale = string;
|
||||
type i18nFieldList =
|
||||
"name" | "slug" | "description" |
|
||||
"sub_title" | "footer_phrase";
|
||||
type i18nFieldList = "name" | "slug" | "description" | "sub_title" | "footer_phrase";
|
||||
type i18nField = Record<string, string>;
|
||||
type i18nModel = SettingsModel | BrandModel | RangeModel | ProductModel;
|
||||
|
||||
|
|
@ -23,6 +21,8 @@ type AppModel = {
|
|||
|
||||
/** Settings from Showroom Bo */
|
||||
type SettingsModel = {
|
||||
/** Langues disponibles dans l'application */
|
||||
locales: Array<string>
|
||||
/** Sous-titre de l'application */
|
||||
sub_title: i18nField;
|
||||
/** Texte en bas de page */
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
export default {
|
||||
"_flag": "de",
|
||||
"_lang": "Deutsch",
|
||||
"_show": "true",
|
||||
"error_occured": "An error has occured",
|
||||
"loading": "Loading",
|
||||
"show_hide_languages": "Show / Hide languages",
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
export default {
|
||||
"_flag": "en",
|
||||
"_lang": "English",
|
||||
"_show": "true",
|
||||
"error_occured": "An error has occured",
|
||||
"loading": "Loading",
|
||||
"show_hide_languages": "Show / Hide languages",
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
export default {
|
||||
"_flag": "es",
|
||||
"_lang": "Español",
|
||||
"_show": "true",
|
||||
"error_occured": "Se ha producido un error",
|
||||
"loading": "Loading",
|
||||
"show_hide_languages": "Mostrar / Ocultar idiomas",
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
export default {
|
||||
"_flag": "fr",
|
||||
"_lang": "Francais",
|
||||
"_show": "true",
|
||||
"error_occured": "Une erreur est survenue",
|
||||
"loading": "Chargement",
|
||||
"show_hide_languages": "Afficher / Masquer les langues",
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
export default {
|
||||
"_flag": "nl",
|
||||
"_lang": "Nederlands",
|
||||
"_show": "true",
|
||||
"error_occured": "Er is een fout opgetreden",
|
||||
"loading": "Bezig met laden",
|
||||
"show_hide_languages": "Talen tonen/verbergen",
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ export default defineNuxtConfig({
|
|||
pinia: "/node_modules/@pinia/nuxt/node_modules/pinia/dist/pinia.mjs"
|
||||
},
|
||||
i18n: {
|
||||
locales: ["fr", "en", "de", "es", "nl"],
|
||||
locales: UnzipData.loadJsonDataFile()?.settings.locales,
|
||||
defaultLocale: "fr",
|
||||
// * Ajouter aussi la locale dans ce fichier
|
||||
vueI18n: "./i18n.config.ts"
|
||||
|
|
|
|||
|
|
@ -43,10 +43,6 @@
|
|||
"description": "Couleur de la marque",
|
||||
"$ref": "#/$defs/hexcolor"
|
||||
},
|
||||
"shelf": {
|
||||
"description": "Les enfant sont rendus sur un étagere.",
|
||||
"type": "boolean"
|
||||
},
|
||||
"status": {
|
||||
"description": "Visible ? (présent dans l'export).",
|
||||
"type": "boolean"
|
||||
|
|
@ -82,7 +78,6 @@
|
|||
"name",
|
||||
"slug",
|
||||
"color",
|
||||
"shelf",
|
||||
"status",
|
||||
"picture",
|
||||
"created_at",
|
||||
|
|
|
|||
|
|
@ -58,10 +58,6 @@
|
|||
"type": "integer",
|
||||
"minimum": 1
|
||||
},
|
||||
"shelf": {
|
||||
"description": "Les enfant sont rendus sur un étagere.",
|
||||
"type": "boolean"
|
||||
},
|
||||
"status": {
|
||||
"description": "Visible ? (présent dans l'export).",
|
||||
"type": "boolean"
|
||||
|
|
@ -104,7 +100,6 @@
|
|||
"slug",
|
||||
"picture",
|
||||
"order",
|
||||
"shelf",
|
||||
"status",
|
||||
"brand_id",
|
||||
"font_id",
|
||||
|
|
|
|||
|
|
@ -4,6 +4,10 @@
|
|||
"description": "Settings from Showroom Bo",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"locales": {
|
||||
"description": "Langues disponibles dans l'application",
|
||||
"type": "array"
|
||||
},
|
||||
"sub_title": {
|
||||
"description": "Sous-titre de l'application",
|
||||
"type": "object",
|
||||
|
|
@ -59,6 +63,7 @@
|
|||
}
|
||||
},
|
||||
"required": [
|
||||
"locales",
|
||||
"sub_title",
|
||||
"footer_phrase",
|
||||
"logo",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue