@taon-dev/i18n 0.0.1 → 0.0.6

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 (276) hide show
  1. package/VERIFIED-BUILD-DATA.jsonc +2 -2
  2. package/bin/start.js +1 -1
  3. package/browser/fesm2022/i18n-browser.mjs +1441 -406
  4. package/browser/fesm2022/i18n-browser.mjs.map +1 -1
  5. package/browser/package.json +1 -1
  6. package/browser/types/i18n-browser.d.ts +146 -305
  7. package/browser-prod/fesm2022/i18n-browser-prod.mjs +1429 -405
  8. package/browser-prod/fesm2022/i18n-browser-prod.mjs.map +1 -1
  9. package/browser-prod/package.json +1 -1
  10. package/browser-prod/types/i18n-browser-prod.d.ts +140 -305
  11. package/browser-prod.split-namespaces.json +26 -2
  12. package/html/app/main-page/main-page.container.html +4 -0
  13. package/html/assets/generated/pwa/html-pwa.html +53 -53
  14. package/lib/build-info._auto-generated_.d.ts +1 -1
  15. package/lib/build-info._auto-generated_.js +1 -1
  16. package/lib/index._auto-generated_.d.ts +9 -14
  17. package/lib/index._auto-generated_.js +9 -14
  18. package/lib/index._auto-generated_.js.map +1 -1
  19. package/lib/package.json +1 -1
  20. package/lib/start-cli.js +6 -4
  21. package/lib/start-cli.js.map +1 -1
  22. package/lib/translate.directive.d.ts +15 -0
  23. package/lib/translate.pipe.d.ts +10 -0
  24. package/lib/translate.service.d.ts +13 -0
  25. package/lib/translation-manager.d.ts +33 -0
  26. package/lib/translation-manager.js +119 -0
  27. package/lib/translation-manager.js.map +1 -0
  28. package/lib/translation.d.ts +44 -0
  29. package/lib/translation.js +253 -0
  30. package/lib/translation.js.map +1 -0
  31. package/lib/translation.models.d.ts +25 -0
  32. package/lib/{features/types.js → translation.models.js} +1 -1
  33. package/lib/translation.models.js.map +1 -0
  34. package/lib/utils-i18n-extract-gettext-translate-from-html.d.ts +4 -0
  35. package/lib/utils-i18n-extract-gettext-translate-from-html.js +465 -0
  36. package/lib/utils-i18n-extract-gettext-translate-from-html.js.map +1 -0
  37. package/lib/utils-i18n-extract-gettext-translate-from-html.test.d.ts +1 -0
  38. package/lib/utils-i18n-extract-gettext-translate-from-html.test.js +282 -0
  39. package/lib/utils-i18n-extract-gettext-translate-from-html.test.js.map +1 -0
  40. package/lib/utils-i18n-html.d.ts +5 -0
  41. package/lib/utils-i18n-html.js +120 -0
  42. package/lib/utils-i18n-html.js.map +1 -0
  43. package/lib/utils-i18n-html.test.d.ts +1 -0
  44. package/lib/utils-i18n-html.test.js +82 -0
  45. package/lib/utils-i18n-html.test.js.map +1 -0
  46. package/lib/utils-po-file.d.ts +8 -0
  47. package/lib/utils-po-file.js +245 -0
  48. package/lib/utils-po-file.js.map +1 -0
  49. package/lib/utils-po-file.test.d.ts +1 -0
  50. package/lib/utils-po-file.test.js +239 -0
  51. package/lib/utils-po-file.test.js.map +1 -0
  52. package/lib-esm/app/main-page/main-page.active.context.d.ts +19 -0
  53. package/lib-esm/app/main-page/main-page.active.context.js +19 -0
  54. package/lib-esm/app/main-page/main-page.active.context.js.map +1 -0
  55. package/lib-esm/app.electron.d.ts +1 -1
  56. package/lib-esm/app.electron.js +1 -1
  57. package/lib-esm/app.hosts.d.ts +54 -2
  58. package/lib-esm/app.hosts.js +64 -4
  59. package/lib-esm/app.hosts.js.map +1 -1
  60. package/lib-esm/app.js +9 -9
  61. package/lib-esm/app.js.map +1 -1
  62. package/lib-esm/lib/build-info._auto-generated_.d.ts +1 -1
  63. package/lib-esm/lib/build-info._auto-generated_.js +1 -1
  64. package/lib-esm/lib/index._auto-generated_.d.ts +6 -14
  65. package/lib-esm/lib/index._auto-generated_.js +9 -14
  66. package/lib-esm/lib/index._auto-generated_.js.map +1 -1
  67. package/lib-esm/lib/start-cli.js +6 -4
  68. package/lib-esm/lib/start-cli.js.map +1 -1
  69. package/lib-esm/lib/translation-manager.d.ts +33 -0
  70. package/lib-esm/lib/translation-manager.js +115 -0
  71. package/lib-esm/lib/translation-manager.js.map +1 -0
  72. package/lib-esm/lib/translation.d.ts +43 -0
  73. package/lib-esm/lib/translation.js +249 -0
  74. package/lib-esm/lib/translation.js.map +1 -0
  75. package/lib-esm/lib/translation.models.d.ts +25 -0
  76. package/lib-esm/lib/translation.models.js +2 -0
  77. package/lib-esm/lib/translation.models.js.map +1 -0
  78. package/lib-esm/lib/utils-i18n-extract-gettext-translate-from-html.d.ts +4 -0
  79. package/lib-esm/lib/utils-i18n-extract-gettext-translate-from-html.js +462 -0
  80. package/lib-esm/lib/utils-i18n-extract-gettext-translate-from-html.js.map +1 -0
  81. package/lib-esm/lib/utils-i18n-extract-gettext-translate-from-html.test.d.ts +1 -0
  82. package/lib-esm/lib/utils-i18n-extract-gettext-translate-from-html.test.js +280 -0
  83. package/lib-esm/lib/utils-i18n-extract-gettext-translate-from-html.test.js.map +1 -0
  84. package/lib-esm/lib/utils-i18n-html.d.ts +5 -0
  85. package/lib-esm/lib/utils-i18n-html.js +117 -0
  86. package/lib-esm/lib/utils-i18n-html.js.map +1 -0
  87. package/lib-esm/lib/utils-i18n-html.test.d.ts +1 -0
  88. package/lib-esm/lib/utils-i18n-html.test.js +80 -0
  89. package/lib-esm/lib/utils-i18n-html.test.js.map +1 -0
  90. package/lib-esm/lib/utils-po-file.d.ts +8 -0
  91. package/lib-esm/lib/utils-po-file.js +242 -0
  92. package/lib-esm/lib/utils-po-file.js.map +1 -0
  93. package/lib-esm/lib/utils-po-file.test.d.ts +1 -0
  94. package/lib-esm/lib/utils-po-file.test.js +237 -0
  95. package/lib-esm/lib/utils-po-file.test.js.map +1 -0
  96. package/lib-prod/build-info._auto-generated_.d.ts +1 -1
  97. package/lib-prod/build-info._auto-generated_.js +1 -1
  98. package/lib-prod/index._auto-generated_.d.ts +6 -14
  99. package/lib-prod/index._auto-generated_.js +9 -14
  100. package/lib-prod/index._auto-generated_.js.map +1 -1
  101. package/lib-prod/package.json +1 -1
  102. package/lib-prod/start-cli.js +6 -4
  103. package/lib-prod/start-cli.js.map +1 -1
  104. package/lib-prod/translation-manager.d.ts +33 -0
  105. package/lib-prod/translation-manager.js +115 -0
  106. package/lib-prod/translation-manager.js.map +1 -0
  107. package/lib-prod/translation.d.ts +43 -0
  108. package/lib-prod/translation.js +249 -0
  109. package/lib-prod/translation.js.map +1 -0
  110. package/lib-prod/translation.models.d.ts +25 -0
  111. package/lib-prod/translation.models.js +2 -0
  112. package/lib-prod/translation.models.js.map +1 -0
  113. package/lib-prod/utils-i18n-extract-gettext-translate-from-html.d.ts +2 -0
  114. package/lib-prod/utils-i18n-extract-gettext-translate-from-html.js +460 -0
  115. package/lib-prod/utils-i18n-extract-gettext-translate-from-html.js.map +1 -0
  116. package/lib-prod/utils-i18n-extract-gettext-translate-from-html.test.d.ts +1 -0
  117. package/lib-prod/utils-i18n-extract-gettext-translate-from-html.test.js +280 -0
  118. package/lib-prod/utils-i18n-extract-gettext-translate-from-html.test.js.map +1 -0
  119. package/lib-prod/utils-i18n-html.d.ts +3 -0
  120. package/lib-prod/utils-i18n-html.js +114 -0
  121. package/lib-prod/utils-i18n-html.js.map +1 -0
  122. package/lib-prod/utils-i18n-html.test.d.ts +1 -0
  123. package/lib-prod/utils-i18n-html.test.js +80 -0
  124. package/lib-prod/utils-i18n-html.test.js.map +1 -0
  125. package/lib-prod/utils-po-file.d.ts +6 -0
  126. package/lib-prod/utils-po-file.js +236 -0
  127. package/lib-prod/utils-po-file.js.map +1 -0
  128. package/lib-prod/utils-po-file.test.d.ts +1 -0
  129. package/lib-prod/utils-po-file.test.js +237 -0
  130. package/lib-prod/utils-po-file.test.js.map +1 -0
  131. package/lib-prod.split-namespaces.json +26 -2
  132. package/package.json +4 -2
  133. package/scss/app/main-page/main-page.container.scss +3 -0
  134. package/websql/fesm2022/i18n-websql.mjs +1441 -406
  135. package/websql/fesm2022/i18n-websql.mjs.map +1 -1
  136. package/websql/package.json +1 -1
  137. package/websql/types/i18n-websql.d.ts +146 -305
  138. package/websql-prod/fesm2022/i18n-websql-prod.mjs +1429 -405
  139. package/websql-prod/fesm2022/i18n-websql-prod.mjs.map +1 -1
  140. package/websql-prod/package.json +1 -1
  141. package/websql-prod/types/i18n-websql-prod.d.ts +140 -305
  142. package/websql-prod.split-namespaces.json +26 -2
  143. package/lib/features/index.d.ts +0 -4
  144. package/lib/features/index.js +0 -21
  145. package/lib/features/index.js.map +0 -1
  146. package/lib/features/types.d.ts +0 -4
  147. package/lib/features/types.js.map +0 -1
  148. package/lib/features/withLanguageLocalStorageSync.d.ts +0 -9
  149. package/lib/features/withLanguageLocalStorageSync.js +0 -39
  150. package/lib/features/withLanguageLocalStorageSync.js.map +0 -1
  151. package/lib/features/withNavigatorLanguage.d.ts +0 -6
  152. package/lib/features/withNavigatorLanguage.js +0 -29
  153. package/lib/features/withNavigatorLanguage.js.map +0 -1
  154. package/lib/features/withPreloadScopes.d.ts +0 -8
  155. package/lib/features/withPreloadScopes.js +0 -25
  156. package/lib/features/withPreloadScopes.js.map +0 -1
  157. package/lib/features/withServerSideLanguage.d.ts +0 -6
  158. package/lib/features/withServerSideLanguage.js +0 -29
  159. package/lib/features/withServerSideLanguage.js.map +0 -1
  160. package/lib/features/withTranslatedTitle.d.ts +0 -34
  161. package/lib/features/withTranslatedTitle.js +0 -69
  162. package/lib/features/withTranslatedTitle.js.map +0 -1
  163. package/lib/internals.d.ts +0 -2
  164. package/lib/internals.js +0 -6
  165. package/lib/internals.js.map +0 -1
  166. package/lib/transignal-config.d.ts +0 -34
  167. package/lib/transignal-config.js +0 -42
  168. package/lib/transignal-config.js.map +0 -1
  169. package/lib/transignal-param-handlers.d.ts +0 -11
  170. package/lib/transignal-param-handlers.js +0 -31
  171. package/lib/transignal-param-handlers.js.map +0 -1
  172. package/lib/transignal-service.d.ts +0 -32
  173. package/lib/transignal-service.js +0 -206
  174. package/lib/transignal-service.js.map +0 -1
  175. package/lib/transignal-testing.d.ts +0 -8
  176. package/lib/transignal-testing.js +0 -14
  177. package/lib/transignal-testing.js.map +0 -1
  178. package/lib/types.d.ts +0 -124
  179. package/lib/types.js +0 -3
  180. package/lib/types.js.map +0 -1
  181. package/lib/utility-types.d.ts +0 -29
  182. package/lib/utility-types.js +0 -3
  183. package/lib/utility-types.js.map +0 -1
  184. package/lib/utils.d.ts +0 -15
  185. package/lib/utils.js +0 -20
  186. package/lib/utils.js.map +0 -1
  187. package/lib-esm/lib/features/index.d.ts +0 -4
  188. package/lib-esm/lib/features/index.js +0 -5
  189. package/lib-esm/lib/features/index.js.map +0 -1
  190. package/lib-esm/lib/features/types.d.ts +0 -4
  191. package/lib-esm/lib/features/types.js +0 -2
  192. package/lib-esm/lib/features/types.js.map +0 -1
  193. package/lib-esm/lib/features/withLanguageLocalStorageSync.d.ts +0 -9
  194. package/lib-esm/lib/features/withLanguageLocalStorageSync.js +0 -35
  195. package/lib-esm/lib/features/withLanguageLocalStorageSync.js.map +0 -1
  196. package/lib-esm/lib/features/withNavigatorLanguage.d.ts +0 -6
  197. package/lib-esm/lib/features/withNavigatorLanguage.js +0 -25
  198. package/lib-esm/lib/features/withNavigatorLanguage.js.map +0 -1
  199. package/lib-esm/lib/features/withPreloadScopes.d.ts +0 -8
  200. package/lib-esm/lib/features/withPreloadScopes.js +0 -21
  201. package/lib-esm/lib/features/withPreloadScopes.js.map +0 -1
  202. package/lib-esm/lib/features/withServerSideLanguage.d.ts +0 -6
  203. package/lib-esm/lib/features/withServerSideLanguage.js +0 -25
  204. package/lib-esm/lib/features/withServerSideLanguage.js.map +0 -1
  205. package/lib-esm/lib/features/withTranslatedTitle.d.ts +0 -34
  206. package/lib-esm/lib/features/withTranslatedTitle.js +0 -65
  207. package/lib-esm/lib/features/withTranslatedTitle.js.map +0 -1
  208. package/lib-esm/lib/internals.d.ts +0 -2
  209. package/lib-esm/lib/internals.js +0 -3
  210. package/lib-esm/lib/internals.js.map +0 -1
  211. package/lib-esm/lib/transignal-config.d.ts +0 -34
  212. package/lib-esm/lib/transignal-config.js +0 -36
  213. package/lib-esm/lib/transignal-config.js.map +0 -1
  214. package/lib-esm/lib/transignal-param-handlers.d.ts +0 -11
  215. package/lib-esm/lib/transignal-param-handlers.js +0 -25
  216. package/lib-esm/lib/transignal-param-handlers.js.map +0 -1
  217. package/lib-esm/lib/transignal-service.d.ts +0 -32
  218. package/lib-esm/lib/transignal-service.js +0 -197
  219. package/lib-esm/lib/transignal-service.js.map +0 -1
  220. package/lib-esm/lib/transignal-testing.d.ts +0 -8
  221. package/lib-esm/lib/transignal-testing.js +0 -10
  222. package/lib-esm/lib/transignal-testing.js.map +0 -1
  223. package/lib-esm/lib/types.d.ts +0 -124
  224. package/lib-esm/lib/types.js +0 -2
  225. package/lib-esm/lib/types.js.map +0 -1
  226. package/lib-esm/lib/utility-types.d.ts +0 -29
  227. package/lib-esm/lib/utility-types.js +0 -2
  228. package/lib-esm/lib/utility-types.js.map +0 -1
  229. package/lib-esm/lib/utils.d.ts +0 -15
  230. package/lib-esm/lib/utils.js +0 -15
  231. package/lib-esm/lib/utils.js.map +0 -1
  232. package/lib-prod/features/index.d.ts +0 -4
  233. package/lib-prod/features/index.js +0 -5
  234. package/lib-prod/features/index.js.map +0 -1
  235. package/lib-prod/features/types.d.ts +0 -4
  236. package/lib-prod/features/types.js +0 -2
  237. package/lib-prod/features/types.js.map +0 -1
  238. package/lib-prod/features/withLanguageLocalStorageSync.d.ts +0 -9
  239. package/lib-prod/features/withLanguageLocalStorageSync.js +0 -35
  240. package/lib-prod/features/withLanguageLocalStorageSync.js.map +0 -1
  241. package/lib-prod/features/withNavigatorLanguage.d.ts +0 -6
  242. package/lib-prod/features/withNavigatorLanguage.js +0 -25
  243. package/lib-prod/features/withNavigatorLanguage.js.map +0 -1
  244. package/lib-prod/features/withPreloadScopes.d.ts +0 -8
  245. package/lib-prod/features/withPreloadScopes.js +0 -21
  246. package/lib-prod/features/withPreloadScopes.js.map +0 -1
  247. package/lib-prod/features/withServerSideLanguage.d.ts +0 -6
  248. package/lib-prod/features/withServerSideLanguage.js +0 -25
  249. package/lib-prod/features/withServerSideLanguage.js.map +0 -1
  250. package/lib-prod/features/withTranslatedTitle.d.ts +0 -34
  251. package/lib-prod/features/withTranslatedTitle.js +0 -65
  252. package/lib-prod/features/withTranslatedTitle.js.map +0 -1
  253. package/lib-prod/internals.d.ts +0 -2
  254. package/lib-prod/internals.js +0 -3
  255. package/lib-prod/internals.js.map +0 -1
  256. package/lib-prod/transignal-config.d.ts +0 -34
  257. package/lib-prod/transignal-config.js +0 -36
  258. package/lib-prod/transignal-config.js.map +0 -1
  259. package/lib-prod/transignal-param-handlers.d.ts +0 -11
  260. package/lib-prod/transignal-param-handlers.js +0 -25
  261. package/lib-prod/transignal-param-handlers.js.map +0 -1
  262. package/lib-prod/transignal-service.d.ts +0 -32
  263. package/lib-prod/transignal-service.js +0 -197
  264. package/lib-prod/transignal-service.js.map +0 -1
  265. package/lib-prod/transignal-testing.d.ts +0 -8
  266. package/lib-prod/transignal-testing.js +0 -10
  267. package/lib-prod/transignal-testing.js.map +0 -1
  268. package/lib-prod/types.d.ts +0 -124
  269. package/lib-prod/types.js +0 -2
  270. package/lib-prod/types.js.map +0 -1
  271. package/lib-prod/utility-types.d.ts +0 -29
  272. package/lib-prod/utility-types.js +0 -2
  273. package/lib-prod/utility-types.js.map +0 -1
  274. package/lib-prod/utils.d.ts +0 -15
  275. package/lib-prod/utils.js +0 -15
  276. package/lib-prod/utils.js.map +0 -1
@@ -1,11 +0,0 @@
1
- import { TranslateParams } from './types';
2
- export type ParamHandler = (translation: string, params?: TranslateParams) => string;
3
- /**
4
- * Param handler which allows for specification of basic params: `{name}`
5
- *
6
- * @param translation Translated text
7
- * @param params Params provided to translation function
8
- */
9
- export declare const simpleParamsHandler: ParamHandler;
10
- export declare const noParamsHandler: ParamHandler;
11
- export declare const simpleParamValueStringify: (paramValue: unknown) => any;
@@ -1,25 +0,0 @@
1
- /**
2
- * Param handler which allows for specification of basic params: `{name}`
3
- *
4
- * @param translation Translated text
5
- * @param params Params provided to translation function
6
- */
7
- export const simpleParamsHandler = (translation, params) => {
8
- if (!params)
9
- return translation;
10
- for (const [key, value] of Object.entries(params)) {
11
- translation = translation.replaceAll(`{${key}}`, simpleParamValueStringify(value));
12
- }
13
- return translation;
14
- };
15
- export const noParamsHandler = translation => translation;
16
- export const simpleParamValueStringify = (paramValue) => {
17
- if (typeof paramValue === 'string') {
18
- return paramValue;
19
- }
20
- if (paramValue == null) {
21
- return '';
22
- }
23
- return paramValue.toString();
24
- };
25
- //# sourceMappingURL=transignal-param-handlers.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"transignal-param-handlers.js","sourceRoot":"","sources":[""],"names":[],"mappings":"AAIA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAiB,CAAC,WAAW,EAAE,MAAM,EAAE,EAAE;IACvE,IAAI,CAAC,MAAM;QAAE,OAAO,WAAW,CAAC;IAChC,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QAClD,WAAW,GAAG,WAAW,CAAC,UAAU,CAAC,IAAI,GAAG,GAAG,EAAE,yBAAyB,CAAC,KAAK,CAAC,CAAC,CAAC;IACrF,CAAC;IACD,OAAO,WAAW,CAAC;AACrB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,eAAe,GAAiB,WAAW,CAAC,EAAE,CAAC,WAAW,CAAC;AAExE,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,UAAmB,EAAE,EAAE;IAC/D,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE,CAAC;QACnC,OAAO,UAAU,CAAC;IACpB,CAAC;IACD,IAAI,UAAU,IAAI,IAAI,EAAE,CAAC;QACvB,OAAO,EAAE,CAAC;IACZ,CAAC;IACD,OAAQ,UAAkB,CAAC,QAAQ,EAAE,CAAC;AACxC,CAAC,CAAC"}
@@ -1,32 +0,0 @@
1
- import { TranslateObj, TranslateParams } from './types';
2
- import { StringKeys } from './utility-types';
3
- /**
4
- * Main transignal service, used to process and cache translations
5
- * Can be injected directly or with use of transignal object created with {@link prepareTransignal} function (recommended)
6
- */
7
- export declare class TransignalService<Languages extends string, Translations extends Record<string, Record<string, any>>, Scopes extends StringKeys<Translations>> {
8
- private readonly injector;
9
- private readonly config;
10
- private readonly paramsHandler;
11
- private readonly loadingFn;
12
- private readonly errorHandler;
13
- private readonly loadingCount;
14
- private readonly scopeMap;
15
- private readonly languageMap;
16
- /**
17
- * Use to set or get active language
18
- */
19
- readonly activeLang: import("@angular/core").WritableSignal<Languages>;
20
- /**
21
- * Use to determine whether service is currently loading translation files
22
- */
23
- readonly isLoading: import("@angular/core").Signal<boolean>;
24
- t<Scope extends Scopes>(scope: Scope): TranslateObj<Translations[Scope]>;
25
- private initT;
26
- private preparePrefixFn;
27
- private preparePluralFn;
28
- private prepareSelectFn;
29
- protected replaceParams<T>(translation: T, params?: TranslateParams): T;
30
- private fetchLanguage;
31
- private resolveObjectPath;
32
- }
@@ -1,197 +0,0 @@
1
- import { computed, EnvironmentInjector, inject, Injectable, resource, runInInjectionContext, signal, untracked, } from '@angular/core';
2
- import { TREE_SHAKED_TRANSLATIONS } from './internals';
3
- import { injectTransignalConfig } from './transignal-config';
4
- import { simpleParamsHandler } from './transignal-param-handlers';
5
- /**
6
- * Main transignal service, used to process and cache translations
7
- * Can be injected directly or with use of transignal object created with {@link prepareTransignal} function (recommended)
8
- */
9
- let TransignalService = class TransignalService {
10
- injector = inject(EnvironmentInjector);
11
- config = injectTransignalConfig();
12
- paramsHandler = this.config.paramHandler ?? simpleParamsHandler;
13
- loadingFn = this.config.loadingFn ?? (() => '...');
14
- // eslint-disable-next-line no-console
15
- errorHandler = this.config.errorHandler ?? console.error; // TODO maybe add a link to error page in docs
16
- loadingCount = signal(0);
17
- scopeMap = new Map();
18
- languageMap = new Map();
19
- /**
20
- * Use to set or get active language
21
- */
22
- activeLang = signal(this.config.defaultLang);
23
- /**
24
- * Use to determine whether service is currently loading translation files
25
- */
26
- isLoading = computed(() => this.loadingCount() > 0);
27
- t(scope) {
28
- const existing = this.scopeMap.get(scope);
29
- if (existing) {
30
- return existing;
31
- }
32
- const scopeObj = this.initT(scope);
33
- this.scopeMap.set(scope, scopeObj);
34
- return scopeObj;
35
- }
36
- initT(scope) {
37
- const cache = new Map();
38
- const t = ((key, params) => {
39
- const lang = this.activeLang();
40
- const baseKey = `${lang}/${key}`;
41
- const memoKey = params ? `${baseKey}_${JSON.stringify(params)}` : baseKey;
42
- const alreadyComputed = cache.get(memoKey);
43
- if (alreadyComputed) {
44
- return alreadyComputed;
45
- }
46
- const { isLoading, error, value } = this.fetchLanguage(scope, lang);
47
- if (isLoading()) {
48
- return this.loadingFn?.(key);
49
- }
50
- if (error() || !value()) {
51
- this.errorHandler('missing_file', error());
52
- return '';
53
- }
54
- const result = this.replaceParams(this.resolveObjectPath(value(), key), params);
55
- cache.set(memoKey, result);
56
- return result;
57
- }); // needed as other props are assigned below
58
- t.arr = t;
59
- t.obj = t;
60
- t.prefix = this.preparePrefixFn(t, 1);
61
- t.plural = this.preparePluralFn(t);
62
- t.select = this.prepareSelectFn(t);
63
- return t;
64
- }
65
- preparePrefixFn(t, depth) {
66
- return (prefix) => {
67
- const prefixedT = (key, params) => t(`${prefix}.${key}`, params);
68
- prefixedT.arr = prefixedT;
69
- prefixedT.obj = prefixedT;
70
- prefixedT.plural = this.preparePluralFn(prefixedT);
71
- prefixedT.select = this.prepareSelectFn(prefixedT);
72
- prefixedT.prefix =
73
- this.config.maxPrefixDepth || 3 >= depth
74
- ? this.preparePrefixFn(prefixedT, depth + 1)
75
- : () => {
76
- this.errorHandler('prefix_too_deep');
77
- const t = () => '';
78
- t.arr = () => [];
79
- t.obj = () => ({});
80
- t.plural = () => '';
81
- return t;
82
- };
83
- return prefixedT;
84
- };
85
- }
86
- preparePluralFn(t) {
87
- return (key, count, params) => {
88
- const plurals = t(key, { count, ...params });
89
- if (typeof plurals === 'string') {
90
- if (plurals === this.loadingFn(key)) {
91
- return plurals;
92
- }
93
- this.errorHandler('invalid_plural', key, plurals);
94
- return plurals;
95
- }
96
- if (plurals[count]) {
97
- return plurals[count];
98
- }
99
- const valueLastDigit = +count.toFixed(0).at(-1);
100
- if (plurals.one && valueLastDigit === 1) {
101
- return plurals.one;
102
- }
103
- if (plurals.many && valueLastDigit >= 5) {
104
- return plurals.many;
105
- }
106
- if (plurals.few && valueLastDigit > 1 && valueLastDigit < 5) {
107
- return plurals.few;
108
- }
109
- if (plurals.other) {
110
- return plurals.other;
111
- }
112
- this.errorHandler('missing_plural', key, plurals, count);
113
- return '';
114
- };
115
- }
116
- prepareSelectFn(t) {
117
- return (key, value, params) => {
118
- const selects = t(key, { value, ...params });
119
- if (typeof selects === 'string') {
120
- if (selects === this.loadingFn(key)) {
121
- return selects;
122
- }
123
- this.errorHandler('invalid_select', key, selects);
124
- return selects;
125
- }
126
- if (value !== null) {
127
- if (selects[value]) {
128
- return selects[value];
129
- }
130
- }
131
- else if (selects['null']) {
132
- return selects['null'];
133
- }
134
- this.errorHandler('missing_select', key, selects, value);
135
- return '';
136
- };
137
- }
138
- replaceParams(translation, params) {
139
- if (!translation)
140
- return translation;
141
- if (typeof translation === 'string') {
142
- return this.paramsHandler(translation, params);
143
- }
144
- if (Array.isArray(translation)) {
145
- return translation.map(val => this.replaceParams(val, params));
146
- }
147
- if (typeof translation === 'object') {
148
- return Object.entries(translation).reduce((prev, [objKey, objVal]) => {
149
- prev[objKey] = this.replaceParams(objVal, params);
150
- return prev;
151
- }, {});
152
- }
153
- return translation;
154
- }
155
- fetchLanguage(scope, lang) {
156
- const cacheKey = `${scope}/${lang}`;
157
- const existing = this.languageMap.get(cacheKey);
158
- if (existing)
159
- return existing;
160
- const { translations, loader } = this.config;
161
- const translation = runInInjectionContext(this.injector, () => translations === TREE_SHAKED_TRANSLATIONS
162
- ? untracked(() => resource({
163
- loader: async () => {
164
- this.loadingCount.update(count => ++count);
165
- const file = await runInInjectionContext(this.injector, () => loader(scope, lang));
166
- this.loadingCount.update(count => --count);
167
- return file;
168
- },
169
- }))
170
- : {
171
- value: signal(translations[scope]),
172
- isLoading: signal(false),
173
- error: signal(undefined),
174
- });
175
- this.languageMap.set(cacheKey, translation);
176
- return translation;
177
- }
178
- resolveObjectPath(obj, path) {
179
- const keys = path.split('.');
180
- let current = obj;
181
- for (const key of keys) {
182
- if (current && typeof current === 'object') {
183
- current = current[key];
184
- }
185
- else {
186
- this.errorHandler('missing_key', { obj, path });
187
- return undefined;
188
- }
189
- }
190
- return current;
191
- }
192
- };
193
- TransignalService = __decorate([
194
- Injectable()
195
- ], TransignalService);
196
- export { TransignalService };
197
- //# sourceMappingURL=transignal-service.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"transignal-service.js","sourceRoot":"","sources":[""],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,mBAAmB,EACnB,MAAM,EACN,UAAU,EACV,QAAQ,EACR,qBAAqB,EACrB,MAAM,EACN,SAAS,GACV,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAWlE;;;GAGG;AAEI,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAKX,QAAQ,GAAG,MAAM,CAAC,mBAAmB,CAAC,CAAC;IACvC,MAAM,GAAG,sBAAsB,EAA2B,CAAC;IAC3D,aAAa,GAAG,IAAI,CAAC,MAAM,CAAC,YAAY,IAAI,mBAAmB,CAAC;IAChE,SAAS,GAAG,IAAI,CAAC,MAAM,CAAC,SAAS,IAAI,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC;IACpE,sCAAsC;IACrB,YAAY,GAAG,IAAI,CAAC,MAAM,CAAC,YAAY,IAAI,OAAO,CAAC,KAAK,CAAC,CAAC,8CAA8C;IACxG,YAAY,GAAG,MAAM,CAAS,CAAC,CAAC,C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;QAC7B,IAAI,OAAO,GAAY,GAAG,CAAC;QAC3B,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;YACvB,IAAI,OAAO,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;gBAC3C,OAAO,GAAI,OAAmC,CAAC,GAAG,CAAC,CAAC;YACtD,CAAC;iBAAM,CAAC;gBACN,IAAI,CAAC,YAAY,CAAC,aAAa,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC;gBAChD,OAAO,SAAS,CAAC;YACnB,CAAC;QACH,CAAC;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;CACF,CAAA;AA9MY,iBAAiB;IAD7B,UAAU,EAAE;GACA,iBAAiB,CA8M7B"}
@@ -1,8 +0,0 @@
1
- import { prepareTransignal } from './transignal-config';
2
- /**
3
- * Provides unit-test version of transignal that loads translation instantly without loading
4
- *
5
- * @param transignal existing transignal instance
6
- * @param translations real translations in a selected language
7
- */
8
- export declare const provideTransignalTesting: <Languages extends string, Translations extends Record<string, Record<string, unknown>>>(transignal: ReturnType<typeof prepareTransignal<Languages, Translations>>, translations: Translations) => import("@angular/core").EnvironmentProviders;
@@ -1,10 +0,0 @@
1
- import { INTERNAL_TRANSIGNAL_CONFIG } from './internals';
2
- import { prepareTransignal } from './transignal-config';
3
- /**
4
- * Provides unit-test version of transignal that loads translation instantly without loading
5
- *
6
- * @param transignal existing transignal instance
7
- * @param translations real translations in a selected language
8
- */
9
- export const provideTransignalTesting = (transignal, translations) => prepareTransignal({ ...transignal[INTERNAL_TRANSIGNAL_CONFIG].config, translations }, ...transignal[INTERNAL_TRANSIGNAL_CONFIG].features).provide();
10
- //# sourceMappingURL=transignal-testing.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"transignal-testing.js","sourceRoot":"","sources":[""],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAItC,UAAyE,EACzE,YAA0B,EAC1B,EAAE,CACF,iBAAiB,CACf,EAAE,GAAG,UAAU,CAAC,0BAA0B,CAAC,CAAC,MAAM,EAAE,YAAY,EAAE,EAClE,GAAG,UAAU,CAAC,0BAA0B,CAAC,CAAC,QAAQ,CACnD,CAAC,OAAO,EAAE,CAAC"}
@@ -1,124 +0,0 @@
1
- import { ParamHandler } from './transignal-param-handlers';
2
- import { ArrayPaths, GetNestedType, ObjectPaths, PluralPaths, SelectPaths, StringKeys, StringPaths } from './utility-types';
3
- export type TransignalError =
4
- /** Error when key is not found in translations */
5
- 'missing_key'
6
- /** Error when translation file for scope and lang has not been found */
7
- | 'missing_file'
8
- /** Error plural for a value is not defined for a language */
9
- | 'missing_plural'
10
- /** Error when plural used on a non-plural translation */
11
- | 'invalid_plural'
12
- /** Error select for a value is not defined for a language */
13
- | 'missing_select'
14
- /** Error when select used on a non-select translation */
15
- | 'invalid_select'
16
- /** Error when prefix chain is called more then {@link TransignalConfig.maxPrefixDepth} */
17
- | 'prefix_too_deep';
18
- export type TranslateParams = Record<string, unknown>;
19
- export type Marked<K, T> = K & {
20
- __marker: T;
21
- };
22
- export type BasePluralTranslation = Partial<Record<number | 'one' | 'few' | 'many' | 'other', string>>;
23
- export type PluralTranslation = Marked<BasePluralTranslation, 'plural'>;
24
- export type BaseSelectTranslation = Partial<Record<string | number | 'null', string>>;
25
- export type MarkedAsSelect<T extends BaseSelectTranslation> = Marked<T, 'select'>;
26
- export type SelectTranslation = MarkedAsSelect<BaseSelectTranslation>;
27
- export type TranslateFn<Keys extends string, Result> = (key: Keys, params?: TranslateParams) => Result;
28
- export type TranslateObj<Context extends Record<string, any>> = TranslateFn<StringPaths<Context>, string> & {
29
- /**
30
- * Returns translating function that returns an array of translations
31
- * @param key path of translation
32
- * @param params parameters of translation in syntax defined by {@link TransignalConfig.paramHandler}
33
- */
34
- arr: <ArrKey extends ArrayPaths<Context>>(key: ArrKey, params?: TranslateParams) => GetNestedType<Context, ArrKey>;
35
- /**
36
- * Returns translating function that returns an object of translations
37
- * @param key path of translation
38
- * @param params parameters of translation in syntax defined by {@link TransignalConfig.paramHandler}
39
- */
40
- obj: <ObjKey extends ObjectPaths<Context>>(key: ObjKey, params?: TranslateParams) => GetNestedType<Context, ObjKey>;
41
- /**
42
- * Returns translating function that returns a string translation depending on a correct plural form
43
- * @param key path of translation
44
- * @param count count to determine correct plural form
45
- * @param params parameters of translation in syntax defined by {@link TransignalConfig.paramHandler}
46
- */
47
- plural: <ObjKey extends PluralPaths<Context>>(key: ObjKey, count: number, params?: TranslateParams) => string;
48
- /**
49
- * Returns translating function that returns a string translation depending on a selected value
50
- * @param key path of translation
51
- * @param value value to determine selected translation
52
- * @param params parameters of translation in syntax defined by {@link TransignalConfig.paramHandler}
53
- */
54
- select: <ObjKey extends SelectPaths<Context>>(key: ObjKey, value: keyof SelectTranslation | null, params?: TranslateParams) => string;
55
- /**
56
- * Returns translating function that is encapsulated in a selected prefix
57
- * @param prefix path of new root translation
58
- */
59
- prefix: <T extends ObjectPaths<Context>>(prefix: T) => TranslateObj<GetNestedType<Context, T>>;
60
- };
61
- export type TranslationFile = Record<string, unknown>;
62
- export type TransignalConfig<Languages extends string, Translations extends Record<string, Record<string, unknown>>> = {
63
- /**
64
- * Default language code
65
- */
66
- defaultLang: NoInfer<Languages>;
67
- /**
68
- * An array of available languages that your application supports.
69
- * These should be unique string identifiers for each language (e.g., ['en', 'fr', 'es']).
70
- */
71
- availableLangs: Languages[];
72
- /**
73
- * Defines the type of translations.
74
- * Please use helper function {@link treeShakedTranslations()}
75
- * @example
76
- * ```typescript
77
- * import type translations from './i18n/translations';
78
- * ...
79
- * translations: treeShakedTranslations<typeof translations>(),
80
- * ```
81
- */
82
- translations: Translations;
83
- /**
84
- * A function responsible for dynamically loading translation files.
85
- * This function is called when a specific translation scope and language is requested
86
- * It runs in TransignalService injection context so {@link inject()} can be used to e.g. use HttpClient
87
- *
88
- * @param scope The string key representing the translation scope (e.g., 'common', 'auth').
89
- * @param lang The language identifier for which to load translations (e.g., 'en', 'fr').
90
- * @returns A Promise that resolves to a `TranslationFile` object, which is
91
- * a record of string keys to unknown values representing the translations for
92
- * the given scope and language.
93
- */
94
- loader: (scope: StringKeys<Translations>, lang: Languages) => Promise<TranslationFile>;
95
- /**
96
- * An optional function that defines how a loading message should be displayed
97
- * while translations are being loaded.
98
- *
99
- * @param key The translation key that is currently being loaded.
100
- * @returns A string representing the loading message.
101
- */
102
- loadingFn?: (key: string) => string;
103
- /**
104
- * An optional function that defines how params should be processed
105
- * Defaults to {@link simpleParamsHandler}
106
- * Use {@link noParamsHandler} if you don't want to use params
107
- * If you want to handle message format then you can install TODO
108
- */
109
- paramHandler?: ParamHandler;
110
- /**
111
- * An optional error handler function that will be called when a `TransignalError` occurs.
112
- * This allows you to implement custom error reporting or logging.
113
- *
114
- * @param errorCode Code of an error {@link TransignalError} code that occurred.
115
- * @param args Any additional arguments relevant to the error.
116
- */
117
- errorHandler?: (errorCode: TransignalError, ...args: unknown[]) => void;
118
- /**
119
- * Defines max depth of prefix functions in {@link TranslateObj}
120
- * Defaults to 3, this means that if prefix function is used more than 3 time on the same t then it will fail
121
- * Required for performance reasons
122
- */
123
- maxPrefixDepth?: number;
124
- };
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":[""],"names":[],"mappings":""}
@@ -1,29 +0,0 @@
1
- import { Signal } from '@angular/core';
2
- import { PluralTranslation, SelectTranslation } from './types';
3
- export type GetNestedType<T, P extends string> = P extends `${infer Key}.${infer Rest}` ? Key extends keyof T ? GetNestedType<T[Key], Rest> : never : P extends keyof T ? NonNullable<T[P]> : never;
4
- type DotPrefix<T extends string> = T extends '' ? '' : `.${T}`;
5
- export type Paths<T> = T extends object ? T extends Array<infer U> ? `${number}${'' | DotPrefix<Paths<U>>}` : {
6
- [K in keyof T]-?: K extends string | number ? `${K}${'' | DotPrefix<Paths<T[K]>>}` : never;
7
- }[keyof T] : '';
8
- export type ArrayPaths<T> = {
9
- [P in Paths<T>]: GetNestedType<T, P> extends Array<unknown> ? P : never;
10
- }[Paths<T>];
11
- export type ObjectPaths<T> = {
12
- [P in Paths<T>]: GetNestedType<T, P> extends Record<any, unknown> ? P : never;
13
- }[Paths<T>];
14
- export type PluralPaths<T> = {
15
- [P in Paths<T>]: GetNestedType<T, P> extends PluralTranslation ? P : never;
16
- }[Paths<T>];
17
- export type SelectPaths<T> = {
18
- [P in Paths<T>]: GetNestedType<T, P> extends SelectTranslation ? P : never;
19
- }[Paths<T>];
20
- export type StringPaths<T> = {
21
- [P in Paths<T>]: GetNestedType<T, P> extends string ? P : never;
22
- }[Paths<T>];
23
- export type StringKeys<T> = Extract<keyof T, string>;
24
- export type ResourceRefLike<T> = {
25
- value: Signal<T | undefined>;
26
- isLoading: Signal<boolean>;
27
- error: Signal<Error | undefined>;
28
- };
29
- export {};
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=utility-types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utility-types.js","sourceRoot":"","sources":[""],"names":[],"mappings":""}
@@ -1,15 +0,0 @@
1
- import { BasePluralTranslation, BaseSelectTranslation, MarkedAsSelect, PluralTranslation } from './types';
2
- /**
3
- * Utility to create a plural translation that can differ between languages and includes variants of translations for different plurals
4
- * Can be used with {@link TranslateObj.plural}
5
- * Translations may use automatic param: `{count}`
6
- * @param translation plural translation object
7
- */
8
- export declare const plural: (translation: BasePluralTranslation) => PluralTranslation;
9
- /**
10
- * Utility to create a select translation
11
- * Can be used with {@link TranslateObj.select}
12
- * Translations may use automatic param: `{value}`
13
- * @param translation select translation object
14
- */
15
- export declare const select: <T extends BaseSelectTranslation>(translation: T) => MarkedAsSelect<T>;
@@ -1,15 +0,0 @@
1
- /**
2
- * Utility to create a plural translation that can differ between languages and includes variants of translations for different plurals
3
- * Can be used with {@link TranslateObj.plural}
4
- * Translations may use automatic param: `{count}`
5
- * @param translation plural translation object
6
- */
7
- export const plural = (translation) => translation;
8
- /**
9
- * Utility to create a select translation
10
- * Can be used with {@link TranslateObj.select}
11
- * Translations may use automatic param: `{value}`
12
- * @param translation select translation object
13
- */
14
- export const select = (translation) => translation;
15
- //# sourceMappingURL=utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":[""],"names":[],"mappings":"AAOA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,WAAkC,EAAqB,EAAE,CAC9E,WAAgC,CAAC;AAEnC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,CAAkC,WAAc,EAAE,EAAE,CACxE,WAAgC,CAAC"}
@@ -1,4 +0,0 @@
1
- export * from './withPreloadScopes';
2
- export * from './withLanguageLocalStorageSync';
3
- export * from './withServerSideLanguage';
4
- export * from './withNavigatorLanguage';
@@ -1,5 +0,0 @@
1
- export * from './withPreloadScopes';
2
- export * from './withLanguageLocalStorageSync';
3
- export * from './withServerSideLanguage';
4
- export * from './withNavigatorLanguage';
5
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":[""],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC"}
@@ -1,4 +0,0 @@
1
- import { EnvironmentProviders } from '@angular/core';
2
- export type TransignalFeature<Languages extends string, Translations extends Record<string, Record<string, unknown>>> = {
3
- providers: EnvironmentProviders[];
4
- };
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":[""],"names":[],"mappings":""}
@@ -1,9 +0,0 @@
1
- import { TransignalFeature } from './types';
2
- /**
3
- * Saves user selected language in selected storage e.g. localStorage
4
- * Works only in browser environment
5
- *
6
- * @param key Key under which it should save the language in storage
7
- * @param storage Storage to be used e.g. localStorage or sessionStorage
8
- */
9
- export declare const withLanguageLocalStorageSync: <Languages extends string, Translations extends Record<string, Record<string, unknown>>>(key?: string, storage?: "localStorage" | "sessionStorage") => TransignalFeature<Languages, Translations>;
@@ -1,35 +0,0 @@
1
- import { isPlatformBrowser } from '@angular/common';
2
- import { effect, inject, PLATFORM_ID, provideAppInitializer } from '@angular/core';
3
- import { injectTransignalConfig } from '../transignal-config';
4
- import { TransignalService } from '../transignal-service';
5
- /**
6
- * Saves user selected language in selected storage e.g. localStorage
7
- * Works only in browser environment
8
- *
9
- * @param key Key under which it should save the language in storage
10
- * @param storage Storage to be used e.g. localStorage or sessionStorage
11
- */
12
- export const withLanguageLocalStorageSync = (key = 'LANG', storage = 'localStorage') => {
13
- return {
14
- providers: [
15
- provideAppInitializer(() => {
16
- if (isPlatformBrowser(inject(PLATFORM_ID))) {
17
- const transignalService = inject(TransignalService);
18
- const store = window[storage];
19
- const savedLanguage = store.getItem(key);
20
- if (savedLanguage) {
21
- const { availableLangs } = injectTransignalConfig();
22
- if (availableLangs.includes(savedLanguage)) {
23
- transignalService.activeLang.set(savedLanguage);
24
- }
25
- }
26
- effect(() => {
27
- const updatedLang = transignalService.activeLang();
28
- store.setItem(key, updatedLang);
29
- });
30
- }
31
- }),
32
- ],
33
- };
34
- };
35
- //# sourceMappingURL=withLanguageLocalStorageSync.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"withLanguageLocalStorageSync.js","sourceRoot":"","sources":[""],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAGnF,OAAO,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAE1D;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG,CAI1C,MAAc,MAAM,EACpB,UAA6C,cAAc,EACf,EAAE;IAC9C,OAAO;QACL,SAAS,EAAE;YACT,qBAAqB,CAAC,GAAG,EAAE;gBACzB,IAAI,iBAAiB,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC;oBAC3C,MAAM,iBAAiB,GAAG,MAAM,CAAC,iBAAiB,CAAC,CAAC;oBACpD,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;oBAE9B,MAAM,aAAa,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;oBACzC,IAAI,aAAa,EAAE,CAAC;wBAClB,MAAM,EAAE,cAAc,EAAE,GAAG,sBAAsB,EAAE,CAAC;wBACpD,IAAI,cAAc,CAAC,QAAQ,CAAC,aAAa,CAAC,EAAE,CAAC;4BAC3C,iBAAiB,CAAC,UAAU,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;wBAClD,CAAC;oBACH,CAAC;oBACD,MAAM,CAAC,GAAG,EAAE;wBACV,MAAM,WAAW,GAAG,iBAAiB,CAAC,UAAU,EAAE,CAAC;wBACnD,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC;oBAClC,CAAC,CAAC,CAAC;gBACL,CAAC;YACH,CAAC,CAAC;SACH;KACF,CAAC;AACJ,CAAC,CAAC"}
@@ -1,6 +0,0 @@
1
- import { TransignalFeature } from './types';
2
- /**
3
- * Sets active language depending on `navigator.language`, which represents user defined browser settings
4
- * Works only in browser environment
5
- */
6
- export declare const withNavigatorLanguage: <Languages extends string, Translations extends Record<string, Record<string, unknown>>>() => TransignalFeature<Languages, Translations>;
@@ -1,25 +0,0 @@
1
- import { isPlatformBrowser } from '@angular/common';
2
- import { inject, PLATFORM_ID, provideAppInitializer } from '@angular/core';
3
- import { injectTransignalConfig } from '../transignal-config';
4
- import { TransignalService } from '../transignal-service';
5
- /**
6
- * Sets active language depending on `navigator.language`, which represents user defined browser settings
7
- * Works only in browser environment
8
- */
9
- export const withNavigatorLanguage = () => {
10
- return {
11
- providers: [
12
- provideAppInitializer(() => {
13
- if (isPlatformBrowser(inject(PLATFORM_ID))) {
14
- const transignalService = inject(TransignalService);
15
- const { availableLangs } = injectTransignalConfig();
16
- const preferredLanguage = navigator.languages.map(language => language.split('-')[0].toLowerCase()).find(language => availableLangs.includes(language));
17
- if (preferredLanguage) {
18
- transignalService.activeLang.set(preferredLanguage);
19
- }
20
- }
21
- }),
22
- ],
23
- };
24
- };
25
- //# sourceMappingURL=withNavigatorLanguage.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"withNavigatorLanguage.js","sourceRoot":"","sources":[""],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAG3E,OAAO,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAE1D;;;GAGG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,GAGW,EAAE;IAChD,OAAO;QACL,SAAS,EAAE;YACT,qBAAqB,CAAC,GAAG,EAAE;gBACzB,IAAI,iBAAiB,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC;oBAC3C,MAAM,iBAAiB,GAAG,MAAM,CAAC,iBAAiB,CAAC,CAAC;oBACpD,MAAM,EAAE,cAAc,EAAE,GAAG,sBAAsB,EAAE,CAAC;oBACpD,MAAM,iBAAiB,GACrB,SAAS,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CACzE,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,cAAc,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC;oBACtD,IAAI,iBAAiB,EAAE,CAAC;wBACtB,iBAAiB,CAAC,UAAU,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;oBACtD,CAAC;gBACH,CAAC;YACH,CAAC,CAAC;SACH;KACF,CAAC;AACJ,CAAC,CAAC"}