@zohodesk/client_build_tool 0.0.11-exp.12 → 0.0.11-exp.15
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/lib/schemas/defaultConfigValues.js +3 -1
- package/lib/schemas/defaultConfigValuesOnly.js +3 -1
- package/lib/shared/bundler/webpack/custom_plugins/I18nNumericIndexPlugin/I18nNumericIndexPlugin.js +34 -18
- package/lib/shared/bundler/webpack/loaderConfigs/i18nIdReplaceLoaderConfig.js +1 -0
- package/lib/shared/bundler/webpack/loaders/i18nIdReplaceLoader.js +2 -0
- package/lib/shared/bundler/webpack/pluginConfigs/configI18nNumericIndexPlugin.js +19 -9
- package/package.json +1 -1
|
@@ -176,6 +176,7 @@ var _default = {
|
|
|
176
176
|
},
|
|
177
177
|
i18nIndexing: {
|
|
178
178
|
enable: false,
|
|
179
|
+
devMode: false,
|
|
179
180
|
jsResourcePath: './deskapp/properties/JSResources.properties',
|
|
180
181
|
propertiesFolderPath: './deskapp/properties',
|
|
181
182
|
numericMapPath: './deskapp/properties/i18n-numeric-map.json',
|
|
@@ -187,7 +188,8 @@ var _default = {
|
|
|
187
188
|
localeVarName: 'window.userLangCode',
|
|
188
189
|
singleFile: false,
|
|
189
190
|
includeContentHash: false,
|
|
190
|
-
generateManifest: false
|
|
191
|
+
generateManifest: false,
|
|
192
|
+
manifestPath: null
|
|
191
193
|
},
|
|
192
194
|
publicFolders: ['...'],
|
|
193
195
|
app: {
|
|
@@ -99,6 +99,7 @@ var _default = {
|
|
|
99
99
|
},
|
|
100
100
|
i18nIndexing: {
|
|
101
101
|
enable: false,
|
|
102
|
+
devMode: false,
|
|
102
103
|
jsResourcePath: './deskapp/properties/JSResources.properties',
|
|
103
104
|
propertiesFolderPath: './deskapp/properties',
|
|
104
105
|
numericMapPath: './deskapp/properties/i18n-numeric-map.json',
|
|
@@ -109,7 +110,8 @@ var _default = {
|
|
|
109
110
|
localeVarName: 'window.userLangCode',
|
|
110
111
|
singleFile: false,
|
|
111
112
|
includeContentHash: false,
|
|
112
|
-
generateManifest: false
|
|
113
|
+
generateManifest: false,
|
|
114
|
+
manifestPath: null
|
|
113
115
|
},
|
|
114
116
|
publicFolders: ['...', {
|
|
115
117
|
source: './deskapp/tp/',
|
package/lib/shared/bundler/webpack/custom_plugins/I18nNumericIndexPlugin/I18nNumericIndexPlugin.js
CHANGED
|
@@ -28,7 +28,8 @@ class I18nNumericIndexPlugin {
|
|
|
28
28
|
singleFile: options.singleFile || false,
|
|
29
29
|
singleFileTemplate: options.singleFileTemplate,
|
|
30
30
|
includeContentHash: options.includeContentHash || false,
|
|
31
|
-
generateManifest: options.generateManifest || false
|
|
31
|
+
generateManifest: options.generateManifest || false,
|
|
32
|
+
manifestPath: options.manifestPath || 'i18n/manifest.json'
|
|
32
33
|
};
|
|
33
34
|
this.numericMap = null;
|
|
34
35
|
this.i18nData = null;
|
|
@@ -103,7 +104,8 @@ class I18nNumericIndexPlugin {
|
|
|
103
104
|
|
|
104
105
|
const {
|
|
105
106
|
sortedKeys,
|
|
106
|
-
totalKeys
|
|
107
|
+
totalKeys,
|
|
108
|
+
originalKeyToNumericId
|
|
107
109
|
} = this.getNumericMap(compilation);
|
|
108
110
|
const {
|
|
109
111
|
jsResourceBase,
|
|
@@ -113,28 +115,31 @@ class I18nNumericIndexPlugin {
|
|
|
113
115
|
if (!locales.length) return callback();
|
|
114
116
|
const numericKeysSet = new Set(sortedKeys);
|
|
115
117
|
const englishData = allI18n.en_US || jsResourceBase;
|
|
118
|
+
const isDevMode = this.options.devMode || process.env.NODE_ENV === 'development';
|
|
116
119
|
locales.forEach(locale => {
|
|
117
120
|
const localeData = allI18n[locale] || {};
|
|
118
121
|
const numericData = {};
|
|
119
|
-
|
|
120
|
-
for (let i = 0; i < totalKeys; i++) {
|
|
121
|
-
const key = sortedKeys[i];
|
|
122
|
-
|
|
123
|
-
if (key && jsResourceBase[key] !== undefined) {
|
|
124
|
-
numericData[i] = localeData[key] ?? englishData[key];
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
const dynamicData = {};
|
|
122
|
+
const unmappedData = {};
|
|
129
123
|
Object.keys(jsResourceBase).forEach(key => {
|
|
130
|
-
|
|
131
|
-
|
|
124
|
+
const translation = localeData[key] ?? englishData[key];
|
|
125
|
+
|
|
126
|
+
if (originalKeyToNumericId && originalKeyToNumericId.hasOwnProperty(key)) {
|
|
127
|
+
const numericId = originalKeyToNumericId[key];
|
|
128
|
+
numericData[numericId] = translation;
|
|
129
|
+
} else if (numericKeysSet.has(key)) {
|
|
130
|
+
const index = sortedKeys.indexOf(key);
|
|
131
|
+
|
|
132
|
+
if (index !== -1) {
|
|
133
|
+
numericData[index] = translation;
|
|
134
|
+
}
|
|
135
|
+
} else {
|
|
136
|
+
unmappedData[key] = translation;
|
|
132
137
|
}
|
|
133
138
|
});
|
|
134
139
|
|
|
135
140
|
if (this.options.singleFile) {
|
|
136
141
|
const combinedData = { ...numericData,
|
|
137
|
-
...
|
|
142
|
+
...unmappedData
|
|
138
143
|
};
|
|
139
144
|
|
|
140
145
|
if (Object.keys(combinedData).length > 0) {
|
|
@@ -146,14 +151,25 @@ class I18nNumericIndexPlugin {
|
|
|
146
151
|
this.emitChunk(compilation, this.options.numericFilenameTemplate, locale, numericData, 'numeric');
|
|
147
152
|
}
|
|
148
153
|
|
|
149
|
-
if (Object.keys(
|
|
150
|
-
this.emitChunk(compilation, this.options.dynamicFilenameTemplate, locale,
|
|
154
|
+
if (Object.keys(unmappedData).length > 0) {
|
|
155
|
+
this.emitChunk(compilation, this.options.dynamicFilenameTemplate, locale, unmappedData, 'dynamic');
|
|
151
156
|
}
|
|
152
157
|
}
|
|
153
158
|
});
|
|
154
159
|
|
|
155
160
|
if (this.options.generateManifest && Object.keys(this.manifest).length > 0) {
|
|
156
|
-
|
|
161
|
+
// Determine manifest path
|
|
162
|
+
let manifestPath;
|
|
163
|
+
|
|
164
|
+
if (this.options.manifestPath) {
|
|
165
|
+
// Use explicitly configured path
|
|
166
|
+
manifestPath = this.options.manifestPath;
|
|
167
|
+
} else {
|
|
168
|
+
// Default to same directory as i18n files with manifest.json name
|
|
169
|
+
const template = this.options.singleFileTemplate || this.options.numericFilenameTemplate;
|
|
170
|
+
manifestPath = path.dirname(template) + '/manifest.json';
|
|
171
|
+
}
|
|
172
|
+
|
|
157
173
|
const manifestContent = JSON.stringify(this.manifest, null, 2);
|
|
158
174
|
compilation.emitAsset(manifestPath, new RawSource(manifestContent));
|
|
159
175
|
}
|
|
@@ -56,6 +56,7 @@ function i18nIdReplaceLoaderConfig(options, webpackContext) {
|
|
|
56
56
|
allI18nData: allI18nData,
|
|
57
57
|
sourceMaps: false,
|
|
58
58
|
numericMapPath: numericMapPath,
|
|
59
|
+
devMode: options.i18nIndexing?.devMode || false,
|
|
59
60
|
includePaths: options.i18nIndexing?.loaderOptions?.includePaths || [],
|
|
60
61
|
excludePaths: options.i18nIndexing?.loaderOptions?.excludePaths || ['node_modules', 'tests']
|
|
61
62
|
};
|
|
@@ -61,6 +61,8 @@ module.exports = function i18nIdReplaceLoader(source, map) {
|
|
|
61
61
|
return callback(null, source, map);
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
+
const isDevMode = options.devMode || process.env.NODE_ENV === 'development';
|
|
65
|
+
|
|
64
66
|
try {
|
|
65
67
|
const ast = parser.parse(source, {
|
|
66
68
|
sourceType: 'module',
|
|
@@ -16,8 +16,11 @@ function configI18nNumericIndexPlugin(options) {
|
|
|
16
16
|
return null;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
const i18nOpts = options.i18nIndexing;
|
|
20
|
-
|
|
19
|
+
const i18nOpts = options.i18nIndexing; // Check for required options based on singleFile mode
|
|
20
|
+
|
|
21
|
+
const baseRequiredOptions = ['jsResourcePath', 'propertiesFolderPath', 'numericMapPath', 'jsonpFunc', 'htmlTemplateLabel', 'localeVarName']; // Add template requirements based on mode
|
|
22
|
+
|
|
23
|
+
const requiredOptions = i18nOpts.singleFile ? [...baseRequiredOptions, 'singleFileTemplate'] : [...baseRequiredOptions, 'numericFilenameTemplate', 'dynamicFilenameTemplate'];
|
|
21
24
|
const missingOptions = requiredOptions.filter(opt => !i18nOpts[opt]);
|
|
22
25
|
|
|
23
26
|
if (missingOptions.length > 0) {
|
|
@@ -31,14 +34,20 @@ function configI18nNumericIndexPlugin(options) {
|
|
|
31
34
|
jsResource: i18nOpts.jsResourcePath,
|
|
32
35
|
propertiesFolder: i18nOpts.propertiesFolderPath,
|
|
33
36
|
disableDefault: false
|
|
34
|
-
});
|
|
37
|
+
}); // Validate template patterns based on mode
|
|
35
38
|
|
|
36
|
-
if (
|
|
37
|
-
|
|
38
|
-
|
|
39
|
+
if (i18nOpts.singleFile) {
|
|
40
|
+
if (i18nOpts.singleFileTemplate && !i18nOpts.singleFileTemplate.includes('[locale]')) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
} else {
|
|
44
|
+
if (!i18nOpts.numericFilenameTemplate?.includes('[locale]')) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
39
47
|
|
|
40
|
-
|
|
41
|
-
|
|
48
|
+
if (!i18nOpts.dynamicFilenameTemplate?.includes('[locale]')) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
42
51
|
}
|
|
43
52
|
|
|
44
53
|
const i18nAssetsPublicPathPrefix = '';
|
|
@@ -60,7 +69,8 @@ function configI18nNumericIndexPlugin(options) {
|
|
|
60
69
|
jsonpFunc: i18nOpts.jsonpFunc,
|
|
61
70
|
singleFile: i18nOpts.singleFile || false,
|
|
62
71
|
includeContentHash: finalIncludeContentHash,
|
|
63
|
-
generateManifest: i18nOpts.generateManifest || false
|
|
72
|
+
generateManifest: i18nOpts.generateManifest || false,
|
|
73
|
+
manifestPath: i18nOpts.manifestPath
|
|
64
74
|
};
|
|
65
75
|
const htmlInjectorOptions = {
|
|
66
76
|
numericFilenameTemplate: i18nOpts.numericFilenameTemplate,
|