@cocoar/localization 0.1.0-beta.155 → 0.1.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.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocoar/localization",
|
|
3
|
-
"version": "0.1.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "Localization and language management for the Cocoar Design System",
|
|
5
5
|
"author": "Cocoar",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -26,12 +26,12 @@
|
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
28
|
"@js-temporal/polyfill": "^0.5.1",
|
|
29
|
-
"@angular/common": "21.0.
|
|
29
|
+
"@angular/common": "^21.0.0",
|
|
30
30
|
"@angular/core": "^21.0.0",
|
|
31
31
|
"rxjs": "^7.0.0"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@cocoar/ts-utils": "0.1.0
|
|
34
|
+
"@cocoar/ts-utils": "0.1.0",
|
|
35
35
|
"tslib": "^2.3.0"
|
|
36
36
|
},
|
|
37
37
|
"sideEffects": false,
|
|
@@ -226,12 +226,19 @@ declare abstract class CoarLocalizationDataLoader {
|
|
|
226
226
|
static ɵprov: i0.ɵɵInjectableDeclaration<CoarLocalizationDataLoader>;
|
|
227
227
|
}
|
|
228
228
|
/**
|
|
229
|
-
* HTTP-based locale data loader.
|
|
230
|
-
* Loads locale data from JSON files via HTTP.
|
|
229
|
+
* HTTP-based locale data loader with BCP 47 fallback.
|
|
231
230
|
*
|
|
232
|
-
*
|
|
231
|
+
* Loads locale data from JSON files via HTTP.
|
|
233
232
|
* Typically used as a second source (after Intl) to provide business-specific overrides.
|
|
234
233
|
*
|
|
234
|
+
* When a full BCP 47 tag is used (e.g., `de-AT`), the loader:
|
|
235
|
+
* 1. Loads the base language file (`de.json`)
|
|
236
|
+
* 2. Tries to load the regional file (`de-AT.json`)
|
|
237
|
+
* 3. Deep-merges them — regional fields override base fields
|
|
238
|
+
*
|
|
239
|
+
* If the regional file doesn't exist, the base file is used as-is.
|
|
240
|
+
* If the base file doesn't exist either, the loader fails (propagated to caller).
|
|
241
|
+
*
|
|
235
242
|
* @example
|
|
236
243
|
* ```typescript
|
|
237
244
|
* // Simple base path
|
|
@@ -247,6 +254,15 @@ declare abstract class CoarLocalizationDataLoader {
|
|
|
247
254
|
* { 'Authorization': 'Bearer token' }
|
|
248
255
|
* )
|
|
249
256
|
* ```
|
|
257
|
+
*
|
|
258
|
+
* ## Expected file structure
|
|
259
|
+
* ```
|
|
260
|
+
* /locales/
|
|
261
|
+
* en.json ← base English overrides
|
|
262
|
+
* en-AT.json ← optional: Austrian-specific overrides on top of en.json
|
|
263
|
+
* de.json ← base German overrides
|
|
264
|
+
* de-AT.json ← optional: Austrian-specific overrides on top of de.json
|
|
265
|
+
* ```
|
|
250
266
|
*/
|
|
251
267
|
declare class CoarHttpLocaleDataLoader extends CoarLocalizationDataLoader {
|
|
252
268
|
private readonly httpClient;
|
|
@@ -254,6 +270,7 @@ declare class CoarHttpLocaleDataLoader extends CoarLocalizationDataLoader {
|
|
|
254
270
|
private readonly headers?;
|
|
255
271
|
constructor(httpClient: HttpClient, urlFn: (language: string) => string, headers?: Record<string, string> | undefined);
|
|
256
272
|
loadLocaleData(locale: string): Observable<CoarLocalizationData>;
|
|
273
|
+
private loadFile;
|
|
257
274
|
}
|
|
258
275
|
|
|
259
276
|
/**
|
|
@@ -451,6 +468,8 @@ declare class CoarLocalizationDataStore {
|
|
|
451
468
|
* Clear all loaded locale data.
|
|
452
469
|
*/
|
|
453
470
|
clear(): void;
|
|
471
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<CoarLocalizationDataStore, never>;
|
|
472
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<CoarLocalizationDataStore>;
|
|
454
473
|
}
|
|
455
474
|
|
|
456
475
|
/**
|
|
@@ -1073,10 +1092,21 @@ declare abstract class CoarTranslationLoader {
|
|
|
1073
1092
|
abstract loadTranslations(language: string): Observable<CoarTranslations>;
|
|
1074
1093
|
}
|
|
1075
1094
|
/**
|
|
1076
|
-
* HTTP-based translation loader.
|
|
1095
|
+
* HTTP-based translation loader with BCP 47 fallback.
|
|
1077
1096
|
*
|
|
1078
1097
|
* Loads translation JSON files from a configurable URL function.
|
|
1079
1098
|
*
|
|
1099
|
+
* When a full BCP 47 tag is used (e.g., `de-AT`), the loader:
|
|
1100
|
+
* 1. Loads the base language file (`de.json`)
|
|
1101
|
+
* 2. Tries to load the regional file (`de-AT.json`)
|
|
1102
|
+
* 3. Merges them — regional keys override base keys
|
|
1103
|
+
*
|
|
1104
|
+
* If the regional file doesn't exist, the base file is used as-is.
|
|
1105
|
+
* If the base file doesn't exist either, the loader fails (propagated to caller).
|
|
1106
|
+
*
|
|
1107
|
+
* This means `en.json` serves all English variants. An optional `en-AT.json`
|
|
1108
|
+
* only needs to contain keys that differ from the base.
|
|
1109
|
+
*
|
|
1080
1110
|
* ## Usage
|
|
1081
1111
|
* ```ts
|
|
1082
1112
|
* const loader = new CoarHttpTranslationLoader();
|
|
@@ -1084,6 +1114,15 @@ declare abstract class CoarTranslationLoader {
|
|
|
1084
1114
|
* loader.headers = { 'Authorization': 'Bearer token' };
|
|
1085
1115
|
* ```
|
|
1086
1116
|
*
|
|
1117
|
+
* ## Expected file structure
|
|
1118
|
+
* ```
|
|
1119
|
+
* /i18n/
|
|
1120
|
+
* en.json ← base English (used for en-US, en-GB, en-AT, etc.)
|
|
1121
|
+
* en-AT.json ← optional: only keys that differ from en.json
|
|
1122
|
+
* de.json ← base German
|
|
1123
|
+
* de-AT.json ← optional: Austrian overrides (if any)
|
|
1124
|
+
* ```
|
|
1125
|
+
*
|
|
1087
1126
|
* ## Expected JSON format
|
|
1088
1127
|
* ```json
|
|
1089
1128
|
* {
|
|
@@ -1100,6 +1139,7 @@ declare class CoarHttpTranslationLoader implements CoarTranslationLoader {
|
|
|
1100
1139
|
/** Optional HTTP headers */
|
|
1101
1140
|
headers?: Record<string, string>;
|
|
1102
1141
|
loadTranslations(language: string): Observable<CoarTranslations>;
|
|
1142
|
+
private loadFile;
|
|
1103
1143
|
static ɵfac: i0.ɵɵFactoryDeclaration<CoarHttpTranslationLoader, never>;
|
|
1104
1144
|
static ɵprov: i0.ɵɵInjectableDeclaration<CoarHttpTranslationLoader>;
|
|
1105
1145
|
}
|