From cbcd2136cd80395eff898738747c52c4b301fd56 Mon Sep 17 00:00:00 2001 From: Dixsie Wolmers Date: Thu, 30 Jan 2020 20:58:37 -0600 Subject: Set up initial language translation - Add i18n internationalization plugin - Create json files for group 0 English and Spanish - Uses $t method to set up initial translations on login page - Meta title is translated using i18n in App.vue and PageTitle.Vue Signed-off-by: Dixsie Wolmers Change-Id: Ifce9f5e54d96f8b2a13239ad6178892f99fc4537 --- src/i18n.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/i18n.js (limited to 'src/i18n.js') diff --git a/src/i18n.js b/src/i18n.js new file mode 100644 index 00000000..09b3f4ca --- /dev/null +++ b/src/i18n.js @@ -0,0 +1,29 @@ +import Vue from 'vue'; +import VueI18n from 'vue-i18n'; + +Vue.use(VueI18n); + +function loadLocaleMessages() { + const locales = require.context( + './locales', + true, + /[A-Za-z0-9-_,\s]+\.json$/i + ); + const messages = {}; + locales.keys().forEach(key => { + const matched = key.match(/([A-Za-z0-9-_]+)\./i); + if (matched && matched.length > 1) { + const locale = matched[1]; + messages[locale] = locales(key); + } + }); + return messages; +} + +export default new VueI18n({ + // default language is English + locale: 'en', + // locale messages with a message key that doesn't exist will fallback to English + fallbackLocale: 'en', + messages: loadLocaleMessages() +}); -- cgit v1.2.3