@prosopo/locale 3.6.2 → 3.7.0

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 (106) hide show
  1. package/.turbo/turbo-build$colon$cjs.log +3 -6
  2. package/.turbo/turbo-build$colon$tsc.log +6 -9
  3. package/.turbo/turbo-build.log +5 -11
  4. package/CHANGELOG.md +16 -0
  5. package/LICENSE +201 -0
  6. package/dist/cjs/locales/en/translation.cjs +2 -1
  7. package/dist/locales/ar/translation.json +2 -1
  8. package/dist/locales/az/translation.json +2 -1
  9. package/dist/locales/cs/translation.json +2 -1
  10. package/dist/locales/de/translation.json +2 -1
  11. package/dist/locales/el/translation.json +2 -1
  12. package/dist/locales/en/translation.js +2 -1
  13. package/dist/locales/en/translation.json +2 -1
  14. package/dist/locales/es/translation.json +2 -1
  15. package/dist/locales/fi/translation.json +2 -1
  16. package/dist/locales/fr/translation.json +2 -1
  17. package/dist/locales/hi/translation.json +2 -1
  18. package/dist/locales/hu/translation.json +2 -1
  19. package/dist/locales/id/translation.json +2 -1
  20. package/dist/locales/it/translation.json +2 -1
  21. package/dist/locales/ja/translation.json +2 -1
  22. package/dist/locales/jv/translation.json +2 -1
  23. package/dist/locales/ko/translation.json +2 -1
  24. package/dist/locales/ml/translation.json +2 -1
  25. package/dist/locales/ms/translation.json +2 -1
  26. package/dist/locales/nl/translation.json +2 -1
  27. package/dist/locales/no/translation.json +2 -1
  28. package/dist/locales/pl/translation.json +2 -1
  29. package/dist/locales/pt/translation.json +2 -1
  30. package/dist/locales/pt-BR/translation.json +2 -1
  31. package/dist/locales/ro/translation.json +2 -1
  32. package/dist/locales/ru/translation.json +2 -1
  33. package/dist/locales/sr/translation.json +2 -1
  34. package/dist/locales/sv/translation.json +2 -1
  35. package/dist/locales/th/translation.json +2 -1
  36. package/dist/locales/tr/translation.json +2 -1
  37. package/dist/locales/uk/translation.json +2 -1
  38. package/dist/locales/vi/translation.json +2 -1
  39. package/dist/locales/zh-CN/translation.json +2 -1
  40. package/package.json +65 -66
  41. package/src/direction.ts +0 -36
  42. package/src/errorMessage.ts +0 -37
  43. package/src/i18SharedOptions.ts +0 -29
  44. package/src/i18nBackend.ts +0 -69
  45. package/src/i18nFrontend.ts +0 -267
  46. package/src/i18nMiddleware.ts +0 -35
  47. package/src/index.ts +0 -33
  48. package/src/loadI18next.ts +0 -136
  49. package/src/locales/ar/translation.json +0 -493
  50. package/src/locales/az/translation.json +0 -493
  51. package/src/locales/cs/translation.json +0 -493
  52. package/src/locales/de/translation.json +0 -493
  53. package/src/locales/el/translation.json +0 -493
  54. package/src/locales/en/translation.json +0 -493
  55. package/src/locales/es/translation.json +0 -493
  56. package/src/locales/fi/translation.json +0 -493
  57. package/src/locales/fr/translation.json +0 -493
  58. package/src/locales/hi/translation.json +0 -493
  59. package/src/locales/hu/translation.json +0 -493
  60. package/src/locales/id/translation.json +0 -493
  61. package/src/locales/it/translation.json +0 -493
  62. package/src/locales/ja/translation.json +0 -493
  63. package/src/locales/jv/translation.json +0 -493
  64. package/src/locales/ko/translation.json +0 -493
  65. package/src/locales/ml/translation.json +0 -493
  66. package/src/locales/ms/translation.json +0 -493
  67. package/src/locales/nl/translation.json +0 -493
  68. package/src/locales/no/translation.json +0 -493
  69. package/src/locales/pl/translation.json +0 -493
  70. package/src/locales/pt/translation.json +0 -493
  71. package/src/locales/pt-BR/translation.json +0 -493
  72. package/src/locales/ro/translation.json +0 -493
  73. package/src/locales/ru/translation.json +0 -493
  74. package/src/locales/sr/translation.json +0 -493
  75. package/src/locales/sv/translation.json +0 -493
  76. package/src/locales/th/translation.json +0 -493
  77. package/src/locales/tr/translation.json +0 -493
  78. package/src/locales/uk/translation.json +0 -493
  79. package/src/locales/vi/translation.json +0 -493
  80. package/src/locales/zh-CN/translation.json +0 -493
  81. package/src/process.ts +0 -29
  82. package/src/tests/direction.unit.test.ts +0 -52
  83. package/src/tests/errorMessage.unit.test.ts +0 -84
  84. package/src/tests/i18SharedOptions.unit.test.ts +0 -139
  85. package/src/tests/i18nBackend.unit.test.ts +0 -241
  86. package/src/tests/i18nFrontend.unit.test.ts +0 -404
  87. package/src/tests/i18nMiddleware.unit.test.ts +0 -159
  88. package/src/tests/loadI18next.unit.test.ts +0 -443
  89. package/src/tests/locale.test-d.ts +0 -184
  90. package/src/tests/localePlaceholders.unit.test.ts +0 -81
  91. package/src/tests/locales.unit.test.ts +0 -79
  92. package/src/tests/process.unit.test.ts +0 -33
  93. package/src/tests/thrownErrorKeys.unit.test.ts +0 -91
  94. package/src/tests/translationKey.unit.test.ts +0 -155
  95. package/src/tests/translations.unit.test.ts +0 -97
  96. package/src/tests/translator.unit.test.ts +0 -213
  97. package/src/tests/util.unit.test.ts +0 -102
  98. package/src/translationKey.ts +0 -73
  99. package/src/translations.ts +0 -55
  100. package/src/translator.ts +0 -69
  101. package/src/types.ts +0 -47
  102. package/src/util.ts +0 -25
  103. package/tsconfig.cjs.json +0 -21
  104. package/tsconfig.json +0 -22
  105. package/tsconfig.tsbuildinfo +0 -1
  106. package/tsconfig.types.json +0 -9
@@ -1,35 +0,0 @@
1
- // Copyright 2021-2026 Prosopo (UK) Ltd.
2
- //
3
- // Licensed under the Apache License, Version 2.0 (the "License");
4
- // you may not use this file except in compliance with the License.
5
- // You may obtain a copy of the License at
6
- //
7
- // http://www.apache.org/licenses/LICENSE-2.0
8
- //
9
- // Unless required by applicable law or agreed to in writing, software
10
- // distributed under the License is distributed on an "AS IS" BASIS,
11
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- // See the License for the specific language governing permissions and
13
- // limitations under the License.
14
-
15
- import i18n from "i18next";
16
- import { handle } from "i18next-http-middleware";
17
- import loadI18next from "./loadI18next.js";
18
-
19
- // i18next-http-middleware stopped exporting HandleOptions in 3.9.x (the
20
- // interface is still there, just no longer `export`ed). Derive it from handle()
21
- // so it keeps tracking whatever the library actually accepts.
22
- type HandleOptions = NonNullable<Parameters<typeof handle>[1]>;
23
-
24
- async function i18nMiddleware(
25
- options: HandleOptions,
26
- ): Promise<ReturnType<typeof handle>> {
27
- // The middleware needs the i18next instance itself, not the narrow Ti18n
28
- // the widget shares with it. loadI18next(true) initialises that very
29
- // singleton and waits for its resources, so importing it here is the same
30
- // object, fully loaded.
31
- await loadI18next(true);
32
- return handle(i18n, { ...options });
33
- }
34
-
35
- export default i18nMiddleware;
package/src/index.ts DELETED
@@ -1,33 +0,0 @@
1
- // Copyright 2021-2026 Prosopo (UK) Ltd.
2
- //
3
- // Licensed under the Apache License, Version 2.0 (the "License");
4
- // you may not use this file except in compliance with the License.
5
- // You may obtain a copy of the License at
6
- //
7
- // http://www.apache.org/licenses/LICENSE-2.0
8
- //
9
- // Unless required by applicable law or agreed to in writing, software
10
- // distributed under the License is distributed on an "AS IS" BASIS,
11
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- // See the License for the specific language governing permissions and
13
- // limitations under the License.
14
-
15
- export { getLanguageDirection } from "./direction.js";
16
- export type { TextDirection } from "./direction.js";
17
- export { default as i18nMiddleware } from "./i18nMiddleware.js";
18
- export { default as loadI18next } from "./loadI18next.js";
19
- export { isLanguage, LanguageCodes, Languages } from "./translations.js";
20
- export type { Language } from "./translations.js";
21
- export { isClientSide } from "./util.js";
22
- export { isTranslationKey, translationKeys } from "./translationKey.js";
23
- export type { TranslationKey } from "./translationKey.js";
24
- export { createTranslator } from "./translator.js";
25
- export type { Translator } from "./translator.js";
26
- export type {
27
- I18nEvent,
28
- Ti18n,
29
- TranslateFn,
30
- TranslateOptions,
31
- } from "./types.js";
32
- export { localiseErrorMessage } from "./errorMessage.js";
33
- export type { KeyedErrorMessage } from "./errorMessage.js";
@@ -1,136 +0,0 @@
1
- // Copyright 2021-2026 Prosopo (UK) Ltd.
2
- //
3
- // Licensed under the Apache License, Version 2.0 (the "License");
4
- // you may not use this file except in compliance with the License.
5
- // You may obtain a copy of the License at
6
- //
7
- // http://www.apache.org/licenses/LICENSE-2.0
8
- //
9
- // Unless required by applicable law or agreed to in writing, software
10
- // distributed under the License is distributed on an "AS IS" BASIS,
11
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- // See the License for the specific language governing permissions and
13
- // limitations under the License.
14
-
15
- import type { Ti18n } from "./types.js";
16
-
17
- let i18nInstance: Ti18n;
18
-
19
- /**
20
- * How long to wait for i18next to report `loaded` before giving up on it.
21
- *
22
- * Resolution is driven by an event, and events are not guaranteed: a backend
23
- * that never answers (http backend against a dead CDN, fs backend against a
24
- * missing locales dir) leaves the listener armed and the promise pending for
25
- * the lifetime of the process. `cli.ts` calls loadI18next(true).then(...) with
26
- * nothing to time it out, so a pending promise there is a silent boot hang with
27
- * no log line to explain it.
28
- */
29
- export const I18N_LOAD_TIMEOUT_MS = 10_000;
30
-
31
- const reconcileLanguage = async (
32
- instance: Ti18n,
33
- lng: string | undefined,
34
- ): Promise<Ti18n> => {
35
- if (lng && instance.language !== lng) {
36
- await instance.changeLanguage(lng);
37
- }
38
- return instance;
39
- };
40
-
41
- async function loadI18next(backend: boolean, lng?: string): Promise<Ti18n> {
42
- return new Promise((resolve, reject) => {
43
- // On timeout we resolve with the (possibly not fully loaded) instance
44
- // rather than rejecting. i18next falls back to the key itself when a
45
- // resource is missing, so a degraded instance renders untranslated text;
46
- // a rejection instead takes down the caller, and neither caller handles
47
- // one — cli.ts has no .catch, and widgetFactory awaits it inside the
48
- // render path, so the widget would not appear at all. Untranslated beats
49
- // absent. Genuine errors still reject: this arm only fires on silence.
50
- let settled = false;
51
- // No `settled` guard needed here: both latches clear this timer, so it
52
- // can only fire while nothing has settled.
53
- const timer = setTimeout(() => {
54
- settled = true;
55
- if (i18nInstance) {
56
- resolve(i18nInstance);
57
- } else {
58
- reject(
59
- new Error(
60
- `i18next did not load within ${I18N_LOAD_TIMEOUT_MS}ms and no instance was created`,
61
- ),
62
- );
63
- }
64
- }, I18N_LOAD_TIMEOUT_MS);
65
- // Node keeps the event loop alive for a pending timer, which would hold
66
- // a short-lived CLI process open for the full timeout after it had
67
- // otherwise finished.
68
- timer.unref?.();
69
-
70
- // Both latches are one-shot: i18next can emit `loaded` more than once
71
- // (per namespace, and again after changeLanguage), and a late event
72
- // arriving after the timeout must not re-settle or leak a second timer.
73
- const done = (instance: Ti18n): void => {
74
- if (settled) {
75
- return;
76
- }
77
- settled = true;
78
- clearTimeout(timer);
79
- resolve(instance);
80
- };
81
- const failWith = (error: unknown): void => {
82
- if (settled) {
83
- return;
84
- }
85
- settled = true;
86
- clearTimeout(timer);
87
- reject(error);
88
- };
89
-
90
- // Every asynchronous branch below terminates in `.catch(failWith)`. A
91
- // synchronous try/catch cannot see a rejected dynamic import or a
92
- // rejected changeLanguage(), so without these the executor would
93
- // simply return and the promise would stay pending forever — callers
94
- // (i18nMiddleware, and through it the whole server bootstrap) would
95
- // hang rather than fail.
96
- if (backend) {
97
- import("./i18nBackend.js")
98
- .then(({ default: initializeI18n }) => {
99
- if (!i18nInstance) {
100
- // pass the resolver into the i18n init fn, which fires it on the first
101
- // "loaded" event
102
- i18nInstance = initializeI18n(done);
103
- } else {
104
- // we've already initialised i18n so just return it
105
- done(i18nInstance);
106
- }
107
- })
108
- .catch(failWith);
109
- } else {
110
- import("./i18nFrontend.js")
111
- .then(({ default: initializeI18n }) => {
112
- if (!i18nInstance) {
113
- // Pass `lng` in on first init so browser detection is skipped
114
- // entirely when the site owner has supplied a language. The
115
- // resolver only fires on the `loaded` event, so at resolve
116
- // time the target-language resources are guaranteed present.
117
- i18nInstance = initializeI18n((instance) => {
118
- void reconcileLanguage(instance, lng).then(done).catch(failWith);
119
- }, lng);
120
- } else {
121
- // Singleton already exists (e.g. a prior widget mounted with a
122
- // different language, or a direct consumer initialised earlier).
123
- // Reconcile before resolving so callers can render synchronously
124
- // against the requested language instead of seeing a flash of
125
- // the previous one.
126
- void reconcileLanguage(i18nInstance, lng)
127
- .then(done)
128
- .catch(failWith);
129
- }
130
- })
131
- .catch(failWith);
132
- }
133
- });
134
- }
135
-
136
- export default loadI18next;