From fcbad50a194e0c9ac5821b16008e880d91db6398 Mon Sep 17 00:00:00 2001 From: Simone Orsi Date: Mon, 2 Nov 2020 11:19:20 +0100 Subject: [PATCH 1/4] shopfloor_mobile: get available lang from registry --- shopfloor_mobile/static/wms/src/i18n.js | 6 ++++-- .../static/wms/src/services/registry.js | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/shopfloor_mobile/static/wms/src/i18n.js b/shopfloor_mobile/static/wms/src/i18n.js index 33a6242093..f749097d5c 100644 --- a/shopfloor_mobile/static/wms/src/i18n.js +++ b/shopfloor_mobile/static/wms/src/i18n.js @@ -6,11 +6,13 @@ import {translation_registry} from "./services/translation_registry.js"; +const default_lang = translation_registry.get_default_lang(); +const available_langs = translation_registry.available_langs(); const messages = translation_registry.all(); export const i18n = new VueI18n({ - locale: "en-US", // set locale - availableLocales: ["en-US", "fr-FR", "de-DE"], + locale: default_lang, // set locale + availableLocales: available_langs, messages, // set locale messages }); diff --git a/shopfloor_mobile/static/wms/src/services/registry.js b/shopfloor_mobile/static/wms/src/services/registry.js index 48ff4b963b..bdf980c9b2 100644 --- a/shopfloor_mobile/static/wms/src/services/registry.js +++ b/shopfloor_mobile/static/wms/src/services/registry.js @@ -141,6 +141,7 @@ export class ColorRegistry { export class TranslationRegistry { constructor() { this._data = {}; + this._default_lang = "en-US"; } get(path) { @@ -154,4 +155,19 @@ export class TranslationRegistry { all() { return this._data; } + + available_langs() { + return Object.keys(this._data); + } + + set_default_lang(lang) { + if (_.isEmpty(this._data[lang])) { + throw "Language not available: " + lang; + } + this._default_lang = lang; + } + + get_default_lang() { + return this._default_lang; + } } From f06daacd731534ca65c707e78b121b7277445043 Mon Sep 17 00:00:00 2001 From: Simone Orsi Date: Mon, 2 Nov 2020 11:31:07 +0100 Subject: [PATCH 2/4] shopfloor_mobile: split i18n lang files --- .../static/wms/src/i18n.translation.js | 164 ------------------ .../static/wms/src/i18n/i18n.de.js | 57 ++++++ .../static/wms/src/i18n/i18n.en.js | 68 ++++++++ .../static/wms/src/i18n/i18n.fr.js | 57 ++++++ shopfloor_mobile/templates/assets.xml | 14 +- 5 files changed, 194 insertions(+), 166 deletions(-) delete mode 100644 shopfloor_mobile/static/wms/src/i18n.translation.js create mode 100644 shopfloor_mobile/static/wms/src/i18n/i18n.de.js create mode 100644 shopfloor_mobile/static/wms/src/i18n/i18n.en.js create mode 100644 shopfloor_mobile/static/wms/src/i18n/i18n.fr.js diff --git a/shopfloor_mobile/static/wms/src/i18n.translation.js b/shopfloor_mobile/static/wms/src/i18n.translation.js deleted file mode 100644 index dcf56c412e..0000000000 --- a/shopfloor_mobile/static/wms/src/i18n.translation.js +++ /dev/null @@ -1,164 +0,0 @@ -/** - * Copyright 2020 Camptocamp SA (http://www.camptocamp.com) - * @author Simone Orsi - * License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). - */ - -import {translation_registry} from "./services/translation_registry.js"; - -const messages_en = { - screen: { - home: { - title: "Barcode scanner", - }, - scan_anything: { - title: "Scan {what}", - }, - settings: { - home: { - name: "Settings", - title: "Settings", - }, - language: { - name: "Language", - title: "Select language", - }, - profile: { - name: "Profile", - title: "Select profile", - }, - fullscreen: { - enter: "Go fullscreen", - exit: "Exit fullscreen", - }, - }, - }, - language: { - name: { - English: "English", - French: "French", - German: "German", - }, - }, - btn: { - back: { - title: "Back", - }, - confirm: { - title: "Confirm", - }, - ok: { - title: "Ok", - }, - }, - picking_type: { - lines_count: "{lines_count} lines (over {picking_count} operations).", - priority_lines_count: - "{priority_lines_count} priority lines (over {priority_picking_count} operations).", - }, - zone_picking: { - picking_type_detail: "{lines_count} ({priority_lines_count}) {name}", - }, - order_lines_by: { - priority: "Order by priority", - location: "Order by location", - }, -}; -const messages_fr = { - screen: { - home: { - title: "Barcode scanner", - }, - scan_anything: { - name: "Scanner", - title: "Scanner {what}", - }, - settings: { - home: { - name: "Réglages", - title: "Réglages", - }, - language: { - name: "Langue", - title: "Choisir la langue", - }, - profile: { - name: "Profil", - title: "Choisissez un profil", - }, - fullscreen: { - enter: "Go fullscreen", - exit: "Exit fullscreen", - }, - }, - }, - language: { - name: { - English: "Anglais", - French: "Français", - German: "Allemand", - }, - }, - btn: { - back: { - title: "Retour", - }, - confirm: { - title: "Confirmer", - }, - ok: { - title: "Ok", - }, - }, -}; -const messages_de = { - screen: { - home: { - title: "Barcode scanner", - }, - scan_anything: { - name: "Gescannt", - title: "Gescannt {what}", - }, - settings: { - home: { - name: "Einstellungen", - title: "Einstellungen", - }, - language: { - name: "Sprache", - title: "Sprache auswählen", - }, - profile: { - name: "Profil", - title: "Wähle Profil", - }, - fullscreen: { - enter: "Go fullscreen", - exit: "Exit fullscreen", - }, - }, - }, - language: { - name: { - English: "Englisch", - French: "Französisch", - German: "Deutsche", - }, - }, - btn: { - back: { - title: "Zurück", - }, - confirm: { - title: "Bestätigen", - }, - ok: { - title: "Ok", - }, - }, -}; - -translation_registry.add("en-US", messages_en); -translation_registry.add("fr-FR", messages_fr); -translation_registry.add("de-DE", messages_de); diff --git a/shopfloor_mobile/static/wms/src/i18n/i18n.de.js b/shopfloor_mobile/static/wms/src/i18n/i18n.de.js new file mode 100644 index 0000000000..d606a1b169 --- /dev/null +++ b/shopfloor_mobile/static/wms/src/i18n/i18n.de.js @@ -0,0 +1,57 @@ +/** + * Copyright 2020 Camptocamp SA (http://www.camptocamp.com) + * @author Simone Orsi + * License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + */ + +import {translation_registry} from "../services/translation_registry.js"; + +const messages_de = { + screen: { + home: { + title: "Barcode scanner", + }, + scan_anything: { + name: "Gescannt", + title: "Gescannt {what}", + }, + settings: { + home: { + name: "Einstellungen", + title: "Einstellungen", + }, + language: { + name: "Sprache", + title: "Sprache auswählen", + }, + profile: { + name: "Profil", + title: "Wähle Profil", + }, + fullscreen: { + enter: "Go fullscreen", + exit: "Exit fullscreen", + }, + }, + }, + language: { + name: { + English: "Englisch", + French: "Französisch", + German: "Deutsche", + }, + }, + btn: { + back: { + title: "Zurück", + }, + confirm: { + title: "Bestätigen", + }, + ok: { + title: "Ok", + }, + }, +}; + +translation_registry.add("de-DE", messages_de); diff --git a/shopfloor_mobile/static/wms/src/i18n/i18n.en.js b/shopfloor_mobile/static/wms/src/i18n/i18n.en.js new file mode 100644 index 0000000000..39e1d1a621 --- /dev/null +++ b/shopfloor_mobile/static/wms/src/i18n/i18n.en.js @@ -0,0 +1,68 @@ +/** + * Copyright 2020 Camptocamp SA (http://www.camptocamp.com) + * @author Simone Orsi + * License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + */ + +import {translation_registry} from "../services/translation_registry.js"; + +const messages_en = { + screen: { + home: { + title: "Barcode scanner", + }, + scan_anything: { + title: "Scan {what}", + }, + settings: { + home: { + name: "Settings", + title: "Settings", + }, + language: { + name: "Language", + title: "Select language", + }, + profile: { + name: "Profile", + title: "Select profile", + }, + fullscreen: { + enter: "Go fullscreen", + exit: "Exit fullscreen", + }, + }, + }, + language: { + name: { + English: "English", + French: "French", + German: "German", + }, + }, + btn: { + back: { + title: "Back", + }, + confirm: { + title: "Confirm", + }, + ok: { + title: "Ok", + }, + }, + picking_type: { + lines_count: "{lines_count} lines (over {picking_count} operations).", + priority_lines_count: + "{priority_lines_count} priority lines (over {priority_picking_count} operations).", + }, + zone_picking: { + picking_type_detail: "{lines_count} ({priority_lines_count}) {name}", + }, + order_lines_by: { + priority: "Order by priority", + location: "Order by location", + }, +}; + +translation_registry.add("en-US", messages_en); diff --git a/shopfloor_mobile/static/wms/src/i18n/i18n.fr.js b/shopfloor_mobile/static/wms/src/i18n/i18n.fr.js new file mode 100644 index 0000000000..201a5504ff --- /dev/null +++ b/shopfloor_mobile/static/wms/src/i18n/i18n.fr.js @@ -0,0 +1,57 @@ +/** + * Copyright 2020 Camptocamp SA (http://www.camptocamp.com) + * @author Simone Orsi + * License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + */ + +import {translation_registry} from "../services/translation_registry.js"; + +const messages_fr = { + screen: { + home: { + title: "Barcode scanner", + }, + scan_anything: { + name: "Scanner", + title: "Scanner {what}", + }, + settings: { + home: { + name: "Réglages", + title: "Réglages", + }, + language: { + name: "Langue", + title: "Choisir la langue", + }, + profile: { + name: "Profil", + title: "Choisissez un profil", + }, + fullscreen: { + enter: "Go fullscreen", + exit: "Exit fullscreen", + }, + }, + }, + language: { + name: { + English: "Anglais", + French: "Français", + German: "Allemand", + }, + }, + btn: { + back: { + title: "Retour", + }, + confirm: { + title: "Confirmer", + }, + ok: { + title: "Ok", + }, + }, +}; + +translation_registry.add("fr-FR", messages_fr); diff --git a/shopfloor_mobile/templates/assets.xml b/shopfloor_mobile/templates/assets.xml index a2fd89baa5..1ffaec9127 100644 --- a/shopfloor_mobile/templates/assets.xml +++ b/shopfloor_mobile/templates/assets.xml @@ -90,8 +90,18 @@ type="module" />