How to use the createInstance function from i18next

Find comprehensive JavaScript i18next.createInstance code examples handpicked from public code repositorys.

73
74
75
76
77
78
79
80
81
82
// In case the default locale also has inadequate admin UI phrases
if (fallbackLng[0] !== 'en') {
  fallbackLng.push('en');
}
// Make sure we have our own instance to avoid conflicts with other apos objects
self.i18next = i18next.createInstance({
  fallbackLng,
  // Required to prevent the debugger from complaining
  languages: Object.keys(self.locales),
  // Added later, but required here
fork icon544
star icon0
watch icon125

5
6
7
8
9
10
11
12
13
14
const YAML = require('yaml');

const source = fs.readFileSync(path.join(__dirname, '../locale/en.yaml'), 'utf8');
const en = YAML.parse(source);

const i18n = i18next.createInstance();
i18n.init({
  fallbackLng: 'en',
  lng: 'en',
  defaultNS: 'uwave',
fork icon12
star icon0
watch icon0

203
204
205
206
207
208
209
210
211
212
 * @param {Array<string>} fallbacks A prioritized list of translation fallbacks
 *                                  for the locale.
 * @param {Object<string, Object>} translations A map of locales to translations
 */
static async create (locale, fallbacks, translations) {
  const i18nextInstance = i18next.createInstance();
  await i18nextInstance.init({
    lng: locale,
    nsSeparator: false, // allow keys to be phrases having `:`
    keySeparator: false, // allow keys to be phrases having `.`
fork icon6
star icon23
watch icon8

55
56
57
58
59
60
61
62
63
64
constructor(steps, section = null, templatePath, content = {}) {
  this.steps = steps;
  this.section = section;
  this.templatePath = templatePath;
  this.content = JSON.parse(JSON.stringify(content));
  this.i18next = i18next.createInstance();
  this.i18next.init(this.content, error => {
    if (error) {
      process.emit('applicaton-log', {
        level: 'ERROR',
fork icon7
star icon4
watch icon46

30
31
32
33
34
35
36
37
38
39
40
    return new stepObject(steps, section.toString(), resourcePath, i18next, schema);
};


const initSteps = (stepLocations) => {
    const content = requireDir(module, '../', {include: /resources/});
    i18next.createInstance();
    i18next.init(content, (err) => {
        if (err) {
            logger.error(err);
        }
fork icon1
star icon0
watch icon0

26
27
28
29
30
31
32
33
34
35
36
37


class i18n {


  constructor() {
    if (!this.i18nInstance) {
      this.i18nInstance = i18Next.createInstance()
    }
    this.loaded = false
    this.loading = false
  }
fork icon0
star icon0
watch icon1

+ 24 other calls in file

60
61
62
63
64
65
66
67
68
69
  return this.i18next;
}

createI18nextInstance() {
  this.log('info', {}, 'Create i18next instacne');
  const newI18next = i18next.createInstance();
  this.plugins.forEach(plugin => {
    newI18next.use(plugin);
  });
  return newI18next;
fork icon0
star icon0
watch icon4

+ 3 other calls in file