@tolgee/core 4.9.0-rc.b7a4088.0 → 4.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (148) hide show
  1. package/dist/Constants/Global.d.ts +0 -0
  2. package/dist/Constants/ModifierKey.d.ts +0 -0
  3. package/dist/Errors/ApiHttpError.d.ts +0 -0
  4. package/dist/Observer.d.ts +0 -0
  5. package/dist/Observer.test.d.ts +0 -0
  6. package/dist/Properties.d.ts +0 -0
  7. package/dist/Properties.test.d.ts +0 -0
  8. package/dist/Tolgee.d.ts +0 -0
  9. package/dist/Tolgee.test.d.ts +0 -0
  10. package/dist/TolgeeConfig.d.ts +0 -0
  11. package/dist/TolgeeConfig.test.d.ts +0 -0
  12. package/dist/__integration/FormatterIcu.test.d.ts +0 -0
  13. package/dist/__integration/FormatterMissing.d.ts +0 -0
  14. package/dist/__integration/Tolgee.test.d.ts +0 -0
  15. package/dist/__integration/TolgeeInvisible.test.d.ts +0 -0
  16. package/dist/__integration/mockTranslations.d.ts +0 -0
  17. package/dist/__integration/testConfig.d.ts +0 -0
  18. package/dist/__testFixtures/classMock.d.ts +0 -0
  19. package/dist/__testFixtures/createElement.d.ts +0 -0
  20. package/dist/__testFixtures/createTestDom.d.ts +0 -0
  21. package/dist/__testFixtures/mocked.d.ts +0 -0
  22. package/dist/__testFixtures/setupAfterEnv.d.ts +0 -0
  23. package/dist/helpers/NodeHelper.d.ts +0 -0
  24. package/dist/helpers/TextHelper.d.ts +0 -0
  25. package/dist/helpers/TextHelper.test.d.ts +0 -0
  26. package/dist/helpers/commonTypes.d.ts +0 -0
  27. package/dist/helpers/encoderPolyfill.d.ts +0 -0
  28. package/dist/helpers/secret.d.ts +0 -0
  29. package/dist/helpers/secret.test.d.ts +0 -0
  30. package/dist/helpers/sleep.d.ts +0 -0
  31. package/dist/highlighter/HighlightFunctionsInitializer.d.ts +0 -0
  32. package/dist/highlighter/HighlightFunctionsInitializer.test.d.ts +0 -0
  33. package/dist/highlighter/MouseEventHandler.d.ts +0 -0
  34. package/dist/highlighter/MouseEventHandler.test.d.ts +0 -0
  35. package/dist/highlighter/TranslationHighlighter.d.ts +0 -0
  36. package/dist/highlighter/TranslationHighlighter.test.d.ts +0 -0
  37. package/dist/index.d.ts +0 -0
  38. package/dist/internal.d.ts +0 -0
  39. package/dist/modules/IcuFormatter.d.ts +0 -0
  40. package/dist/modules/IcuFormatter.test.d.ts +1 -0
  41. package/dist/modules/index.d.ts +0 -0
  42. package/dist/services/ApiHttpService.d.ts +0 -0
  43. package/dist/services/CoreService.d.ts +0 -0
  44. package/dist/services/CoreService.test.d.ts +0 -0
  45. package/dist/services/DependencyService.d.ts +0 -0
  46. package/dist/services/DependencyService.test.d.ts +0 -0
  47. package/dist/services/ElementRegistrar.d.ts +0 -0
  48. package/dist/services/ElementRegistrar.test.d.ts +0 -0
  49. package/dist/services/EventEmitter.d.ts +0 -0
  50. package/dist/services/EventService.d.ts +0 -0
  51. package/dist/services/ModuleService.d.ts +0 -0
  52. package/dist/services/ScreenshotService.d.ts +0 -0
  53. package/dist/services/Subscription.d.ts +0 -0
  54. package/dist/services/TextService.d.ts +0 -0
  55. package/dist/services/TextService.test.d.ts +0 -0
  56. package/dist/services/TranslationService.d.ts +0 -0
  57. package/dist/services/TranslationService.test.d.ts +0 -0
  58. package/dist/services/__mocks__/CoreService.d.ts +0 -0
  59. package/dist/tolgee.cjs.js +23 -3
  60. package/dist/tolgee.cjs.js.map +1 -1
  61. package/dist/tolgee.cjs.min.js +1 -1
  62. package/dist/tolgee.cjs.min.js.map +1 -1
  63. package/dist/tolgee.esm.min.mjs +1 -1
  64. package/dist/tolgee.esm.min.mjs.map +1 -1
  65. package/dist/tolgee.esm.mjs +23 -3
  66. package/dist/tolgee.esm.mjs.map +1 -1
  67. package/dist/tolgee.umd.js +23 -3
  68. package/dist/tolgee.umd.js.map +1 -1
  69. package/dist/tolgee.umd.min.js +1 -1
  70. package/dist/tolgee.umd.min.js.map +1 -1
  71. package/dist/toolsManager/Messages.d.ts +0 -0
  72. package/dist/toolsManager/Messages.test.d.ts +0 -0
  73. package/dist/toolsManager/PluginManager.d.ts +0 -0
  74. package/dist/toolsManager/PluginManager.test.d.ts +0 -0
  75. package/dist/types/DTOs.d.ts +0 -0
  76. package/dist/types/apiSchema.generated.d.ts +0 -0
  77. package/dist/types.d.ts +0 -0
  78. package/dist/wrappers/AbstractWrapper.d.ts +0 -0
  79. package/dist/wrappers/NodeHandler.d.ts +0 -0
  80. package/dist/wrappers/WrappedHandler.d.ts +0 -0
  81. package/dist/wrappers/invisible/AttributeHandler.d.ts +0 -0
  82. package/dist/wrappers/invisible/Coder.d.ts +0 -0
  83. package/dist/wrappers/invisible/ContentHandler.d.ts +0 -0
  84. package/dist/wrappers/invisible/CoreHandler.d.ts +0 -0
  85. package/dist/wrappers/invisible/InvisibleWrapper.d.ts +0 -0
  86. package/dist/wrappers/invisible/ValueMemory.d.ts +0 -0
  87. package/dist/wrappers/invisible/ValueMemory.test.d.ts +0 -0
  88. package/dist/wrappers/text/AttributeHandler.d.ts +0 -0
  89. package/dist/wrappers/text/AttributeHandler.test.d.ts +0 -0
  90. package/dist/wrappers/text/Coder.d.ts +0 -0
  91. package/dist/wrappers/text/Coder.test.d.ts +0 -0
  92. package/dist/wrappers/text/ContentHandler.d.ts +0 -0
  93. package/dist/wrappers/text/ContentHandler.test.d.ts +0 -0
  94. package/dist/wrappers/text/CoreHandler.d.ts +0 -0
  95. package/dist/wrappers/text/CoreHandler.test.d.ts +0 -0
  96. package/dist/wrappers/text/TextWrapper.d.ts +0 -0
  97. package/lib/Constants/Global.d.ts +0 -0
  98. package/lib/Constants/ModifierKey.d.ts +0 -0
  99. package/lib/Errors/ApiHttpError.d.ts +0 -0
  100. package/lib/Observer.d.ts +0 -0
  101. package/lib/Properties.d.ts +0 -0
  102. package/lib/Tolgee.d.ts +0 -0
  103. package/lib/TolgeeConfig.d.ts +0 -0
  104. package/lib/helpers/NodeHelper.d.ts +0 -0
  105. package/lib/helpers/TextHelper.d.ts +0 -0
  106. package/lib/helpers/commonTypes.d.ts +0 -0
  107. package/lib/helpers/encoderPolyfill.d.ts +0 -0
  108. package/lib/helpers/secret.d.ts +0 -0
  109. package/lib/helpers/sleep.d.ts +0 -0
  110. package/lib/highlighter/HighlightFunctionsInitializer.d.ts +0 -0
  111. package/lib/highlighter/MouseEventHandler.d.ts +0 -0
  112. package/lib/highlighter/TranslationHighlighter.d.ts +0 -0
  113. package/lib/index.d.ts +0 -0
  114. package/lib/modules/IcuFormatter.d.ts +0 -0
  115. package/lib/modules/index.d.ts +0 -0
  116. package/lib/services/ApiHttpService.d.ts +0 -0
  117. package/lib/services/CoreService.d.ts +0 -0
  118. package/lib/services/DependencyService.d.ts +0 -0
  119. package/lib/services/ElementRegistrar.d.ts +0 -0
  120. package/lib/services/EventEmitter.d.ts +0 -0
  121. package/lib/services/EventService.d.ts +0 -0
  122. package/lib/services/ModuleService.d.ts +0 -0
  123. package/lib/services/ScreenshotService.d.ts +0 -0
  124. package/lib/services/Subscription.d.ts +0 -0
  125. package/lib/services/TextService.d.ts +0 -0
  126. package/lib/services/TranslationService.d.ts +0 -0
  127. package/lib/toolsManager/Messages.d.ts +0 -0
  128. package/lib/toolsManager/PluginManager.d.ts +0 -0
  129. package/lib/types/DTOs.d.ts +0 -0
  130. package/lib/types/apiSchema.generated.d.ts +0 -0
  131. package/lib/types.d.ts +0 -0
  132. package/lib/wrappers/AbstractWrapper.d.ts +0 -0
  133. package/lib/wrappers/NodeHandler.d.ts +0 -0
  134. package/lib/wrappers/WrappedHandler.d.ts +0 -0
  135. package/lib/wrappers/invisible/AttributeHandler.d.ts +0 -0
  136. package/lib/wrappers/invisible/Coder.d.ts +0 -0
  137. package/lib/wrappers/invisible/ContentHandler.d.ts +0 -0
  138. package/lib/wrappers/invisible/CoreHandler.d.ts +0 -0
  139. package/lib/wrappers/invisible/InvisibleWrapper.d.ts +0 -0
  140. package/lib/wrappers/invisible/ValueMemory.d.ts +0 -0
  141. package/lib/wrappers/text/AttributeHandler.d.ts +0 -0
  142. package/lib/wrappers/text/Coder.d.ts +0 -0
  143. package/lib/wrappers/text/ContentHandler.d.ts +0 -0
  144. package/lib/wrappers/text/CoreHandler.d.ts +0 -0
  145. package/lib/wrappers/text/TextWrapper.d.ts +0 -0
  146. package/package.json +2 -2
  147. package/src/modules/IcuFormatter.test.ts +21 -0
  148. package/src/modules/IcuFormatter.ts +24 -2
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
package/dist/types.d.ts CHANGED
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
package/lib/Observer.d.ts CHANGED
File without changes
File without changes
package/lib/Tolgee.d.ts CHANGED
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
package/lib/index.d.ts CHANGED
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
package/lib/types.d.ts CHANGED
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tolgee/core",
3
- "version": "4.9.0-rc.b7a4088.0",
3
+ "version": "4.9.2",
4
4
  "description": "Library providing ability to translate messages directly in context of developed application.",
5
5
  "main": "index.js",
6
6
  "module": "./dist/tolgee.esm.mjs",
@@ -67,7 +67,7 @@
67
67
  "require": "./dist/tolgee.cjs.js",
68
68
  "import": "./dist/tolgee.esm.mjs"
69
69
  },
70
- "gitHead": "eb9351083de345c08157103aa758a8c6ef370d73",
70
+ "gitHead": "dcbded7f7d158facb5eac126baf2ec1e1dc5699e",
71
71
  "publishConfig": {
72
72
  "access": "public"
73
73
  }
@@ -0,0 +1,21 @@
1
+ jest.autoMockOff();
2
+ import { IcuFormatter } from './IcuFormatter';
3
+
4
+ describe('icu formatter', () => {
5
+ it('formats simple string', () => {
6
+ const formatter = new IcuFormatter();
7
+ const result = formatter.format({
8
+ translation: 'result is {number, number}',
9
+ params: { number: 42000 },
10
+ language: 'en',
11
+ });
12
+ expect(result).toEqual('result is 42,000');
13
+ });
14
+
15
+ it('fixes invalid locale', () => {
16
+ const formatter = new IcuFormatter() as any;
17
+ expect(formatter.getLocale('en_GB')).toEqual('en-GB');
18
+ expect(formatter.getLocale('en_GB-nonsenceeeee')).toEqual('en-GB');
19
+ expect(formatter.getLocale('cs CZ')).toEqual('cs-CZ');
20
+ });
21
+ });
@@ -3,14 +3,36 @@ import { TolgeeModule } from '../types';
3
3
  export const IcuFormatter: TolgeeModule = class {
4
4
  static type = 'formatter' as const;
5
5
 
6
- cache = new Map<string, IntlMessageFormat>();
6
+ private locales = new Map() as Map<string, string>;
7
+
8
+ isLocaleValid(locale: string) {
9
+ try {
10
+ return Boolean(Intl.NumberFormat.supportedLocalesOf(locale).length);
11
+ } catch {
12
+ return false;
13
+ }
14
+ }
15
+
16
+ getLocale(language: string) {
17
+ if (!this.locales.get(language)) {
18
+ let localeCandidate: string = String(language).replace(/[^a-zA-Z]/g, '-');
19
+ while (!this.isLocaleValid(localeCandidate)) {
20
+ localeCandidate =
21
+ localeCandidate.split('-').slice(0, -1).join('-') || 'en';
22
+ }
23
+ this.locales.set(language, localeCandidate);
24
+ }
25
+ return this.locales.get(language);
26
+ }
7
27
 
8
28
  format({ translation, language, params }) {
9
29
  const ignoreTag = !Object.values(params).find(
10
30
  (p) => typeof p === 'function'
11
31
  );
12
32
 
13
- return new IntlMessageFormat(translation, language, undefined, {
33
+ const locale = this.getLocale(language);
34
+
35
+ return new IntlMessageFormat(translation, locale, undefined, {
14
36
  ignoreTag,
15
37
  }).format(params) as string;
16
38
  }