Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

3 лет назад
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. export function warn() {
  2. if (console && console.warn) {
  3. var _console;
  4. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  5. args[_key] = arguments[_key];
  6. }
  7. if (typeof args[0] === 'string') args[0] = "react-i18next:: ".concat(args[0]);
  8. (_console = console).warn.apply(_console, args);
  9. }
  10. }
  11. var alreadyWarned = {};
  12. export function warnOnce() {
  13. for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
  14. args[_key2] = arguments[_key2];
  15. }
  16. if (typeof args[0] === 'string' && alreadyWarned[args[0]]) return;
  17. if (typeof args[0] === 'string') alreadyWarned[args[0]] = new Date();
  18. warn.apply(void 0, args);
  19. } // not needed right now
  20. //
  21. // export function deprecated(...args) {
  22. // if (process && process.env && (!process.env.NODE_ENV || process.env.NODE_ENV === 'development')) {
  23. // if (typeof args[0] === 'string') args[0] = `deprecation warning -> ${args[0]}`;
  24. // warnOnce(...args);
  25. // }
  26. // }
  27. export function loadNamespaces(i18n, ns, cb) {
  28. i18n.loadNamespaces(ns, function () {
  29. // delay ready if not yet initialized i18n instance
  30. if (i18n.isInitialized) {
  31. cb();
  32. } else {
  33. var initialized = function initialized() {
  34. // due to emitter removing issue in i18next we need to delay remove
  35. setTimeout(function () {
  36. i18n.off('initialized', initialized);
  37. }, 0);
  38. cb();
  39. };
  40. i18n.on('initialized', initialized);
  41. }
  42. });
  43. }
  44. export function hasLoadedNamespace(ns, i18n) {
  45. if (!i18n.languages || !i18n.languages.length) {
  46. warnOnce('i18n.languages were undefined or empty', i18n.languages);
  47. return true;
  48. }
  49. var lng = i18n.languages[0];
  50. var fallbackLng = i18n.options ? i18n.options.fallbackLng : false;
  51. var lastLng = i18n.languages[i18n.languages.length - 1]; // we're in cimode so this shall pass
  52. if (lng.toLowerCase() === 'cimode') return true;
  53. var loadNotPending = function loadNotPending(l, n) {
  54. var loadState = i18n.services.backendConnector.state["".concat(l, "|").concat(n)];
  55. return loadState === -1 || loadState === 2;
  56. }; // loaded -> SUCCESS
  57. if (i18n.hasResourceBundle(lng, ns)) return true; // were not loading at all -> SEMI SUCCESS
  58. if (!i18n.services.backendConnector.backend) return true; // failed loading ns - but at least fallback is not pending -> SEMI SUCCESS
  59. if (loadNotPending(lng, ns) && (!fallbackLng || loadNotPending(lastLng, ns))) return true;
  60. return false;
  61. }
  62. export function getDisplayName(Component) {
  63. return Component.displayName || Component.name || (typeof Component === 'string' && Component.length > 0 ? Component : 'Unknown');
  64. }