@oracle/oraclejet-icu-l10n 17.0.1 → 17.0.3
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/Bundler.d.ts +8 -6
- package/Bundler.js +5 -4
- package/l10nBundleBuilder.js +1 -1
- package/package.json +1 -1
- package/test/{l10nTest.js → l10nTest.ts} +53 -39
- package/tsconfig.json +3 -0
package/Bundler.d.ts
CHANGED
|
@@ -10,13 +10,14 @@
|
|
|
10
10
|
* @param {string} props.rootDir The path to the root message bundle
|
|
11
11
|
* @param {string} props.bundleName The name of the bundle file
|
|
12
12
|
* @param {string} props.locale The locale of the root message bundle
|
|
13
|
-
* @param {string} props.outDir The
|
|
14
|
-
* @param {
|
|
15
|
-
*
|
|
13
|
+
* @param {string} props.outDir The output directory where the built bundle will be written
|
|
14
|
+
* @param {('amd'|'cjs'|'esm'|'legacy-amd')=} props.module The type of module to produce -- 'amd', 'cjs', 'esm', or 'legacy-amd'.
|
|
15
|
+
* If not supplied, the Typscript will not be transpiled.
|
|
16
|
+
* @param {('default'|'named')=} props.exportType The type of export to produce -- 'default' or 'named'
|
|
16
17
|
* @param {boolean=} props.override Indicates the bundle is an override, and only the root
|
|
17
18
|
* locale and those explicitly stated in [--supportedLocales] will be built.
|
|
18
19
|
* @param {string[]=} props.additionalLocales An array of additional locales to build
|
|
19
|
-
* @param {string=} hooks A path to the custom hooks file
|
|
20
|
+
* @param {string=} props.hooks A path to the custom hooks file
|
|
20
21
|
*/
|
|
21
22
|
export function build({
|
|
22
23
|
rootDir,
|
|
@@ -33,10 +34,11 @@ export function build({
|
|
|
33
34
|
bundleName: string;
|
|
34
35
|
locale: string;
|
|
35
36
|
outDir: string;
|
|
36
|
-
module?:
|
|
37
|
-
exportType?:
|
|
37
|
+
module?: ('amd' | 'cjs' | 'esm' | 'legacy-amd') | undefined;
|
|
38
|
+
exportType?: ('default' | 'named') | undefined;
|
|
38
39
|
override?: boolean | undefined;
|
|
39
40
|
additionalLocales?: string[] | undefined;
|
|
41
|
+
hooks?: string | undefined;
|
|
40
42
|
}): void;
|
|
41
43
|
/**
|
|
42
44
|
* Test if a given directory name (base name only) is an NLS directory.
|
package/Bundler.js
CHANGED
|
@@ -209,13 +209,14 @@ let customHooks = {};
|
|
|
209
209
|
* @param {string} props.rootDir The path to the root message bundle
|
|
210
210
|
* @param {string} props.bundleName The name of the bundle file
|
|
211
211
|
* @param {string} props.locale The locale of the root message bundle
|
|
212
|
-
* @param {string} props.outDir The
|
|
213
|
-
* @param {
|
|
214
|
-
*
|
|
212
|
+
* @param {string} props.outDir The output directory where the built bundle will be written
|
|
213
|
+
* @param {('amd'|'cjs'|'esm'|'legacy-amd')=} props.module The type of module to produce -- 'amd', 'cjs', 'esm', or 'legacy-amd'.
|
|
214
|
+
* If not supplied, the Typscript will not be transpiled.
|
|
215
|
+
* @param {('default'|'named')=} props.exportType The type of export to produce -- 'default' or 'named'
|
|
215
216
|
* @param {boolean=} props.override Indicates the bundle is an override, and only the root
|
|
216
217
|
* locale and those explicitly stated in [--supportedLocales] will be built.
|
|
217
218
|
* @param {string[]=} props.additionalLocales An array of additional locales to build
|
|
218
|
-
* @param {string=} hooks A path to the custom hooks file
|
|
219
|
+
* @param {string=} props.hooks A path to the custom hooks file
|
|
219
220
|
*/
|
|
220
221
|
function build({
|
|
221
222
|
rootDir,
|
package/l10nBundleBuilder.js
CHANGED
|
@@ -29,7 +29,7 @@ if ('rootDir' in argsMap && 'bundleName' in argsMap && 'locale' in argsMap && 'o
|
|
|
29
29
|
--locale\tThe root bundle's locale
|
|
30
30
|
--outDir\tThe output directory where the built bundle will be written
|
|
31
31
|
Optional:
|
|
32
|
-
--module\
|
|
32
|
+
--module\tThe type of module to produce -- 'amd', 'cjs', 'esm', or 'legacy-amd'. If not supplied, the Typscript will not be transpiled.
|
|
33
33
|
--exportType\tThe type of export, either 'named' or 'default' (default='default')
|
|
34
34
|
--hooks\tThe hooks file to use (see example)
|
|
35
35
|
--override\tIndicates the bundle is an override, and only the root locale and
|
package/package.json
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
import assert from 'node:assert';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { build, isNlsDir } from '../Bundler';
|
|
5
|
+
import fsx from 'fs-extra';
|
|
6
|
+
import vm from 'node:vm';
|
|
7
|
+
import glob from 'glob';
|
|
8
8
|
|
|
9
9
|
const rootDir = path.join(__dirname, 'resources/nls');
|
|
10
10
|
const outputRoot = path.resolve(__dirname, 'built');
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
type ExportType = 'default' | 'named';
|
|
13
|
+
|
|
14
|
+
function runTestCases(extractBundle: (bundle: string) => any) {
|
|
13
15
|
describe('Bundle files', () => {
|
|
14
16
|
it('creates the root bundle in English', () => {
|
|
15
17
|
const bundle = extractBundle(`app-strings.js`);
|
|
@@ -190,27 +192,32 @@ function runTestCases(extractBundle) {
|
|
|
190
192
|
bundleName: 'app-strings-bad-root.json',
|
|
191
193
|
outDir: path.join(outputRoot, 'nls-bad-metadata')
|
|
192
194
|
});
|
|
193
|
-
} catch (ex) {
|
|
195
|
+
} catch (ex: any) {
|
|
194
196
|
didFail = !!ex.message.match(/While processing ro-MD\/app-strings-bad-root.json/);
|
|
195
197
|
}
|
|
196
198
|
assert(didFail === true);
|
|
197
|
-
})
|
|
199
|
+
});
|
|
198
200
|
|
|
199
201
|
it('metadata keys should not be in bundle', () => {
|
|
200
|
-
assert.strictEqual(
|
|
202
|
+
assert.strictEqual(
|
|
203
|
+
Object.keys(bundle).every((k) => !k.startsWith('@')),
|
|
204
|
+
true
|
|
205
|
+
);
|
|
201
206
|
});
|
|
202
207
|
|
|
203
208
|
it('metadata parameters present in locale bundle', () => {
|
|
204
209
|
const birthDate = '2022-09-29 07:25 GMT';
|
|
205
|
-
assert.equal(
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
210
|
+
assert.equal(
|
|
211
|
+
bundle.localeParams({
|
|
212
|
+
total: 1,
|
|
213
|
+
gender: 'male',
|
|
214
|
+
title: 'Mr.',
|
|
215
|
+
birthDate
|
|
216
|
+
}),
|
|
217
|
+
'Moldavian total: 1 unu, gender: male, title: Mr., birthDate: 29.09.2022'
|
|
218
|
+
);
|
|
211
219
|
});
|
|
212
220
|
});
|
|
213
|
-
|
|
214
221
|
}
|
|
215
222
|
|
|
216
223
|
describe('Custom hooks', () => {
|
|
@@ -258,8 +265,8 @@ describe('Custom hooks', () => {
|
|
|
258
265
|
* @param {string} outDir
|
|
259
266
|
* @param {string} filePath
|
|
260
267
|
*/
|
|
261
|
-
function extractCjsBundle(outDir,
|
|
262
|
-
return require(path.join(outDir,
|
|
268
|
+
function extractCjsBundle(outDir: string, filePath: string) {
|
|
269
|
+
return require(path.join(outDir, filePath));
|
|
263
270
|
}
|
|
264
271
|
|
|
265
272
|
describe('CJS default export', () => {
|
|
@@ -281,13 +288,14 @@ describe('AMD', () => {
|
|
|
281
288
|
/**
|
|
282
289
|
* Read contents of ES6 file and convert to CommonJS export for Node testing
|
|
283
290
|
* @param {string} filepath
|
|
291
|
+
* @param {ExportType} exportType
|
|
284
292
|
*/
|
|
285
|
-
function extractBundle(filepath, exportType) {
|
|
293
|
+
function extractBundle(filepath: string, exportType: ExportType) {
|
|
286
294
|
const bundleContents = fsx.readFileSync(filepath).toString();
|
|
287
295
|
// Create a 'define' method in the context which returns the object passed in
|
|
288
296
|
const script = new vm.Script(bundleContents, '');
|
|
289
297
|
const context = vm.createContext({
|
|
290
|
-
define: function (rb) {
|
|
298
|
+
define: function (rb: any) {
|
|
291
299
|
// define({ ... })
|
|
292
300
|
if (arguments.length === 1) {
|
|
293
301
|
return rb;
|
|
@@ -306,7 +314,11 @@ describe('AMD', () => {
|
|
|
306
314
|
return rb;
|
|
307
315
|
}
|
|
308
316
|
|
|
309
|
-
|
|
317
|
+
/**
|
|
318
|
+
*
|
|
319
|
+
* @param {ExportType} exportType
|
|
320
|
+
*/
|
|
321
|
+
function testAmd(exportType: ExportType) {
|
|
310
322
|
const outDir = path.resolve(outputRoot, `amd-${exportType}`);
|
|
311
323
|
|
|
312
324
|
fsx.removeSync(outDir);
|
|
@@ -349,10 +361,7 @@ describe('AMD', () => {
|
|
|
349
361
|
});
|
|
350
362
|
|
|
351
363
|
it('creates non-standard keys', () => {
|
|
352
|
-
const bundle = extractBundle(
|
|
353
|
-
path.join(outDir, 'app-strings-legacy-keys.js'),
|
|
354
|
-
'named'
|
|
355
|
-
);
|
|
364
|
+
const bundle = extractBundle(path.join(outDir, 'app-strings-legacy-keys.js'), 'named');
|
|
356
365
|
expect(bundle['dot.key']()).toEqual('Dot key');
|
|
357
366
|
expect(bundle['.leading.dot.key']()).toEqual('Leading dot key');
|
|
358
367
|
expect(bundle['dash-key']()).toEqual('Dash key');
|
|
@@ -377,7 +386,7 @@ describe('Extra locales', () => {
|
|
|
377
386
|
additionalLocales
|
|
378
387
|
});
|
|
379
388
|
|
|
380
|
-
const extractBundle = (fp) => extractCjsBundle(outDir, fp).default;
|
|
389
|
+
const extractBundle = (fp: string) => extractCjsBundle(outDir, fp).default;
|
|
381
390
|
runTestCases(extractBundle);
|
|
382
391
|
|
|
383
392
|
it('creates the de bundle in English', () => {
|
|
@@ -403,7 +412,7 @@ describe('Extra locales', () => {
|
|
|
403
412
|
|
|
404
413
|
describe('Override files', () => {
|
|
405
414
|
const outDir = path.resolve(outputRoot, 'override');
|
|
406
|
-
const extractBundle = (fp) => extractCjsBundle(outDir, fp).default;
|
|
415
|
+
const extractBundle = (fp: string) => extractCjsBundle(outDir, fp).default;
|
|
407
416
|
|
|
408
417
|
describe('with root overrides', () => {
|
|
409
418
|
build({
|
|
@@ -430,9 +439,11 @@ describe('Override files', () => {
|
|
|
430
439
|
|
|
431
440
|
it('creates the ru-RU override bundle in Russian', () => {
|
|
432
441
|
const bundle = extractBundle(`ru-RU/app-strings-x.js`);
|
|
433
|
-
assert.equal(Object.keys(bundle).length, 2,
|
|
442
|
+
assert.equal(Object.keys(bundle).length, 2, 'override should have root keys');
|
|
434
443
|
assert.equal(
|
|
435
|
-
bundle.contentArea({ name: 'Dashboard' }),
|
|
444
|
+
bundle.contentArea({ name: 'Dashboard' }),
|
|
445
|
+
'Dashboard ru-RU contentArea override'
|
|
446
|
+
);
|
|
436
447
|
assert.equal(bundle.pageIntro(), 'root pageIntro');
|
|
437
448
|
});
|
|
438
449
|
|
|
@@ -455,6 +466,7 @@ describe('Override files', () => {
|
|
|
455
466
|
rootDir,
|
|
456
467
|
bundleName: 'extra-app-strings-x.json',
|
|
457
468
|
override: true,
|
|
469
|
+
locale: 'en-US',
|
|
458
470
|
additionalLocales: ['zh-Hans'],
|
|
459
471
|
outDir,
|
|
460
472
|
module: 'cjs'
|
|
@@ -465,13 +477,14 @@ describe('Override files', () => {
|
|
|
465
477
|
expect(generatedFiles.length).toEqual(1);
|
|
466
478
|
|
|
467
479
|
const bundle = extractBundle('zh-Hans/extra-app-strings-x.js');
|
|
468
|
-
assert.equal(Object.keys(bundle).length, 1,
|
|
480
|
+
assert.equal(Object.keys(bundle).length, 1, 'override should not have root keys');
|
|
469
481
|
assert.equal(
|
|
470
|
-
bundle.contentArea({ name: 'Dashboard' }),
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
})
|
|
482
|
+
bundle.contentArea({ name: 'Dashboard' }),
|
|
483
|
+
'Dashboard zh-Hans contentArea override'
|
|
484
|
+
);
|
|
485
|
+
});
|
|
486
|
+
});
|
|
487
|
+
});
|
|
475
488
|
|
|
476
489
|
describe('extra keys', () => {
|
|
477
490
|
const outDir = path.resolve(outputRoot, 'extra-keys');
|
|
@@ -482,11 +495,12 @@ describe('extra keys', () => {
|
|
|
482
495
|
build({
|
|
483
496
|
rootDir: `${rootDir}-extra-keys`,
|
|
484
497
|
bundleName: 'app-bundle-bad.json',
|
|
498
|
+
locale: 'en-US',
|
|
485
499
|
outDir
|
|
486
500
|
});
|
|
487
|
-
} catch (ex) {
|
|
501
|
+
} catch (ex: any) {
|
|
488
502
|
didFail = ex.message.indexOf('description') >= 0;
|
|
489
503
|
}
|
|
490
504
|
expect(didFail).toBeTruthy();
|
|
491
|
-
})
|
|
492
|
-
})
|
|
505
|
+
});
|
|
506
|
+
});
|