Adds a util file for easier language adding

This commit is contained in:
Alicia Sykes 2021-07-24 16:47:14 +01:00
parent 55aeb44c1a
commit c8a73dbda6
2 changed files with 27 additions and 8 deletions

View File

@ -15,9 +15,7 @@ import router from '@/router';
import registerServiceWorker from '@/registerServiceWorker';
import clickOutside from '@/utils/ClickOutside';
import { toastedOptions } from '@/utils/defaults';
// Locales - Import translation files here!
import en from '@/assets/locales/en-GB.json';
import { messages } from '@/utils/languages';
Vue.use(VueI18n);
Vue.use(VTooltip);
@ -29,12 +27,10 @@ Vue.directive('clickOutside', clickOutside);
Vue.config.productionTip = false;
// Setup translations
const messages = { en }; // <-- Add new language files here!
// Setup i18n translations
const i18n = new VueI18n({
locale: 'en',
fallbackLocale: 'en',
locale: 'en-GB',
fallbackLocale: 'en-GB',
messages,
});

23
src/utils/languages.js Normal file
View File

@ -0,0 +1,23 @@
// Locales - Import translation files here!
import enGB from '@/assets/locales/en-GB.json';
// Language data - Add your country name, locale code and imported file here
export const languages = [
{
name: 'English',
code: 'en-GB',
locale: enGB,
flag: '🇬🇧',
},
// Including:
// name - Human readable name for your language
// code - ISO language code
// locale - The file that you imported above
// flag - A nice emoji flag (optional)
];
const i18nMessages = {};
languages.forEach((lang) => {
i18nMessages[lang.code] = lang.locale;
});
export const messages = i18nMessages;