@rushstack/localization-utilities 0.12.24 → 0.13.1
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/CHANGELOG.json +27 -0
- package/CHANGELOG.md +13 -1
- package/dist/localization-utilities.d.ts +27 -0
- package/dist/tsdoc-metadata.json +1 -1
- package/lib/TypingsGenerator.d.ts +28 -1
- package/lib/TypingsGenerator.d.ts.map +1 -1
- package/lib/TypingsGenerator.js +29 -3
- package/lib/TypingsGenerator.js.map +1 -1
- package/lib/parsers/parseLocJson.d.ts.map +1 -1
- package/lib/parsers/parseLocJson.js +8 -10
- package/lib/parsers/parseLocJson.js.map +1 -1
- package/lib/schemas/locJson.schema.json +15 -8
- package/package.json +5 -5
package/CHANGELOG.json
CHANGED
|
@@ -1,6 +1,33 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rushstack/localization-utilities",
|
|
3
3
|
"entries": [
|
|
4
|
+
{
|
|
5
|
+
"version": "0.13.1",
|
|
6
|
+
"tag": "@rushstack/localization-utilities_v0.13.1",
|
|
7
|
+
"date": "Sat, 01 Mar 2025 05:00:09 GMT",
|
|
8
|
+
"comments": {
|
|
9
|
+
"dependency": [
|
|
10
|
+
{
|
|
11
|
+
"comment": "Updating dependency \"@rushstack/typings-generator\" to `0.14.25`"
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"comment": "Updating dependency \"@rushstack/heft\" to `0.69.2`"
|
|
15
|
+
}
|
|
16
|
+
]
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"version": "0.13.0",
|
|
21
|
+
"tag": "@rushstack/localization-utilities_v0.13.0",
|
|
22
|
+
"date": "Thu, 27 Feb 2025 16:10:47 GMT",
|
|
23
|
+
"comments": {
|
|
24
|
+
"minor": [
|
|
25
|
+
{
|
|
26
|
+
"comment": "Update `loc.json` format to allow keys to be mapped to raw strings. This is useful so that the file name can be preserved for a strings file that can be directly imported at runtime."
|
|
27
|
+
}
|
|
28
|
+
]
|
|
29
|
+
}
|
|
30
|
+
},
|
|
4
31
|
{
|
|
5
32
|
"version": "0.12.24",
|
|
6
33
|
"tag": "@rushstack/localization-utilities_v0.12.24",
|
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
# Change Log - @rushstack/localization-utilities
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Sat, 01 Mar 2025 05:00:09 GMT and should not be manually modified.
|
|
4
|
+
|
|
5
|
+
## 0.13.1
|
|
6
|
+
Sat, 01 Mar 2025 05:00:09 GMT
|
|
7
|
+
|
|
8
|
+
_Version update only_
|
|
9
|
+
|
|
10
|
+
## 0.13.0
|
|
11
|
+
Thu, 27 Feb 2025 16:10:47 GMT
|
|
12
|
+
|
|
13
|
+
### Minor changes
|
|
14
|
+
|
|
15
|
+
- Update `loc.json` format to allow keys to be mapped to raw strings. This is useful so that the file name can be preserved for a strings file that can be directly imported at runtime.
|
|
4
16
|
|
|
5
17
|
## 0.12.24
|
|
6
18
|
Thu, 27 Feb 2025 01:10:39 GMT
|
|
@@ -105,10 +105,37 @@ export declare interface IPseudolocaleOptions {
|
|
|
105
105
|
* @public
|
|
106
106
|
*/
|
|
107
107
|
export declare interface ITypingsGeneratorOptions extends ITypingsGeneratorBaseOptions {
|
|
108
|
+
/**
|
|
109
|
+
* Options for configuring the default export.
|
|
110
|
+
*/
|
|
108
111
|
exportAsDefault?: boolean | IExportAsDefaultOptions | IInferInterfaceNameExportAsDefaultOptions;
|
|
112
|
+
/**
|
|
113
|
+
* Normalizes the line endings in .resx files to the specified kind.
|
|
114
|
+
*/
|
|
109
115
|
resxNewlineNormalization?: NewlineKind | undefined;
|
|
116
|
+
/**
|
|
117
|
+
* If specified, the generator will write trimmed .json files to the specified folders.
|
|
118
|
+
* The .json files will be written to the same relative path as the source file.
|
|
119
|
+
* For example, if the source file is "<root>/foo/bar.resx", and the output folder is "dist",
|
|
120
|
+
* the trimmed .json file will be written to "dist/foo/bar.resx.json".
|
|
121
|
+
*/
|
|
122
|
+
trimmedJsonOutputFolders?: string[] | undefined;
|
|
123
|
+
/**
|
|
124
|
+
* If true, .resx files will not throw errors if comments are missing.
|
|
125
|
+
*/
|
|
110
126
|
ignoreMissingResxComments?: boolean | undefined;
|
|
127
|
+
/**
|
|
128
|
+
* Optionally, provide a function that will be called for each string. If the function returns `true`
|
|
129
|
+
* the string will not be included.
|
|
130
|
+
*/
|
|
111
131
|
ignoreString?: IgnoreStringFunction;
|
|
132
|
+
/**
|
|
133
|
+
* Processes the raw text of a comment.
|
|
134
|
+
* @param comment - The original text of the comment to process
|
|
135
|
+
* @param relativeFilePath - The relative file path
|
|
136
|
+
* @param stringName - The name of the string that the comment is for
|
|
137
|
+
* @returns The processed comment
|
|
138
|
+
*/
|
|
112
139
|
processComment?: (comment: string | undefined, relativeFilePath: string, stringName: string) => string | undefined;
|
|
113
140
|
}
|
|
114
141
|
|
package/dist/tsdoc-metadata.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { StringValuesTypingsGenerator, type IExportAsDefaultOptions, type ITypingsGeneratorBaseOptions } from '@rushstack/typings-generator';
|
|
2
|
-
import type
|
|
2
|
+
import { type NewlineKind } from '@rushstack/node-core-library';
|
|
3
3
|
import type { IgnoreStringFunction } from './interfaces';
|
|
4
4
|
/**
|
|
5
5
|
* @public
|
|
@@ -15,10 +15,37 @@ export interface IInferInterfaceNameExportAsDefaultOptions extends Omit<IExportA
|
|
|
15
15
|
* @public
|
|
16
16
|
*/
|
|
17
17
|
export interface ITypingsGeneratorOptions extends ITypingsGeneratorBaseOptions {
|
|
18
|
+
/**
|
|
19
|
+
* Options for configuring the default export.
|
|
20
|
+
*/
|
|
18
21
|
exportAsDefault?: boolean | IExportAsDefaultOptions | IInferInterfaceNameExportAsDefaultOptions;
|
|
22
|
+
/**
|
|
23
|
+
* Normalizes the line endings in .resx files to the specified kind.
|
|
24
|
+
*/
|
|
19
25
|
resxNewlineNormalization?: NewlineKind | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* If specified, the generator will write trimmed .json files to the specified folders.
|
|
28
|
+
* The .json files will be written to the same relative path as the source file.
|
|
29
|
+
* For example, if the source file is "<root>/foo/bar.resx", and the output folder is "dist",
|
|
30
|
+
* the trimmed .json file will be written to "dist/foo/bar.resx.json".
|
|
31
|
+
*/
|
|
32
|
+
trimmedJsonOutputFolders?: string[] | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* If true, .resx files will not throw errors if comments are missing.
|
|
35
|
+
*/
|
|
20
36
|
ignoreMissingResxComments?: boolean | undefined;
|
|
37
|
+
/**
|
|
38
|
+
* Optionally, provide a function that will be called for each string. If the function returns `true`
|
|
39
|
+
* the string will not be included.
|
|
40
|
+
*/
|
|
21
41
|
ignoreString?: IgnoreStringFunction;
|
|
42
|
+
/**
|
|
43
|
+
* Processes the raw text of a comment.
|
|
44
|
+
* @param comment - The original text of the comment to process
|
|
45
|
+
* @param relativeFilePath - The relative file path
|
|
46
|
+
* @param stringName - The name of the string that the comment is for
|
|
47
|
+
* @returns The processed comment
|
|
48
|
+
*/
|
|
22
49
|
processComment?: (comment: string | undefined, relativeFilePath: string, stringName: string) => string | undefined;
|
|
23
50
|
}
|
|
24
51
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TypingsGenerator.d.ts","sourceRoot":"","sources":["../src/TypingsGenerator.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,4BAA4B,EAE5B,KAAK,uBAAuB,EAE5B,KAAK,4BAA4B,EAClC,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"TypingsGenerator.d.ts","sourceRoot":"","sources":["../src/TypingsGenerator.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,4BAA4B,EAE5B,KAAK,uBAAuB,EAE5B,KAAK,4BAA4B,EAClC,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAc,KAAK,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAE5E,OAAO,KAAK,EAAE,oBAAoB,EAAqB,MAAM,cAAc,CAAC;AAG5E;;GAEG;AACH,MAAM,WAAW,yCACf,SAAQ,IAAI,CAAC,uBAAuB,EAAE,eAAe,CAAC;IACtD;;;OAGG;IACH,8BAA8B,CAAC,EAAE,OAAO,CAAC;CAC1C;AAED;;GAEG;AACH,MAAM,WAAW,wBAAyB,SAAQ,4BAA4B;IAC5E;;OAEG;IACH,eAAe,CAAC,EAAE,OAAO,GAAG,uBAAuB,GAAG,yCAAyC,CAAC;IAEhG;;OAEG;IACH,wBAAwB,CAAC,EAAE,WAAW,GAAG,SAAS,CAAC;IAEnD;;;;;OAKG;IACH,wBAAwB,CAAC,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;IAEhD;;OAEG;IACH,yBAAyB,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAEhD;;;OAGG;IACH,YAAY,CAAC,EAAE,oBAAoB,CAAC;IAEpC;;;;;;OAMG;IACH,cAAc,CAAC,EAAE,CACf,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,gBAAgB,EAAE,MAAM,EACxB,UAAU,EAAE,MAAM,KACf,MAAM,GAAG,SAAS,CAAC;CACzB;AAED;;;;GAIG;AACH,qBAAa,gBAAiB,SAAQ,4BAA4B;gBAC7C,OAAO,EAAE,wBAAwB;CA4GrD"}
|
package/lib/TypingsGenerator.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
5
|
exports.TypingsGenerator = void 0;
|
|
6
6
|
const typings_generator_1 = require("@rushstack/typings-generator");
|
|
7
|
+
const node_core_library_1 = require("@rushstack/node-core-library");
|
|
7
8
|
const LocFileParser_1 = require("./LocFileParser");
|
|
8
9
|
/**
|
|
9
10
|
* This is a simple tool that generates .d.ts files for .loc.json, .resx.json, .resjson, and .resx files.
|
|
@@ -12,14 +13,28 @@ const LocFileParser_1 = require("./LocFileParser");
|
|
|
12
13
|
*/
|
|
13
14
|
class TypingsGenerator extends typings_generator_1.StringValuesTypingsGenerator {
|
|
14
15
|
constructor(options) {
|
|
15
|
-
const { ignoreString, processComment, resxNewlineNormalization, ignoreMissingResxComments, exportAsDefault } = options;
|
|
16
|
+
const { ignoreString, processComment, resxNewlineNormalization, ignoreMissingResxComments, trimmedJsonOutputFolders, exportAsDefault } = options;
|
|
16
17
|
const inferDefaultExportInterfaceNameFromFilename = typeof exportAsDefault === 'object'
|
|
17
18
|
? exportAsDefault.inferInterfaceNameFromFilename
|
|
18
19
|
: undefined;
|
|
20
|
+
const getJsonPaths = trimmedJsonOutputFolders && trimmedJsonOutputFolders.length > 0
|
|
21
|
+
? (relativePath) => {
|
|
22
|
+
const jsonRelativePath = relativePath.endsWith('.json') || relativePath.endsWith('.resjson')
|
|
23
|
+
? relativePath
|
|
24
|
+
: `${relativePath}.json`;
|
|
25
|
+
const jsonPaths = [];
|
|
26
|
+
for (const outputFolder of trimmedJsonOutputFolders) {
|
|
27
|
+
jsonPaths.push(`${outputFolder}/${jsonRelativePath}`);
|
|
28
|
+
}
|
|
29
|
+
return jsonPaths;
|
|
30
|
+
}
|
|
31
|
+
: undefined;
|
|
19
32
|
super({
|
|
20
33
|
...options,
|
|
21
34
|
fileExtensions: ['.resx', '.resx.json', '.loc.json', '.resjson'],
|
|
22
|
-
|
|
35
|
+
getAdditionalOutputFiles: getJsonPaths,
|
|
36
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
37
|
+
parseAndGenerateTypings: async (content, filePath, relativeFilePath) => {
|
|
23
38
|
const locFileData = (0, LocFileParser_1.parseLocFile)({
|
|
24
39
|
filePath,
|
|
25
40
|
content,
|
|
@@ -29,17 +44,28 @@ class TypingsGenerator extends typings_generator_1.StringValuesTypingsGenerator
|
|
|
29
44
|
ignoreString
|
|
30
45
|
});
|
|
31
46
|
const typings = [];
|
|
32
|
-
|
|
47
|
+
const json = trimmedJsonOutputFolders ? {} : undefined;
|
|
33
48
|
for (const [stringName, value] of Object.entries(locFileData)) {
|
|
34
49
|
let comment = value.comment;
|
|
35
50
|
if (processComment) {
|
|
36
51
|
comment = processComment(comment, relativeFilePath, stringName);
|
|
37
52
|
}
|
|
53
|
+
if (json) {
|
|
54
|
+
json[stringName] = value.value;
|
|
55
|
+
}
|
|
38
56
|
typings.push({
|
|
39
57
|
exportName: stringName,
|
|
40
58
|
comment
|
|
41
59
|
});
|
|
42
60
|
}
|
|
61
|
+
if (getJsonPaths) {
|
|
62
|
+
const jsonBuffer = Buffer.from(JSON.stringify(json), 'utf8');
|
|
63
|
+
for (const jsonFile of getJsonPaths(relativeFilePath)) {
|
|
64
|
+
await node_core_library_1.FileSystem.writeFileAsync(jsonFile, jsonBuffer, {
|
|
65
|
+
ensureFolderExists: true
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
43
69
|
if (inferDefaultExportInterfaceNameFromFilename) {
|
|
44
70
|
const lastSlashIndex = Math.max(filePath.lastIndexOf('/'), filePath.lastIndexOf('\\'));
|
|
45
71
|
let extensionIndex = filePath.lastIndexOf('.');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TypingsGenerator.js","sourceRoot":"","sources":["../src/TypingsGenerator.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAE3D,oEAMsC;
|
|
1
|
+
{"version":3,"file":"TypingsGenerator.js","sourceRoot":"","sources":["../src/TypingsGenerator.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAE3D,oEAMsC;AACtC,oEAA4E;AAG5E,mDAA+C;AA6D/C;;;;GAIG;AACH,MAAa,gBAAiB,SAAQ,gDAA4B;IAChE,YAAmB,OAAiC;QAClD,MAAM,EACJ,YAAY,EACZ,cAAc,EACd,wBAAwB,EACxB,yBAAyB,EACzB,wBAAwB,EACxB,eAAe,EAChB,GAAG,OAAO,CAAC;QACZ,MAAM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W,QAAQ,CAAC,SAAS,CAAC,cAAc,GAAG,CAAC,EAAE,cAAc,CAAC,CAAC;oBAChG,MAAM,kBAAkB,GAAW,wBAAwB,CAAC,OAAO,CAAC,iBAAiB,EAAE,EAAE,CAAC,CAAC;oBAC3F,MAAM,mBAAmB,GAAW,kBAAkB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;oBAC/E,IAAI,aAAa,GAAuB,IAAI,mBAAmB,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;oBAEhG,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC;wBAC7E,aAAa,IAAI,SAAS,CAAC;oBAC7B,CAAC;oBAED,OAAO;wBACL,OAAO;wBACP,eAAe,EAAE;4BACf,aAAa;yBACd;qBACF,CAAC;gBACJ,CAAC;qBAAM,CAAC;oBACN,OAAO;wBACL,OAAO;qBACR,CAAC;gBACJ,CAAC;YACH,CAAC;SACF,CAAC,CAAC;IACL,CAAC;CACF;AA7GD,4CA6GC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport {\n StringValuesTypingsGenerator,\n type IStringValueTypings,\n type IExportAsDefaultOptions,\n type IStringValueTyping,\n type ITypingsGeneratorBaseOptions\n} from '@rushstack/typings-generator';\nimport { FileSystem, type NewlineKind } from '@rushstack/node-core-library';\n\nimport type { IgnoreStringFunction, ILocalizationFile } from './interfaces';\nimport { parseLocFile } from './LocFileParser';\n\n/**\n * @public\n */\nexport interface IInferInterfaceNameExportAsDefaultOptions\n extends Omit<IExportAsDefaultOptions, 'interfaceName'> {\n /**\n * When `exportAsDefault` is true and this option is true, the default export interface name will be inferred\n * from the filename.\n */\n inferInterfaceNameFromFilename?: boolean;\n}\n\n/**\n * @public\n */\nexport interface ITypingsGeneratorOptions extends ITypingsGeneratorBaseOptions {\n /**\n * Options for configuring the default export.\n */\n exportAsDefault?: boolean | IExportAsDefaultOptions | IInferInterfaceNameExportAsDefaultOptions;\n\n /**\n * Normalizes the line endings in .resx files to the specified kind.\n */\n resxNewlineNormalization?: NewlineKind | undefined;\n\n /**\n * If specified, the generator will write trimmed .json files to the specified folders.\n * The .json files will be written to the same relative path as the source file.\n * For example, if the source file is \"<root>/foo/bar.resx\", and the output folder is \"dist\",\n * the trimmed .json file will be written to \"dist/foo/bar.resx.json\".\n */\n trimmedJsonOutputFolders?: string[] | undefined;\n\n /**\n * If true, .resx files will not throw errors if comments are missing.\n */\n ignoreMissingResxComments?: boolean | undefined;\n\n /**\n * Optionally, provide a function that will be called for each string. If the function returns `true`\n * the string will not be included.\n */\n ignoreString?: IgnoreStringFunction;\n\n /**\n * Processes the raw text of a comment.\n * @param comment - The original text of the comment to process\n * @param relativeFilePath - The relative file path\n * @param stringName - The name of the string that the comment is for\n * @returns The processed comment\n */\n processComment?: (\n comment: string | undefined,\n relativeFilePath: string,\n stringName: string\n ) => string | undefined;\n}\n\n/**\n * This is a simple tool that generates .d.ts files for .loc.json, .resx.json, .resjson, and .resx files.\n *\n * @public\n */\nexport class TypingsGenerator extends StringValuesTypingsGenerator {\n public constructor(options: ITypingsGeneratorOptions) {\n const {\n ignoreString,\n processComment,\n resxNewlineNormalization,\n ignoreMissingResxComments,\n trimmedJsonOutputFolders,\n exportAsDefault\n } = options;\n const inferDefaultExportInterfaceNameFromFilename: boolean | undefined =\n typeof exportAsDefault === 'object'\n ? (exportAsDefault as IInferInterfaceNameExportAsDefaultOptions).inferInterfaceNameFromFilename\n : undefined;\n\n const getJsonPaths: ((relativePath: string) => string[]) | undefined =\n trimmedJsonOutputFolders && trimmedJsonOutputFolders.length > 0\n ? (relativePath: string): string[] => {\n const jsonRelativePath: string =\n relativePath.endsWith('.json') || relativePath.endsWith('.resjson')\n ? relativePath\n : `${relativePath}.json`;\n\n const jsonPaths: string[] = [];\n for (const outputFolder of trimmedJsonOutputFolders) {\n jsonPaths.push(`${outputFolder}/${jsonRelativePath}`);\n }\n return jsonPaths;\n }\n : undefined;\n\n super({\n ...options,\n fileExtensions: ['.resx', '.resx.json', '.loc.json', '.resjson'],\n getAdditionalOutputFiles: getJsonPaths,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n parseAndGenerateTypings: async (\n content: string,\n filePath: string,\n relativeFilePath: string\n ): Promise<IStringValueTypings> => {\n const locFileData: ILocalizationFile = parseLocFile({\n filePath,\n content,\n terminal: this.terminal,\n resxNewlineNormalization,\n ignoreMissingResxComments,\n ignoreString\n });\n\n const typings: IStringValueTyping[] = [];\n\n const json: Record<string, string> | undefined = trimmedJsonOutputFolders ? {} : undefined;\n\n for (const [stringName, value] of Object.entries(locFileData)) {\n let comment: string | undefined = value.comment;\n if (processComment) {\n comment = processComment(comment, relativeFilePath, stringName);\n }\n\n if (json) {\n json[stringName] = value.value;\n }\n\n typings.push({\n exportName: stringName,\n comment\n });\n }\n\n if (getJsonPaths) {\n const jsonBuffer: Buffer = Buffer.from(JSON.stringify(json), 'utf8');\n for (const jsonFile of getJsonPaths(relativeFilePath)) {\n await FileSystem.writeFileAsync(jsonFile, jsonBuffer, {\n ensureFolderExists: true\n });\n }\n }\n\n if (inferDefaultExportInterfaceNameFromFilename) {\n const lastSlashIndex: number = Math.max(filePath.lastIndexOf('/'), filePath.lastIndexOf('\\\\'));\n let extensionIndex: number = filePath.lastIndexOf('.');\n if (filePath.slice(extensionIndex).toLowerCase() === '.json') {\n extensionIndex = filePath.lastIndexOf('.', extensionIndex - 1);\n }\n\n const fileNameWithoutExtension: string = filePath.substring(lastSlashIndex + 1, extensionIndex);\n const normalizedFileName: string = fileNameWithoutExtension.replace(/[^a-zA-Z0-9$_]/g, '');\n const firstCharUpperCased: string = normalizedFileName.charAt(0).toUpperCase();\n let interfaceName: string | undefined = `I${firstCharUpperCased}${normalizedFileName.slice(1)}`;\n\n if (!interfaceName.endsWith('strings') && !interfaceName.endsWith('Strings')) {\n interfaceName += 'Strings';\n }\n\n return {\n typings,\n exportAsDefault: {\n interfaceName\n }\n };\n } else {\n return {\n typings\n };\n }\n }\n });\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseLocJson.d.ts","sourceRoot":"","sources":["../../src/parsers/parseLocJson.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAK1E;;GAEG;AACH,wBAAgB,YAAY,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,EAAE,iBAAiB,GAAG,iBAAiB,
|
|
1
|
+
{"version":3,"file":"parseLocJson.d.ts","sourceRoot":"","sources":["../../src/parsers/parseLocJson.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAK1E;;GAEG;AACH,wBAAgB,YAAY,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,EAAE,iBAAiB,GAAG,iBAAiB,CAmBtG"}
|
|
@@ -20,18 +20,16 @@ function parseLocJson({ content, filePath, ignoreString }) {
|
|
|
20
20
|
catch (e) {
|
|
21
21
|
throw new Error(`The loc file is invalid. Error: ${e}`);
|
|
22
22
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
23
|
+
// Normalize file shape and possibly filter
|
|
24
|
+
const newParsedFile = {};
|
|
25
|
+
for (const [key, stringData] of Object.entries(parsedFile)) {
|
|
26
|
+
if (!(ignoreString === null || ignoreString === void 0 ? void 0 : ignoreString(filePath, key))) {
|
|
27
|
+
// Normalize entry shape. We allow the values to be plain strings as a format that can be handed
|
|
28
|
+
// off to webpack builds that don't understand the comment syntax.
|
|
29
|
+
newParsedFile[key] = typeof stringData === 'string' ? { value: stringData } : stringData;
|
|
29
30
|
}
|
|
30
|
-
return newParsedFile;
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
return parsedFile;
|
|
34
31
|
}
|
|
32
|
+
return newParsedFile;
|
|
35
33
|
}
|
|
36
34
|
exports.parseLocJson = parseLocJson;
|
|
37
35
|
//# sourceMappingURL=parseLocJson.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseLocJson.js","sourceRoot":"","sources":["../../src/parsers/parseLocJson.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;AAE3D,oEAAoE;AAGpE,yFAA2D;AAE3D,MAAM,eAAe,GAAe,8BAAU,CAAC,gBAAgB,CAAC,6BAAa,CAAC,CAAC;AAE/E;;GAEG;AACH,SAAgB,YAAY,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAqB;IACjF,MAAM,UAAU,GAAsB,4BAAQ,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IACpE,IAAI,CAAC;QACH,eAAe,CAAC,cAAc,CAAC,UAAU,EAAE,QAAQ,EAAE,EAAE,iBAAiB,EAAE,IAAI,EAAE,CAAC,CAAC;IACpF,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,EAAE,CAAC,CAAC;IAC1D,CAAC;IAED,
|
|
1
|
+
{"version":3,"file":"parseLocJson.js","sourceRoot":"","sources":["../../src/parsers/parseLocJson.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;AAE3D,oEAAoE;AAGpE,yFAA2D;AAE3D,MAAM,eAAe,GAAe,8BAAU,CAAC,gBAAgB,CAAC,6BAAa,CAAC,CAAC;AAE/E;;GAEG;AACH,SAAgB,YAAY,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAqB;IACjF,MAAM,UAAU,GAAsB,4BAAQ,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IACpE,IAAI,CAAC;QACH,eAAe,CAAC,cAAc,CAAC,UAAU,EAAE,QAAQ,EAAE,EAAE,iBAAiB,EAAE,IAAI,EAAE,CAAC,CAAC;IACpF,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,EAAE,CAAC,CAAC;IAC1D,CAAC;IAED,2CAA2C;IAC3C,MAAM,aAAa,GAAsB,EAAE,CAAC;IAC5C,KAAK,MAAM,CAAC,GAAG,EAAE,UAAU,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;QAC3D,IAAI,CAAC,CAAA,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAG,QAAQ,EAAE,GAAG,CAAC,CAAA,EAAE,CAAC;YACnC,gGAAgG;YAChG,kEAAkE;YAClE,aAAa,CAAC,GAAG,CAAC,GAAG,OAAO,UAAU,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC;QAC3F,CAAC;IACH,CAAC;IAED,OAAO,aAAa,CAAC;AACvB,CAAC;AAnBD,oCAmBC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport { JsonFile, JsonSchema } from '@rushstack/node-core-library';\n\nimport type { ILocalizationFile, IParseFileOptions } from '../interfaces';\nimport locJsonSchema from '../schemas/locJson.schema.json';\n\nconst LOC_JSON_SCHEMA: JsonSchema = JsonSchema.fromLoadedObject(locJsonSchema);\n\n/**\n * @public\n */\nexport function parseLocJson({ content, filePath, ignoreString }: IParseFileOptions): ILocalizationFile {\n const parsedFile: ILocalizationFile = JsonFile.parseString(content);\n try {\n LOC_JSON_SCHEMA.validateObject(parsedFile, filePath, { ignoreSchemaField: true });\n } catch (e) {\n throw new Error(`The loc file is invalid. Error: ${e}`);\n }\n\n // Normalize file shape and possibly filter\n const newParsedFile: ILocalizationFile = {};\n for (const [key, stringData] of Object.entries(parsedFile)) {\n if (!ignoreString?.(filePath, key)) {\n // Normalize entry shape. We allow the values to be plain strings as a format that can be handed\n // off to webpack builds that don't understand the comment syntax.\n newParsedFile[key] = typeof stringData === 'string' ? { value: stringData } : stringData;\n }\n }\n\n return newParsedFile;\n}\n"]}
|
|
@@ -4,17 +4,24 @@
|
|
|
4
4
|
|
|
5
5
|
"patternProperties": {
|
|
6
6
|
"^[A-Za-z_$][0-9A-Za-z_$]*$": {
|
|
7
|
-
"
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
"
|
|
7
|
+
"oneOf": [
|
|
8
|
+
{
|
|
9
|
+
"type": "object",
|
|
10
|
+
"properties": {
|
|
11
|
+
"value": {
|
|
12
|
+
"type": "string"
|
|
13
|
+
},
|
|
14
|
+
"comment": {
|
|
15
|
+
"type": "string"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"additionalProperties": false,
|
|
19
|
+
"required": ["value"]
|
|
11
20
|
},
|
|
12
|
-
|
|
21
|
+
{
|
|
13
22
|
"type": "string"
|
|
14
23
|
}
|
|
15
|
-
|
|
16
|
-
"additionalProperties": false,
|
|
17
|
-
"required": ["value"]
|
|
24
|
+
]
|
|
18
25
|
}
|
|
19
26
|
},
|
|
20
27
|
"additionalProperties": false,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rushstack/localization-utilities",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.1",
|
|
4
4
|
"description": "This plugin contains some useful functions for localization.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "dist/localization-utilities.d.ts",
|
|
@@ -14,13 +14,13 @@
|
|
|
14
14
|
"pseudolocale": "~1.1.0",
|
|
15
15
|
"xmldoc": "~1.1.2",
|
|
16
16
|
"@rushstack/node-core-library": "5.11.0",
|
|
17
|
-
"@rushstack/
|
|
18
|
-
"@rushstack/
|
|
17
|
+
"@rushstack/terminal": "0.15.0",
|
|
18
|
+
"@rushstack/typings-generator": "0.14.25"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"@types/xmldoc": "1.1.4",
|
|
22
|
-
"
|
|
23
|
-
"
|
|
22
|
+
"@rushstack/heft": "0.69.2",
|
|
23
|
+
"local-node-rig": "1.0.0"
|
|
24
24
|
},
|
|
25
25
|
"scripts": {
|
|
26
26
|
"build": "heft build --clean",
|