@lwrjs/label-module-provider 0.11.0-alpha.10 → 0.11.0-alpha.12
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/build/cjs/index.cjs +13 -11
- package/build/es/index.js +16 -13
- package/build/es/utils.d.ts +2 -3
- package/package.json +5 -5
package/build/cjs/index.cjs
CHANGED
|
@@ -63,19 +63,23 @@ var LabelModuleProvider = class {
|
|
|
63
63
|
});
|
|
64
64
|
}
|
|
65
65
|
async getLabelInfo(specifier, initialLocale) {
|
|
66
|
+
const labelInfo = (0, import_utils.parseSpecifier)(this.labelDirs, specifier);
|
|
67
|
+
if (!labelInfo) {
|
|
68
|
+
return void 0;
|
|
69
|
+
}
|
|
70
|
+
let rawValue;
|
|
66
71
|
if (this.useI18nFallbacks) {
|
|
67
|
-
|
|
68
|
-
return this.getLabelInfoForLocale(
|
|
72
|
+
rawValue = await (0, import_shared_utils.walkLocaleFallbacks)(initialLocale, this.i18n, async (locale) => {
|
|
73
|
+
return this.getLabelInfoForLocale(labelInfo, locale, false);
|
|
69
74
|
});
|
|
70
75
|
} else {
|
|
71
|
-
|
|
76
|
+
rawValue = this.getLabelInfoForLocale(labelInfo, initialLocale, true);
|
|
72
77
|
}
|
|
78
|
+
const {labelReference} = labelInfo;
|
|
79
|
+
const labelValue = !rawValue && this.provideDefault ? labelReference : rawValue;
|
|
80
|
+
return labelValue ? {...labelInfo, labelValue} : void 0;
|
|
73
81
|
}
|
|
74
|
-
|
|
75
|
-
const labelInfo = (0, import_utils.parseSpecifier)(this.labelDirs, specifier);
|
|
76
|
-
if (!labelInfo) {
|
|
77
|
-
return void 0;
|
|
78
|
-
}
|
|
82
|
+
getLabelInfoForLocale(labelInfo, locale, legacyFallbacks) {
|
|
79
83
|
const {dir, labelReference} = labelInfo;
|
|
80
84
|
const cacheKey = `${dir}|${locale}`;
|
|
81
85
|
let labelJson = {};
|
|
@@ -91,9 +95,7 @@ var LabelModuleProvider = class {
|
|
|
91
95
|
}
|
|
92
96
|
const [namespace, labelName] = labelReference.split(".");
|
|
93
97
|
const namespacedLabels = labelJson[namespace] || {};
|
|
94
|
-
|
|
95
|
-
const labelValue = !rawValue && this.provideDefault ? labelReference : rawValue;
|
|
96
|
-
return labelValue ? {...labelInfo, labelValue} : void 0;
|
|
98
|
+
return namespacedLabels[labelName] || labelJson[labelReference];
|
|
97
99
|
}
|
|
98
100
|
async getModuleEntry({specifier}, runtimeParams = {}) {
|
|
99
101
|
const locale = runtimeParams.locale && runtimeParams.locale !== "*" ? runtimeParams.locale : this.defaultLocale;
|
package/build/es/index.js
CHANGED
|
@@ -37,24 +37,29 @@ export default class LabelModuleProvider {
|
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
39
|
async getLabelInfo(specifier, initialLocale) {
|
|
40
|
+
// Check if this provider handles given specifier package/prefix
|
|
41
|
+
// Modules handled by this provider have specifiers in this form: "{package}/{labelReference}"
|
|
42
|
+
const labelInfo = parseSpecifier(this.labelDirs, specifier);
|
|
43
|
+
if (!labelInfo) {
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
40
46
|
// If the app has defined any fallbacks in the config. Assume this is the fallback precedence we should follow.
|
|
47
|
+
let rawValue;
|
|
41
48
|
if (this.useI18nFallbacks) {
|
|
42
|
-
|
|
43
|
-
return this.getLabelInfoForLocale(
|
|
49
|
+
rawValue = await walkLocaleFallbacks(initialLocale, this.i18n, async (locale) => {
|
|
50
|
+
return this.getLabelInfoForLocale(labelInfo, locale, false);
|
|
44
51
|
});
|
|
45
52
|
}
|
|
46
53
|
// Other wise use the default fallbacks for backward compatibility
|
|
47
54
|
else {
|
|
48
|
-
|
|
55
|
+
rawValue = this.getLabelInfoForLocale(labelInfo, initialLocale, true);
|
|
49
56
|
}
|
|
57
|
+
// If provideDefault is on, and the label is missing, return the label reference/key
|
|
58
|
+
const { labelReference } = labelInfo;
|
|
59
|
+
const labelValue = !rawValue && this.provideDefault ? labelReference : rawValue;
|
|
60
|
+
return labelValue ? { ...labelInfo, labelValue: labelValue } : undefined;
|
|
50
61
|
}
|
|
51
|
-
|
|
52
|
-
// Check if this provider handles given specifier package/prefix
|
|
53
|
-
// Modules handled by this provider have specifiers in this form: "{package}/{labelReference}"
|
|
54
|
-
const labelInfo = parseSpecifier(this.labelDirs, specifier);
|
|
55
|
-
if (!labelInfo) {
|
|
56
|
-
return undefined;
|
|
57
|
-
}
|
|
62
|
+
getLabelInfoForLocale(labelInfo, locale, legacyFallbacks) {
|
|
58
63
|
const { dir, labelReference } = labelInfo;
|
|
59
64
|
// Fetch the label JSON from the cache or file system
|
|
60
65
|
const cacheKey = `${dir}|${locale}`;
|
|
@@ -79,9 +84,7 @@ export default class LabelModuleProvider {
|
|
|
79
84
|
// If provideDefault is on, and the label is missing, return the label reference/key
|
|
80
85
|
const [namespace, labelName] = labelReference.split('.');
|
|
81
86
|
const namespacedLabels = (labelJson[namespace] || {});
|
|
82
|
-
|
|
83
|
-
const labelValue = !rawValue && this.provideDefault ? labelReference : rawValue;
|
|
84
|
-
return labelValue ? { ...labelInfo, labelValue: labelValue } : undefined;
|
|
87
|
+
return namespacedLabels[labelName] || labelJson[labelReference]; // nested or flat structure
|
|
85
88
|
}
|
|
86
89
|
async getModuleEntry({ specifier }, runtimeParams = {}) {
|
|
87
90
|
const locale = (runtimeParams.locale && runtimeParams.locale !== '*' ? runtimeParams.locale : this.defaultLocale);
|
package/build/es/utils.d.ts
CHANGED
|
@@ -6,14 +6,14 @@ export interface LabelProviderOptions {
|
|
|
6
6
|
provideDefault: boolean;
|
|
7
7
|
labelDirs: LabelDirConfig[];
|
|
8
8
|
}
|
|
9
|
-
interface LabelKeyInfo extends LabelDirConfig {
|
|
9
|
+
export interface LabelKeyInfo extends LabelDirConfig {
|
|
10
10
|
labelReference: string;
|
|
11
11
|
fileType: string;
|
|
12
12
|
}
|
|
13
13
|
export interface LabelInfo extends LabelKeyInfo {
|
|
14
14
|
labelValue: string;
|
|
15
15
|
}
|
|
16
|
-
type LabelEntry = {
|
|
16
|
+
export type LabelEntry = {
|
|
17
17
|
[key: string]: string;
|
|
18
18
|
};
|
|
19
19
|
export type LabelMap = {
|
|
@@ -55,5 +55,4 @@ export declare function getLabels(labelDir: string, locale: string, legacyFallba
|
|
|
55
55
|
* @param fileType - The module file type: html, css or js
|
|
56
56
|
*/
|
|
57
57
|
export declare function generateModule(label: string): string;
|
|
58
|
-
export {};
|
|
59
58
|
//# sourceMappingURL=utils.d.ts.map
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.11.0-alpha.
|
|
7
|
+
"version": "0.11.0-alpha.12",
|
|
8
8
|
"homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
@@ -30,15 +30,15 @@
|
|
|
30
30
|
"build/**/*.d.ts"
|
|
31
31
|
],
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@lwrjs/diagnostics": "0.11.0-alpha.
|
|
34
|
-
"@lwrjs/shared-utils": "0.11.0-alpha.
|
|
33
|
+
"@lwrjs/diagnostics": "0.11.0-alpha.12",
|
|
34
|
+
"@lwrjs/shared-utils": "0.11.0-alpha.12",
|
|
35
35
|
"ajv": "6.12.6"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@lwrjs/types": "0.11.0-alpha.
|
|
38
|
+
"@lwrjs/types": "0.11.0-alpha.12"
|
|
39
39
|
},
|
|
40
40
|
"engines": {
|
|
41
41
|
"node": ">=16.0.0"
|
|
42
42
|
},
|
|
43
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "e19ffe5a48dc2b2b6d74d8acfa9658bedb5dd1ff"
|
|
44
44
|
}
|