2
0

i18n.js 855 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. 'use strict';
  2. const async = require("async");
  3. const i18next = require("i18next");
  4. const Backend = require("i18next-sync-fs-backend");
  5. const rootDir = __dirname.substr(0, __dirname.lastIndexOf("backend"));
  6. let initialized = false;
  7. let lockdown = false;
  8. let i18n;
  9. module.exports = {
  10. init: function(cb) {
  11. i18n = i18next
  12. .use(Backend)
  13. .init({
  14. lng: "en",
  15. debug: false,
  16. fallbackLng: "en",
  17. referenceLng: "en",
  18. backend: {
  19. loadPath: rootDir + "/locales/{{lng}}/{{ns}}.json",
  20. },
  21. ns: ["backend"],
  22. defaultNS: "backend",
  23. keySeparator: false, // we use content as keys
  24. interpolation: {
  25. escapeValue: false, // not needed for react!!
  26. formatSeparator: ",",
  27. },
  28. });
  29. initialized = true;
  30. if (lockdown) return this._lockdown();
  31. cb();
  32. },
  33. i18n,
  34. _lockdown: function() {
  35. lockdown = true;
  36. }
  37. };