@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,14 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.provideTransignalTesting = void 0;
4
- const internals_1 = require("./internals");
5
- const transignal_config_1 = require("./transignal-config");
6
- /**
7
- * Provides unit-test version of transignal that loads translation instantly without loading
8
- *
9
- * @param transignal existing transignal instance
10
- * @param translations real translations in a selected language
11
- */
12
- const provideTransignalTesting = (transignal, translations) => (0, transignal_config_1.prepareTransignal)({ ...transignal[internals_1.INTERNAL_TRANSIGNAL_CONFIG].config, translations }, ...transignal[internals_1.INTERNAL_TRANSIGNAL_CONFIG].features).provide();
13
- exports.provideTransignalTesting = provideTransignalTesting;
14
- //# sourceMappingURL=transignal-testing.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"transignal-testing.js","sourceRoot":"","sources":[""],"names":[],"mappings":";;;AAAA,2CAAyD;AACzD,2DAAwD;AAExD;;;;;GAKG;AACI,MAAM,wBAAwB,GAAG,CAItC,UAAyE,EACzE,YAA0B,EAC1B,EAAE,CACF,IAAA,qCAAiB,EACf,EAAE,GAAG,UAAU,CAAC,sCAA0B,CAAC,CAAC,MAAM,EAAE,YAAY,EAAE,EAClE,GAAG,UAAU,CAAC,sCAA0B,CAAC,CAAC,QAAQ,CACnD,CAAC,OAAO,EAAE,CAAC;AAVD,QAAA,wBAAwB,4BAUvB"}
package/lib/types.d.ts DELETED
@@ -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
- };
package/lib/types.js DELETED
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=types.js.map
package/lib/types.js.map DELETED
@@ -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,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=utility-types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utility-types.js","sourceRoot":"","sources":[""],"names":[],"mappings":""}
package/lib/utils.d.ts DELETED
@@ -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>;
package/lib/utils.js DELETED
@@ -1,20 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.select = exports.plural = void 0;
4
- /**
5
- * Utility to create a plural translation that can differ between languages and includes variants of translations for different plurals
6
- * Can be used with {@link TranslateObj.plural}
7
- * Translations may use automatic param: `{count}`
8
- * @param translation plural translation object
9
- */
10
- const plural = (translation) => translation;
11
- exports.plural = plural;
12
- /**
13
- * Utility to create a select translation
14
- * Can be used with {@link TranslateObj.select}
15
- * Translations may use automatic param: `{value}`
16
- * @param translation select translation object
17
- */
18
- const select = (translation) => translation;
19
- exports.select = select;
20
- //# sourceMappingURL=utils.js.map
package/lib/utils.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":[""],"names":[],"mappings":";;;AAOA;;;;;GAKG;AACI,MAAM,MAAM,GAAG,CAAC,WAAkC,EAAqB,EAAE,CAC9E,WAAgC,CAAC;AADtB,QAAA,MAAM,UACgB;AAEnC;;;;;GAKG;AACI,MAAM,MAAM,GAAG,CAAkC,WAAc,EAAE,EAAE,CACxE,WAAgC,CAAC;AADtB,QAAA,MAAM,UACgB"}
@@ -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"}
@@ -1,8 +0,0 @@
1
- import { TransignalFeature } from './types';
2
- import { StringKeys } from '../utility-types';
3
- /**
4
- * Preloads selected scopes in default language
5
- * Use after language init by {@link withServerSideLanguage} or {@link withNavigatorLanguage}
6
- * @param scopes Scopes which should be preloaded
7
- */
8
- export declare const withPreloadScopes: <Languages extends string, Translations extends Record<string, Record<string, unknown>>>(scopes: StringKeys<Translations>[]) => TransignalFeature<Languages, Translations>;
@@ -1,21 +0,0 @@
1
- import { effect, inject, provideAppInitializer } from '@angular/core';
2
- import { TransignalService } from '../transignal-service';
3
- /**
4
- * Preloads selected scopes in default language
5
- * Use after language init by {@link withServerSideLanguage} or {@link withNavigatorLanguage}
6
- * @param scopes Scopes which should be preloaded
7
- */
8
- export const withPreloadScopes = (scopes) => {
9
- return {
10
- providers: [
11
- provideAppInitializer(() => {
12
- const transignalService = inject(TransignalService);
13
- effect(() => {
14
- const _activeLang = transignalService.activeLang();
15
- scopes.forEach(scope => transignalService.t(scope)(''));
16
- });
17
- }),
18
- ],
19
- };
20
- };
21
- //# sourceMappingURL=withPreloadScopes.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"withPreloadScopes.js","sourceRoot":"","sources":[""],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAGtE,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAG1D;;;;GAIG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAI/B,MAAkC,EACU,EAAE;IAC9C,OAAO;QACL,SAAS,EAAE;YACT,qBAAqB,CAAC,GAAG,EAAE;gBACzB,MAAM,iBAAiB,GAAG,MAAM,CAAC,iBAAiB,CAAC,CAAC;gBACpD,MAAM,CAAC,GAAG,EAAE;oBACV,MAAM,WAAW,GAAG,iBAAiB,CAAC,UAAU,EAAE,CAAC;oBACnD,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,iBAAiB,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;gBAC1D,CAAC,CAAC,CAAC;YACL,CAAC,CAAC;SACH;KACF,CAAC;AACJ,CAAC,CAAC"}
@@ -1,6 +0,0 @@
1
- import { TransignalFeature } from './types';
2
- /**
3
- * Sets active language depending on `document.lang` attribute which should be set by the server.ts depending on `Accept-language` header
4
- * Works only in SSR environment
5
- */
6
- export declare const withServerSideLanguage: <Languages extends string, Translations extends Record<string, Record<string, unknown>>>() => TransignalFeature<Languages, Translations>;
@@ -1,25 +0,0 @@
1
- import { isPlatformServer } from '@angular/common';
2
- import { DOCUMENT, 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 `document.lang` attribute which should be set by the server.ts depending on `Accept-language` header
7
- * Works only in SSR environment
8
- */
9
- export const withServerSideLanguage = () => {
10
- return {
11
- providers: [
12
- provideAppInitializer(() => {
13
- if (isPlatformServer(inject(PLATFORM_ID))) {
14
- const transignalService = inject(TransignalService);
15
- const { documentElement } = inject(DOCUMENT);
16
- const { availableLangs } = injectTransignalConfig();
17
- if (availableLangs.includes(documentElement.lang)) {
18
- transignalService.activeLang.set(documentElement.lang);
19
- }
20
- }
21
- }),
22
- ],
23
- };
24
- };
25
- //# sourceMappingURL=withServerSideLanguage.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"withServerSideLanguage.js","sourceRoot":"","sources":[""],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAGrF,OAAO,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAE1D;;;GAGG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,GAGU,EAAE;IAChD,OAAO;QACL,SAAS,EAAE;YACT,qBAAqB,CAAC,GAAG,EAAE;gBACzB,IAAI,gBAAgB,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC;oBAC1C,MAAM,iBAAiB,GAAG,MAAM,CAAC,iBAAiB,CAAC,CAAC;oBACpD,MAAM,EAAE,eAAe,EAAE,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;oBAC7C,MAAM,EAAE,cAAc,EAAE,GAAG,sBAAsB,EAAE,CAAC;oBACpD,IAAI,cAAc,CAAC,QAAQ,CAAC,eAAe,CAAC,IAAI,CAAC,EAAE,CAAC;wBAClD,iBAAiB,CAAC,UAAU,CAAC,GAAG,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;oBACzD,CAAC;gBACH,CAAC;YACH,CAAC,CAAC;SACH;KACF,CAAC;AACJ,CAAC,CAAC"}
@@ -1,34 +0,0 @@
1
- import { TransignalFeature } from './types';
2
- import { StringKeys } from '../utility-types';
3
- /**
4
- * Enables translation of title param in route definition with use of prepared {@link TitleStrategy}
5
- * Automatically translates `title` param form route definition, sets website title and updates on language changes
6
- * Also it is possible to use parameters from `navigation.extras.state`
7
- *
8
- * @example
9
- * ```typescript
10
- * // src/app/app.routes.ts
11
- * export const routes = [
12
- * { path: 'base', title: 'base', children: [
13
- * { path: 'child', title: 'child' },
14
- * ],
15
- * { path: 'aux', outlet: 'popup', title: 'popupTitle' }
16
- * ];
17
- *
18
- * // src/app/transignal.ts
19
- * export const transignal = prepareTransignal(<config>, withTranslatedTitle('global'));
20
- *
21
- * // src/app/i18n/global/en.ts
22
- * export default {
23
- * title: {
24
- * base: 'Base title',
25
- * child: 'Child title'
26
- * popupTitle: 'Popup title'
27
- * }
28
- * };
29
- * ```
30
- *
31
- * @param scope scope under which there are title translations
32
- * @param translationKey translation key under which there are translations, `title` by default
33
- */
34
- export declare const withTranslatedTitle: <Languages extends string, Translations extends Record<string, Record<string, unknown>>>(scope: StringKeys<Translations>, translationKey?: string) => TransignalFeature<Languages, Translations>;
@@ -1,65 +0,0 @@
1
- import { computed, effect, EnvironmentInjector, inject, makeEnvironmentProviders, runInInjectionContext, } from '@angular/core';
2
- import { Title } from '@angular/platform-browser';
3
- import { Router, TitleStrategy } from '@angular/router';
4
- import { TransignalService } from '../transignal-service';
5
- class TransignalTitleStrategy extends TitleStrategy {
6
- t;
7
- title = inject(Title);
8
- injector = inject(EnvironmentInjector);
9
- effectRef;
10
- constructor(t) {
11
- super();
12
- this.t = t;
13
- }
14
- updateTitle(routerState) {
15
- this.effectRef?.destroy();
16
- const router = this.injector.get(Router);
17
- const title = this.buildTitle(routerState) || 'default';
18
- const translation = computed(() => this.t(title, router.getCurrentNavigation()?.extras.state));
19
- this.effectRef = runInInjectionContext(this.injector, () => effect(() => this.title.setTitle(translation()), { manualCleanup: true }));
20
- }
21
- }
22
- /**
23
- * Enables translation of title param in route definition with use of prepared {@link TitleStrategy}
24
- * Automatically translates `title` param form route definition, sets website title and updates on language changes
25
- * Also it is possible to use parameters from `navigation.extras.state`
26
- *
27
- * @example
28
- * ```typescript
29
- * // src/app/app.routes.ts
30
- * export const routes = [
31
- * { path: 'base', title: 'base', children: [
32
- * { path: 'child', title: 'child' },
33
- * ],
34
- * { path: 'aux', outlet: 'popup', title: 'popupTitle' }
35
- * ];
36
- *
37
- * // src/app/transignal.ts
38
- * export const transignal = prepareTransignal(<config>, withTranslatedTitle('global'));
39
- *
40
- * // src/app/i18n/global/en.ts
41
- * export default {
42
- * title: {
43
- * base: 'Base title',
44
- * child: 'Child title'
45
- * popupTitle: 'Popup title'
46
- * }
47
- * };
48
- * ```
49
- *
50
- * @param scope scope under which there are title translations
51
- * @param translationKey translation key under which there are translations, `title` by default
52
- */
53
- export const withTranslatedTitle = (scope, translationKey = 'title') => {
54
- return {
55
- providers: [
56
- makeEnvironmentProviders([
57
- {
58
- provide: TitleStrategy,
59
- useFactory: (service = inject(TransignalService)) => new TransignalTitleStrategy(service.t(scope).prefix(translationKey)),
60
- },
61
- ]),
62
- ],
63
- };
64
- };
65
- //# sourceMappingURL=withTranslatedTitle.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"withTranslatedTitle.js","sourceRoot":"","sources":[""],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,MAAM,EAEN,mBAAmB,EACnB,MAAM,EACN,wBAAwB,EACxB,qBAAqB,GACtB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,KAAK,EAAE,MAAM,2BAA2B,CAAC;AAClD,OAAO,EAAE,MAAM,EAAuB,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAG7E,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAI1D,MAAM,uBAAwB,SAAQ,aAAa;IAMpB;IALZ,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IACtB,QAAQ,GAAG,MAAM,CAAC,mBAAmB,CAAC,CAAC;IAEhD,SAAS,CAAwB;IAEzC,YAA6B,CAAuC;QAClE,KAAK,EAAE,CAAC;QADmB,MAAC,GAAD,CAAC,CAAsC;IAEpE,CAAC;IAED,WAAW,CAAC,WAAgC;QAC1C,IAAI,CAAC,SAAS,EAAE,OAAO,EAAE,CAAC;QAC1B,MAAM,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACzC,MAAM,KAAK,GAAG,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,IAAI,SAAS,CAAC;QACxD,MAAM,WAAW,GAAG,QAAQ,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,EAAE,MAAM,CAAC,oBAAoB,EAAE,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QAE/F,IAAI,CAAC,SAAS,GAAG,qBAAqB,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,EAAE,CACzD,MAAM,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAC1E,CAAC;IACJ,CAAC;CACF;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAIjC,KAA+B,EAC/B,cAAc,GAAG,OAAO,EACoB,EAAE;IAC9C,OAAO;QACL,SAAS,EAAE;YACT,wBAAwB,CAAC;gBACvB;oBACE,OAAO,EAAE,aAAa;oBACtB,UAAU,EAAE,CAAC,OAAO,GAAG,MAAM,CAAC,iBAAiB,CAAC,EAAE,EAAE,CAClD,IAAI,uBAAuB,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;iBACvE;aACF,CAAC;SACH;KACF,CAAC;AACJ,CAAC,CAAC"}
@@ -1,2 +0,0 @@
1
- export declare const INTERNAL_TRANSIGNAL_CONFIG: unique symbol;
2
- export declare const TREE_SHAKED_TRANSLATIONS: unique symbol;
@@ -1,3 +0,0 @@
1
- export const INTERNAL_TRANSIGNAL_CONFIG = Symbol('INTERNAL_TRANSIGNAL_CONFIG');
2
- export const TREE_SHAKED_TRANSLATIONS = Symbol('TREE_SHAKED_TRANSLATIONS');
3
- //# sourceMappingURL=internals.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"internals.js","sourceRoot":"","sources":[""],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,0BAA0B,GAAG,MAAM,CAAC,4BAA4B,CAAC,CAAC;AAC/E,MAAM,CAAC,MAAM,wBAAwB,GAAG,MAAM,CAAC,0BAA0B,CAAC,CAAC"}
@@ -1,34 +0,0 @@
1
- import { InjectionToken } from '@angular/core';
2
- import { TransignalFeature } from './features/types';
3
- import { INTERNAL_TRANSIGNAL_CONFIG } from './internals';
4
- import { TransignalService } from './transignal-service';
5
- import { TransignalConfig } from './types';
6
- import { StringKeys } from './utility-types';
7
- /**
8
- * Utility function to define a type of translations for type inference
9
- */
10
- export declare const treeShakedTranslations: <Translations extends Record<string, Record<string, unknown>>>() => Translations;
11
- export declare const TRANSIGNAL_CONFIG: InjectionToken<unknown>;
12
- /**
13
- * Use to inject transignal config
14
- */
15
- export declare const injectTransignalConfig: <Languages extends string, Translations extends Record<string, Record<string, unknown>>>() => TransignalConfig<Languages, Translations>;
16
- /**
17
- * Prepares type-safe transignal object
18
- * @param config Transignal configruation {@link TransignalConfig}
19
- * @param features Extra tree-shakeable features
20
- * - {@link withPreloadScopes} - preloads selected scopes
21
- * - {@link withServerSideLanguage} - sets language based on `document.lang` in SSR environment
22
- * - {@link withNavigatorLanguage} - sets language based on `navigator.language` in browser environment
23
- * - {@link withLanguageLocalStorageSync} - syncs language with localStorage
24
- * - {@link withTranslatedTitle} - enables translation of page title
25
- */
26
- export declare const prepareTransignal: <Languages extends string, Translations extends Record<string, Record<string, unknown>>>(config: TransignalConfig<Languages, Translations>, ...features: NoInfer<TransignalFeature<Languages, Translations>[]>) => {
27
- [INTERNAL_TRANSIGNAL_CONFIG]: {
28
- config: TransignalConfig<Languages, Translations>;
29
- features: TransignalFeature<Languages, Translations>[];
30
- };
31
- provide: () => import("@angular/core").EnvironmentProviders;
32
- service: () => TransignalService<Languages, Translations, StringKeys<Translations>>;
33
- t: <Scope extends StringKeys<Translations>>(scope: Scope) => import("./types").TranslateObj<Translations[Scope]>;
34
- };
@@ -1,36 +0,0 @@
1
- import { inject, InjectionToken, makeEnvironmentProviders } from '@angular/core';
2
- import { INTERNAL_TRANSIGNAL_CONFIG, TREE_SHAKED_TRANSLATIONS } from './internals';
3
- import { TransignalService } from './transignal-service';
4
- /**
5
- * Utility function to define a type of translations for type inference
6
- */
7
- export const treeShakedTranslations = () => TREE_SHAKED_TRANSLATIONS;
8
- export const TRANSIGNAL_CONFIG = new InjectionToken('TRANSIGNAL_CONFIG');
9
- /**
10
- * Use to inject transignal config
11
- */
12
- export const injectTransignalConfig = () => inject(TRANSIGNAL_CONFIG);
13
- /**
14
- * Prepares type-safe transignal object
15
- * @param config Transignal configruation {@link TransignalConfig}
16
- * @param features Extra tree-shakeable features
17
- * - {@link withPreloadScopes} - preloads selected scopes
18
- * - {@link withServerSideLanguage} - sets language based on `document.lang` in SSR environment
19
- * - {@link withNavigatorLanguage} - sets language based on `navigator.language` in browser environment
20
- * - {@link withLanguageLocalStorageSync} - syncs language with localStorage
21
- * - {@link withTranslatedTitle} - enables translation of page title
22
- */
23
- export const prepareTransignal = (config, ...features) => {
24
- const service = () => inject(TransignalService);
25
- return {
26
- [INTERNAL_TRANSIGNAL_CONFIG]: { config, features },
27
- provide: () => makeEnvironmentProviders([
28
- { provide: TRANSIGNAL_CONFIG, useValue: config },
29
- TransignalService,
30
- features.map(feature => feature.providers),
31
- ]),
32
- service,
33
- t: (scope) => service().t(scope),
34
- };
35
- };
36
- //# sourceMappingURL=transignal-config.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"transignal-config.js","sourceRoot":"","sources":[""],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AAGjF,OAAO,EAAE,0BAA0B,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AACnF,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAIzD;;GAEG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,GAElC,EAAE,CAAC,wBAAmD,CAAC;AAE3D,MAAM,CAAC,MAAM,iBAAiB,GAAG,IAAI,cAAc,CAAC,mBAAmB,CAAC,CAAC;AAEzE;;GAEG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,GAGlC,EAAE,CAAC,MAAM,CAA4C,iBAAiB,CAAC,CAAC;AAE5E;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAI/B,MAAiD,EACjD,GAAG,QAA+D,EAClE,EAAE;IACF,MAAM,OAAO,GAAG,GAAG,EAAE,CACnB,MAAM,CAAuE,iBAAiB,CAAC,CAAC;IAClG,OAAO;QACL,CAAC,0BAA0B,CAAC,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE;QAClD,OAAO,EAAE,GAAG,EAAE,CACZ,wBAAwB,CAAC;YACvB,EAAE,OAAO,EAAE,iBAAiB,EAAE,QAAQ,EAAE,MAAM,EAAE;YAChD,iBAAiB;YACjB,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,SAAS,CAAC;SAC3C,CAAC;QACJ,OAAO;QACP,CAAC,EAAE,CAAyC,KAAY,EAAE,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC;KAChF,CAAC;AACJ,CAAC,CAAC"}