panter / vue-i18next

Internationalization for vue using the i18next i18n ecosystem.
https://panter.github.io/vue-i18next/
176 stars 47 forks source link

feat(namespace): introduce namespaces #5

Closed claudiocro closed 7 years ago

claudiocro commented 7 years ago

The namespace will be loaded with (loadNamespaces)[http://i18next.com/docs/api/#load-namespaces],so one can lazy load namespaces for components.

const locales = {
  en: {
    tos: 'Term of Service',
    term: 'I accept {{0}}. {{1}}.',
    promise: 'I promise',
  }
};

i18next.init({
  lng: 'en',
  fallbackLng: 'en',
  resources: {
    en: { common: locales.en },
  },
});

const i18n = new VueI18next(i18next);

Vue.component('app', {
  i18nOptions: { namespaces: 'common'},
  template: `
    <div>
      <i18next path="term" tag="label">
        <a href="#" target="_blank">{{ $t("tos") }}</a>
        <strong>{{ $t("promise") }}</strong>
      </i18next>
    </div>`,
});
coveralls commented 7 years ago

Coverage Status

Coverage increased (+0.4%) to 97.849% when pulling 36823168b82fa301674544162a7062e74b9a6047 on features/namespaces into 44bd76e28e7ac613065ec5ec13a2f636f2c397f4 on master.