ma-localization-js
v1.0.8
Published
Javascript implementation of the ma localization library API
Downloads
29
Readme
Usage
const trans = await MAlocalization('PROJECT_ID', 'API_KEY', 'https://functionEndpointUrl');
trans.setLanguage(lang);
const msg = trans.translate(key,placeholders);
const availableLocales = trans.getAvailableLanguages();
const msgsInVueFormat = trans.getVue(locale);
Function types
translate: (string, null | Object | Array<string | number> = null) => string;
setLanguage: (string) => boolean;
getAvailableLanguages: () => string[];
getVue: () => {[key:string]:string};
Vue trans example
import { createApp, nextTick } from 'vue'; import { createI18n } from 'vue-i18n';
const i18n = createI18n({ legacy: false, locale: localStorage.getItem('locale') ?? 'en', messages: defaultTranslations }); let trans: any; let availableLocales = ['en', 'da'];
async function loadLocaleMessages() { if (!trans) trans = await MAlocalization('PROJECT_ID', 'API_KEY', 'https://functionEndpointUrl'); availableLocales = trans.getAvailableLanguages(); availableLocales.forEach((locale) => { const msgs = trans.getVue(locale); i18n.global.setLocaleMessage(locale, msgs); }); return nextTick(); }
createApp(App).use(i18n).mount('#app'); loadLocaleMessages();