• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

i18next / react-i18next / 22771652522

06 Mar 2026 04:12PM UTC coverage: 97.529% (-0.2%) from 97.682%
22771652522

push

github

adrai
16.5.6

690 of 745 branches covered (92.62%)

2842 of 2914 relevant lines covered (97.53%)

63.85 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

91.53
/src/context.js
1
import { createContext } from 'react';
1✔
2
import { getDefaults, setDefaults } from './defaults.js';
1✔
3
import { getI18n, setI18n } from './i18nInstance.js';
1✔
4
import { initReactI18next } from './initReactI18next.js';
1✔
5

1✔
6
export { getDefaults, setDefaults, getI18n, setI18n, initReactI18next };
7

1✔
8
export const I18nContext = createContext();
1✔
9

1✔
10
export class ReportNamespaces {
1✔
11
  constructor() {
1✔
12
    this.usedNamespaces = {};
27✔
13
  }
27✔
14

1✔
15
  addUsedNamespaces(namespaces) {
1✔
16
    namespaces.forEach((ns) => {
69✔
17
      if (!this.usedNamespaces[ns]) this.usedNamespaces[ns] = true;
83✔
18
    });
69✔
19
  }
69✔
20

1✔
21
  getUsedNamespaces() {
1✔
22
    return Object.keys(this.usedNamespaces);
3✔
23
  }
3✔
24
}
1✔
25

1✔
26
export const composeInitialProps = (ForComponent) => async (ctx) => {
1✔
27
  const componentsInitialProps = (await ForComponent.getInitialProps?.(ctx)) ?? {};
1!
28

1✔
29
  const i18nInitialProps = getInitialProps();
1✔
30

1✔
31
  return {
1✔
32
    ...componentsInitialProps,
1✔
33
    ...i18nInitialProps,
1✔
34
  };
1✔
35
};
1✔
36

1✔
37
export const getInitialProps = () => {
1✔
38
  const i18n = getI18n();
1✔
39
  if (!i18n) {
1!
40
    console.warn(
×
41
      'react-i18next:: getInitialProps: You will need to pass in an i18next instance by using initReactI18next',
×
42
    );
×
43
    return {};
×
44
  }
×
45
  const namespaces = i18n.reportNamespaces?.getUsedNamespaces() ?? [];
1!
46

1✔
47
  const ret = {};
1✔
48
  const initialI18nStore = {};
1✔
49
  i18n.languages.forEach((l) => {
1✔
50
    initialI18nStore[l] = {};
1✔
51
    namespaces.forEach((ns) => {
1✔
52
      initialI18nStore[l][ns] = i18n.getResourceBundle(l, ns) || {};
1!
53
    });
1✔
54
  });
1✔
55

1✔
56
  ret.initialI18nStore = initialI18nStore;
1✔
57
  ret.initialLanguage = i18n.language;
1✔
58

1✔
59
  return ret;
1✔
60
};
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc