@rushstack/webpack4-localization-plugin 0.14.5

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.
Files changed (53) hide show
  1. package/LICENSE +24 -0
  2. package/README.md +292 -0
  3. package/dist/tsdoc-metadata.json +11 -0
  4. package/dist/webpack4-localization-plugin.d.ts +324 -0
  5. package/lib/AssetProcessor.d.ts +36 -0
  6. package/lib/AssetProcessor.d.ts.map +1 -0
  7. package/lib/AssetProcessor.js +306 -0
  8. package/lib/AssetProcessor.js.map +1 -0
  9. package/lib/LocalizationPlugin.d.ts +77 -0
  10. package/lib/LocalizationPlugin.d.ts.map +1 -0
  11. package/lib/LocalizationPlugin.js +597 -0
  12. package/lib/LocalizationPlugin.js.map +1 -0
  13. package/lib/WebpackConfigurationUpdater.d.ts +22 -0
  14. package/lib/WebpackConfigurationUpdater.d.ts.map +1 -0
  15. package/lib/WebpackConfigurationUpdater.js +136 -0
  16. package/lib/WebpackConfigurationUpdater.js.map +1 -0
  17. package/lib/index.d.ts +4 -0
  18. package/lib/index.d.ts.map +1 -0
  19. package/lib/index.js +8 -0
  20. package/lib/index.js.map +1 -0
  21. package/lib/interfaces.d.ts +219 -0
  22. package/lib/interfaces.d.ts.map +1 -0
  23. package/lib/interfaces.js +5 -0
  24. package/lib/interfaces.js.map +1 -0
  25. package/lib/loaders/InPlaceLocFileLoader.d.ts +4 -0
  26. package/lib/loaders/InPlaceLocFileLoader.d.ts.map +1 -0
  27. package/lib/loaders/InPlaceLocFileLoader.js +17 -0
  28. package/lib/loaders/InPlaceLocFileLoader.js.map +1 -0
  29. package/lib/loaders/LoaderFactory.d.ts +13 -0
  30. package/lib/loaders/LoaderFactory.d.ts.map +1 -0
  31. package/lib/loaders/LoaderFactory.js +41 -0
  32. package/lib/loaders/LoaderFactory.js.map +1 -0
  33. package/lib/loaders/LocLoader.d.ts +9 -0
  34. package/lib/loaders/LocLoader.d.ts.map +1 -0
  35. package/lib/loaders/LocLoader.js +36 -0
  36. package/lib/loaders/LocLoader.js.map +1 -0
  37. package/lib/utilities/Constants.d.ts +14 -0
  38. package/lib/utilities/Constants.d.ts.map +1 -0
  39. package/lib/utilities/Constants.js +44 -0
  40. package/lib/utilities/Constants.js.map +1 -0
  41. package/lib/utilities/EntityMarker.d.ts +13 -0
  42. package/lib/utilities/EntityMarker.d.ts.map +1 -0
  43. package/lib/utilities/EntityMarker.js +19 -0
  44. package/lib/utilities/EntityMarker.js.map +1 -0
  45. package/lib/utilities/LoaderTerminalProvider.d.ts +6 -0
  46. package/lib/utilities/LoaderTerminalProvider.d.ts.map +1 -0
  47. package/lib/utilities/LoaderTerminalProvider.js +28 -0
  48. package/lib/utilities/LoaderTerminalProvider.js.map +1 -0
  49. package/lib/webpackInterfaces.d.ts +10 -0
  50. package/lib/webpackInterfaces.d.ts.map +1 -0
  51. package/lib/webpackInterfaces.js +5 -0
  52. package/lib/webpackInterfaces.js.map +1 -0
  53. package/package.json +51 -0
package/LICENSE ADDED
@@ -0,0 +1,24 @@
1
+ @rushstack/webpack4-localization-plugin
2
+
3
+ Copyright (c) Microsoft Corporation. All rights reserved.
4
+
5
+ MIT License
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining
8
+ a copy of this software and associated documentation files (the
9
+ "Software"), to deal in the Software without restriction, including
10
+ without limitation the rights to use, copy, modify, merge, publish,
11
+ distribute, sublicense, and/or sell copies of the Software, and to
12
+ permit persons to whom the Software is furnished to do so, subject to
13
+ the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be
16
+ included in all copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,292 @@
1
+ # @rushstack/webpack4-localization-plugin
2
+
3
+ ## Installation
4
+
5
+ `npm install @rushstack/webpack4-localization-plugin --save-dev`
6
+
7
+ ## Overview
8
+
9
+ This Webpack plugin produces bundles that have multiple locales' variants of strings embedded. It also
10
+ has out-of-box support for RESX files in addition to JSON strings files (with the extension `.loc.json`), including
11
+ support for generating typings.
12
+
13
+ ### Example Plugin Usage
14
+
15
+ There are three example projects in this repository that make use of this plugin:
16
+
17
+ - [Project 1](https://github.com/microsoft/rushstack/tree/main/build-tests/localization-plugin-test-01)
18
+ - This project contains two webpack entrypoints (one with an async chunk, one without), without any localized
19
+ resources
20
+ - The output is a single, non-localized variant
21
+ - [Project 2](https://github.com/microsoft/rushstack/tree/main/build-tests/localization-plugin-test-02)
22
+ - This project contains three webpack entrypoints:
23
+ - [`indexA.ts`](https://github.com/microsoft/rushstack/tree/main/build-tests/localization-plugin-test-02/src/indexA.ts)
24
+ directly references two `.loc.json` files and one `.resx` file, and dynamically imports an async chunk with
25
+ localized data, and an async chunk without localized data
26
+ - [`indexB.ts`](https://github.com/microsoft/rushstack/tree/main/build-tests/localization-plugin-test-02/src/indexB.ts)
27
+ directly references two `.loc.json` files
28
+ - [`indexC.ts`](https://github.com/microsoft/rushstack/tree/main/build-tests/localization-plugin-test-02/src/indexC.ts)
29
+ directly references no localized resources, and dynamically imports an async chunk without localized data
30
+ - The webpack config contains and references Spanish translations for most of the English strings in the resource files
31
+ - The output contains English, Spanish, and "passthrough" localized variants of files that contain
32
+ localized data, and a non-localized variant of the files that do not contain localized data
33
+ - [Project 3](https://github.com/microsoft/rushstack/tree/main/build-tests/localization-plugin-test-03)
34
+ - This project contains four webpack entrypoints:
35
+ - [`indexA.ts`](https://github.com/microsoft/rushstack/tree/main/build-tests/localization-plugin-test-03/src/indexA.ts)
36
+ directly references one `.loc.json` file, one `.resx.json` file, one `.resx` file, and one `.resjson` file, and dynamically imports an async chunk with
37
+ localized data, and an async chunk without localized data
38
+ - [`indexB.ts`](https://github.com/microsoft/rushstack/tree/main/build-tests/localization-plugin-test-03/src/indexB.ts)
39
+ directly references one `.loc.json` file and one `.resx.json` file
40
+ - [`indexC.ts`](https://github.com/microsoft/rushstack/tree/main/build-tests/localization-plugin-test-03/src/indexC.ts)
41
+ directly references no localized resources, and dynamically imports an async chunk with localized data
42
+ - [`indexD.ts`](https://github.com/microsoft/rushstack/tree/main/build-tests/localization-plugin-test-03/src/indexD.ts)
43
+ directly references no localized resources, and dynamically imports an async chunk without localized data
44
+ - The webpack config contains or references Spanish translations for some of the English strings in the resource files
45
+ - The output contains English, Spanish, "passthrough," and two pseudo-localized variants of files that contain
46
+ localized data, and a non-localized variant of the files that do not contain localized data
47
+
48
+ ### `.resx` vs `.loc.json` vs `.resjson`
49
+
50
+ [`.resx`](https://docs.microsoft.com/en-us/dotnet/framework/resources/creating-resource-files-for-desktop-apps#resources-in-resx-files)
51
+ is an XML format for resource data. It is primarily used in .NET development, and it is supported by
52
+ some translation services. See an example of a `.resx` file
53
+ [here](https://github.com/microsoft/rushstack/tree/main/build-tests/localization-plugin-test-02/src/strings5.resx).
54
+ Note that the `<xsd:schema>` and `<resheader>` elements are not required. Also note that although the
55
+ `.resx` supports many different types of localized data including strings and binary data, **only strings**
56
+ are supported by this plugin.
57
+
58
+ `.loc.json` is a very simple `JSON` schema for specifying localized string and translator comments.
59
+ See an example of a `.loc.json` file
60
+ [here](https://github.com/microsoft/rushstack/tree/main/build-tests/localization-plugin-test-02/src/strings3.loc.json).
61
+
62
+ `.resjson` is another simple `JSON` schema for specifying localized string and translator comments.
63
+ See [here](https://lingohub.com/developers/resource-files/resjson-localization) for documentation on `.resjson`
64
+
65
+ For most projects, `.loc.json` is a simpler format to use. However for large projects, projects that already use
66
+ translation services that support `.resx`, or engineers who are already experienced .NET developers, `.resx`
67
+ may be more convenient.
68
+
69
+ # Plugin
70
+
71
+ To use the plugin, add it to the `plugins` array of your Webpack config. For example:
72
+
73
+ ```JavaScript
74
+ import { LocalizationPlugin } from '@rushstack/webpack4-localization-plugin';
75
+
76
+ {
77
+ plugins: [
78
+ new LocalizationPlugin( /* options */ )
79
+ ]
80
+ }
81
+ ```
82
+
83
+ ***A note about the dev server:*** When Webpack is being run by the Webpack dev server, this plugin pipes
84
+ the strings in the loc files in the source (the `.loc.json` and the `.resx` files) to the output without
85
+ any translations.
86
+
87
+ ## Options
88
+
89
+ ### `localizedData = { }`
90
+
91
+ #### `localizedData.defaultLocale = { }`
92
+
93
+ This option has a required property (`localeName`), to specify the name of the locale used in the
94
+ `.resx` and `.loc.json` files in the source.
95
+
96
+ ##### `localizedData.defaultLocale.fillMissingTranslationStrings = true | false`
97
+
98
+ If this option is set to `true`, strings that are missing from `localizedData.translatedStrings` will be
99
+ provided by the default locale (the strings in the `.resx` and `.loc.json` files in the source). If
100
+ this option is unset or set to `false`, an error will be emitted if a string is missing from
101
+ `localizedData.translatedStrings`.
102
+
103
+ #### `localizedData.translatedStrings = { }`
104
+
105
+ This option is used to specify the localization data to be used in the build. This object has the following
106
+ structure:
107
+
108
+ - Locale name
109
+ - Compilation context-relative or absolute localization file path
110
+ - Translated strings
111
+
112
+ For example:
113
+
114
+ ```JavaScript
115
+ translatedStrings: {
116
+ "en-us": {
117
+ "./src/strings1.loc.json": {
118
+ "string1": "the first string"
119
+ }
120
+ },
121
+ "es-es": {
122
+ "./src/strings1.loc.json": {
123
+ "string1": "la primera cadena"
124
+ }
125
+ }
126
+ }
127
+ ```
128
+
129
+ Alternatively, instead of directly specifying the translations, a path to a translated resource file can be
130
+ specified. For example:
131
+
132
+ ```JavaScript
133
+ translatedStrings: {
134
+ "en-us": {
135
+ "./src/strings1.loc.json": "./localization/en-us/strings1.loc.json"
136
+ },
137
+ "es-es": {
138
+ "./src/strings1.loc.json": "./localization/es-es/strings1.loc.json"
139
+ }
140
+ }
141
+ ```
142
+
143
+ #### `localizedData.resolveMissingTranslatedStrings = (locales: string[], filePath: string) => { ... }`
144
+
145
+ This optional option can be used to resolve translated data that is missing from data that is provided
146
+ in the `localizedData.translatedStrings` option. Set this option with a function expecting two parameters:
147
+ the first, an array of locale names, and second, a fully-qualified path to the localized file in source. The
148
+ function should return an object with locale names as keys and localized data as values. The localized data
149
+ value should either be:
150
+
151
+ - a string: The absolute path to the translated data in `.resx` or `.loc.json` format
152
+ - an object: An object containing the translated data
153
+
154
+ Note that these values are the same as the values that can be specified for translations for a localized
155
+ resource in `localizedData.translatedStrings`.
156
+
157
+ If the function returns data that is missing locales or individual strings, the plugin will fall back to the
158
+ default locale if `localizedData.defaultLocale.fillMissingTranslationStrings` is set to `true`. If
159
+ `localizedData.defaultLocale.fillMissingTranslationStrings` is set to `false`, an error will result.
160
+
161
+ #### `localizedData.passthroughLocale = { }`
162
+
163
+ This option is used to specify how and if a passthrough locale should be generated. A passthrough locale
164
+ is a generated locale in which each string's value is its name. This is useful for debugging and for identifying
165
+ cases where a locale is missing.
166
+
167
+ This option takes two optional properties:
168
+
169
+ ##### `localizedData.passthroughLocale.usePassthroughLocale = true | false`
170
+
171
+ If `passthroughLocale.usePassthroughLocale` is set to `true`, a passthrough locale will be included in the output.
172
+ By default, the passthrough locale's name is "passthrough."
173
+
174
+ ##### `localizedData.passthroughLocale.passthroughLocaleName = '...'`
175
+
176
+ If `passthroughLocale.usePassthroughLocale` is set to `true`, the "passthrough" locale name can be overridden
177
+ by setting a value on `passthroughLocale.passthroughLocaleName`.
178
+
179
+ #### `localizedData.pseudolocales = { }`
180
+
181
+ This option allows pseudolocales to be generated from the strings in the default locale. This option takes
182
+ an option with pseudolocales as keys and options for the
183
+ [pseudolocale package](https://www.npmjs.com/package/pseudolocale) as values.
184
+
185
+ #### `localizedData.normalizeResxNewlines = 'crlf' | 'lf'`
186
+
187
+ This option allows normalization of newlines in RESX files. RESX files are XML, so newlines can be
188
+ specified by including a newline in the `<value>` element. For files stored on source control systems,
189
+ clones on Windows can end up with CRLF newlines and clones on 'nix operating systems can end up with LF
190
+ newlines. This option can be used to help make compilations run on different platforms produce the same
191
+ result.
192
+
193
+ #### `localizedData.ignoreMissingResxComments = true | false | undefined
194
+
195
+ If set to true, do not warn on missing RESX <data> element comments.
196
+
197
+ ### `globsToIgnore = [ ]`
198
+
199
+ This option is used to specify `.resx` and `.loc.json` files that should not be processed by this plugin.
200
+ By default, every `.resx`, `.resx.json`, and `.loc.json` file import is intercepted by this plugin, and an
201
+ error occurs if translations aren't provided for an intercepted file and the
202
+ `localizedData.defaultLocale.fillMissingTranslationStrings` option is set to falsy, or if the
203
+ file is in an unexpected format. To avoid an error, specify files that should be ignored by this plugin in
204
+ this property. This is useful if a dependency uses files with a `.resx`, `.resx.json`, or `.loc.json`
205
+ extension, but are processed in a different way from how this plugin handles localization.
206
+ For example: `globsToIgnore: [ 'node_modules/some-dependency-name/lib/**/*.loc.json' ]`
207
+
208
+ ### `noStringsLocaleName = '...'`
209
+
210
+ The value to replace the `[locale]` token with for chunks without localized strings. Defaults to "none"
211
+
212
+ ### `localizationStats = { }`
213
+
214
+ #### `localizationStats.dropPath = '...'`
215
+
216
+ This option is used to designate a path at which a JSON file describing the localized assets produced should be
217
+ written. If this property is omitted, the stats file won't be written.
218
+
219
+ The file has the following format:
220
+
221
+ ```JSON
222
+ {
223
+ "entrypoints": {
224
+ "<BUNDLE NAME>": {
225
+ "localizedAssets": {
226
+ "<LOCALE NAME>": "<ASSET NAME>",
227
+ "<LOCALE NAME>": "<ASSET NAME>"
228
+ }
229
+ },
230
+ "<BUNDLE NAME>": {
231
+ "localizedAssets": {
232
+ "<LOCALE NAME>": "<ASSET NAME>",
233
+ "<LOCALE NAME>": "<ASSET NAME>"
234
+ }
235
+ }
236
+ },
237
+ "namedChunkGroups": {
238
+ "<CHUNK NAME>": {
239
+ "localizedAssets": {
240
+ "<LOCALE NAME>": "<ASSET NAME>",
241
+ "<LOCALE NAME>": "<ASSET NAME>"
242
+ }
243
+ },
244
+ "<CHUNK NAME>": {
245
+ "localizedAssets": {
246
+ "<LOCALE NAME>": "<ASSET NAME>",
247
+ "<LOCALE NAME>": "<ASSET NAME>"
248
+ }
249
+ }
250
+ }
251
+ }
252
+
253
+ ```
254
+
255
+ #### `localizationStats.callback = (stats) => { ... }`
256
+
257
+ This option is used to specify a callback to be called with the stats data that would be dropped at
258
+ [`localizationStats.dropPath`](#localizationStats.DropPath--) after compilation completes.
259
+
260
+ ### `typingsOptions = { }`
261
+
262
+ This option is used to specify how and if TypeScript typings should be generated for loc files.
263
+
264
+ It takes two options:
265
+
266
+ #### `typingsOptions.generatedTsFolder = '...'`
267
+
268
+ This property specifies the folder in which `.d.ts` files for loc files should be dropped. It is recommended
269
+ that this be a folder parallel to the source folder, specified in addition to the source folder in the
270
+ [`rootDirs` `tsconfig.json` option](https://www.typescriptlang.org/docs/handbook/compiler-options.html).
271
+ **The folder specified by this option is emptied when compilation is started.**
272
+
273
+ This property is required if `typingsOptions` is set.
274
+
275
+ #### `typingsOptions.sourceRoot = '...'`
276
+
277
+ This optional property overrides the compiler context for discovery of localization files for which
278
+ typings should be generated.
279
+
280
+ #### `typingsOptions.exportAsDefault = true | false`
281
+
282
+ If this option is set to `true`, loc modules typings will be exported wrapped in a `default` property. This
283
+ allows strings to be imported by using the `import strings from './strings.loc.json';` syntax instead of
284
+ the `import { string1 } from './strings.loc.json';` or the `import * as strings from './strings.loc.json';`
285
+ syntax. This option is not recommended.
286
+
287
+ ## Links
288
+
289
+ - [CHANGELOG.md](https://github.com/microsoft/rushstack/blob/main/webpack/localization-plugin/CHANGELOG.md) - Find
290
+ out what's new in the latest version
291
+
292
+ `@rushstack/webpack4-localization-plugin` is part of the [Rush Stack](https://rushstack.io/) family of projects.
@@ -0,0 +1,11 @@
1
+ // This file is read by tools that parse documentation comments conforming to the TSDoc standard.
2
+ // It should be published with your NPM package. It should not be tracked by Git.
3
+ {
4
+ "tsdocVersion": "0.12",
5
+ "toolPackages": [
6
+ {
7
+ "packageName": "@microsoft/api-extractor",
8
+ "packageVersion": "7.25.2"
9
+ }
10
+ ]
11
+ }
@@ -0,0 +1,324 @@
1
+ import { IgnoreStringFunction } from '@rushstack/localization-utilities';
2
+ import { ILocalizationFile } from '@rushstack/localization-utilities';
3
+ import { IPseudolocaleOptions } from '@rushstack/localization-utilities';
4
+ import { ITerminal } from '@rushstack/node-core-library';
5
+ import * as Webpack from 'webpack';
6
+
7
+ /**
8
+ * @internal
9
+ */
10
+ declare interface IAddDefaultLocFileResult {
11
+ /**
12
+ * A list of paths to translation files that were loaded
13
+ */
14
+ additionalLoadedFilePaths: string[];
15
+ errors: Error[];
16
+ }
17
+
18
+ /**
19
+ * @public
20
+ */
21
+ export declare interface IDefaultLocaleOptions {
22
+ /**
23
+ * This required property specifies the name of the locale used in the
24
+ * `.resx`, `.loc.json`, and `.resjson` files in the source
25
+ */
26
+ localeName: string;
27
+ /**
28
+ * If this option is set to `true`, strings that are missing from
29
+ * `localizedData.translatedStrings` will be provided by the default locale
30
+ */
31
+ fillMissingTranslationStrings?: boolean;
32
+ }
33
+
34
+ /**
35
+ * @public
36
+ */
37
+ export declare interface ILocaleData {
38
+ [locFilePath: string]: string | ILocaleFileData;
39
+ }
40
+
41
+ /**
42
+ * @public
43
+ */
44
+ export declare interface ILocaleElementMap {
45
+ [locale: string]: string;
46
+ }
47
+
48
+ /**
49
+ * @public
50
+ */
51
+ export declare interface ILocaleFileData {
52
+ [stringName: string]: string;
53
+ }
54
+
55
+ /**
56
+ * The options for localization.
57
+ *
58
+ * @public
59
+ */
60
+ export declare interface ILocalizationPluginOptions {
61
+ /**
62
+ * Localization data.
63
+ */
64
+ localizedData: ILocalizedData;
65
+ /**
66
+ * This option is used to specify `.resx`, `.resx.json`, and `.loc.json` files that should not be processed by
67
+ * this plugin.
68
+ */
69
+ globsToIgnore?: string[];
70
+ /**
71
+ * The value to replace the [locale] token with for chunks without localized strings. Defaults to "none"
72
+ */
73
+ noStringsLocaleName?: string;
74
+ /**
75
+ * Options for how localization stats data should be produced.
76
+ */
77
+ localizationStats?: ILocalizationStatsOptions;
78
+ /**
79
+ * This option is used to specify how and if TypeScript typings should be generated for loc files.
80
+ */
81
+ typingsOptions?: ITypingsGenerationOptions;
82
+ /**
83
+ * Optionally, provide a function that will be called for each string. If the function returns `true`
84
+ * the string will not be included.
85
+ */
86
+ ignoreString?: IgnoreStringFunction;
87
+ /**
88
+ * @deprecated
89
+ * Use {@link ILocalizationPluginOptions.globsToIgnore} instead.
90
+ *
91
+ * @internalRemarks
92
+ * TODO: Remove when version 1.0.0 is released.
93
+ */
94
+ filesToIgnore?: string[];
95
+ }
96
+
97
+ /**
98
+ * @public
99
+ */
100
+ export declare interface ILocalizationStats {
101
+ entrypoints: {
102
+ [name: string]: ILocalizationStatsEntrypoint;
103
+ };
104
+ namedChunkGroups: {
105
+ [name: string]: ILocalizationStatsChunkGroup;
106
+ };
107
+ }
108
+
109
+ /**
110
+ * @public
111
+ */
112
+ export declare interface ILocalizationStatsChunkGroup {
113
+ localizedAssets: ILocaleElementMap;
114
+ }
115
+
116
+ /**
117
+ * @public
118
+ */
119
+ export declare interface ILocalizationStatsEntrypoint {
120
+ localizedAssets: ILocaleElementMap;
121
+ }
122
+
123
+ /**
124
+ * Options for how localization stats data should be produced.
125
+ *
126
+ * @public
127
+ */
128
+ export declare interface ILocalizationStatsOptions {
129
+ /**
130
+ * This option is used to designate a path at which a JSON file describing the localized
131
+ * assets produced should be written.
132
+ */
133
+ dropPath?: string;
134
+ /**
135
+ * This option is used to specify a callback to be called with the stats data that would be
136
+ * dropped at `localizationStats.dropPath` after compilation completes.
137
+ */
138
+ callback?: (stats: ILocalizationStats) => void;
139
+ }
140
+
141
+ /**
142
+ * @public
143
+ */
144
+ export declare interface ILocalizedData {
145
+ /**
146
+ * Options for the locale used in the source localized data files.
147
+ */
148
+ defaultLocale: IDefaultLocaleOptions;
149
+ /**
150
+ * Use this parameter to specify the translated data.
151
+ */
152
+ translatedStrings: ILocalizedStrings;
153
+ /**
154
+ * Use this parameter to specify a function used to load translations missing from
155
+ * the {@link ILocalizedData.translatedStrings} parameter.
156
+ */
157
+ resolveMissingTranslatedStrings?: (locales: string[], filePath: string) => IResolvedMissingTranslations;
158
+ /**
159
+ * Options around including a passthrough locale.
160
+ */
161
+ passthroughLocale?: IPassthroughLocaleOptions;
162
+ /**
163
+ * Options for pseudo-localization.
164
+ */
165
+ pseudolocales?: IPseudolocalesOptions;
166
+ /**
167
+ * Normalize newlines in RESX files to either CRLF (Windows-style) or LF ('nix style)
168
+ */
169
+ normalizeResxNewlines?: 'lf' | 'crlf';
170
+ /**
171
+ * If set to true, do not warn on missing RESX `<data>` element comments.
172
+ */
173
+ ignoreMissingResxComments?: boolean;
174
+ }
175
+
176
+ /**
177
+ * @public
178
+ */
179
+ export declare interface ILocalizedStrings {
180
+ [locale: string]: ILocaleData;
181
+ }
182
+
183
+ /**
184
+ * @public
185
+ */
186
+ export declare interface ILocalizedWebpackChunk extends Webpack.compilation.Chunk {
187
+ localizedFiles?: {
188
+ [locale: string]: string;
189
+ };
190
+ }
191
+
192
+ /**
193
+ * Options for the passthrough locale.
194
+ *
195
+ * @public
196
+ */
197
+ export declare interface IPassthroughLocaleOptions {
198
+ /**
199
+ * If this is set to `true`, a passthrough locale will be included in the output
200
+ */
201
+ usePassthroughLocale?: boolean;
202
+ /**
203
+ * If {@link IPassthroughLocaleOptions.usePassthroughLocale} is set, use this name for the passthrough locale.
204
+ * Defaults to "passthrough"
205
+ */
206
+ passthroughLocaleName?: string;
207
+ }
208
+
209
+ /**
210
+ * Options for generated pseudolocales.
211
+ *
212
+ * @public
213
+ */
214
+ export declare interface IPseudolocalesOptions {
215
+ [pseudoLocaleName: string]: IPseudolocaleOptions;
216
+ }
217
+
218
+ /**
219
+ * @public
220
+ */
221
+ export declare interface IResolvedMissingTranslations {
222
+ [localeName: string]: string | ILocaleFileData;
223
+ }
224
+
225
+ /**
226
+ * @internal
227
+ */
228
+ export declare interface _IStringPlaceholder {
229
+ value: string;
230
+ suffix: string;
231
+ }
232
+
233
+ /**
234
+ * @internal
235
+ */
236
+ declare interface IStringSerialNumberData {
237
+ values: ILocaleElementMap;
238
+ locFilePath: string;
239
+ stringName: string;
240
+ }
241
+
242
+ /**
243
+ * Options for typing generation.
244
+ *
245
+ * @public
246
+ */
247
+ export declare interface ITypingsGenerationOptions {
248
+ /**
249
+ * This property specifies the folder in which `.d.ts` files for loc files should be dropped.
250
+ */
251
+ generatedTsFolder: string;
252
+ /**
253
+ * This optional property overrides the compiler context for discovery of localization files
254
+ * for which typings should be generated.
255
+ */
256
+ sourceRoot?: string;
257
+ /**
258
+ * If this option is set to `true`, loc modules typings will be exported wrapped in a `default` property.
259
+ */
260
+ exportAsDefault?: boolean;
261
+ /**
262
+ * @deprecated
263
+ * Use {@link ILocalizationPluginOptions.ignoreString} instead.
264
+ *
265
+ * @internalRemarks
266
+ * TODO: Remove when version 1.0.0 is released.
267
+ */
268
+ ignoreString?: (resxFilePath: string, stringName: string) => boolean;
269
+ /**
270
+ * Optionally, provide a function that will process string comments. The returned value will become the
271
+ * TSDoc comment for the string in the typings.
272
+ */
273
+ processComment?: (comment: string | undefined, resxFilePath: string, stringName: string) => string | undefined;
274
+ }
275
+
276
+ /**
277
+ * This plugin facilitates localization in webpack.
278
+ *
279
+ * @public
280
+ */
281
+ export declare class LocalizationPlugin implements Webpack.Plugin {
282
+ /**
283
+ * @internal
284
+ */
285
+ stringKeys: Map<string, _IStringPlaceholder>;
286
+ private _options;
287
+ private _resolvedTranslatedStringsFromOptions;
288
+ private _globsToIgnore;
289
+ private _stringPlaceholderCounter;
290
+ private _stringPlaceholderMap;
291
+ private _locales;
292
+ private _passthroughLocaleName;
293
+ private _defaultLocale;
294
+ private _noStringsLocaleName;
295
+ private _fillMissingTranslationStrings;
296
+ private _pseudolocalizers;
297
+ private _resxNewlineNormalization;
298
+ private _ignoreMissingResxComments;
299
+ /**
300
+ * The outermost map's keys are the locale names.
301
+ * The middle map's keys are the resolved, file names.
302
+ * The innermost map's keys are the string identifiers and its values are the string values.
303
+ */
304
+ private _resolvedLocalizedStrings;
305
+ constructor(options: ILocalizationPluginOptions);
306
+ apply(compiler: Webpack.Compiler): void;
307
+ /**
308
+ * @internal
309
+ *
310
+ * @returns
311
+ */
312
+ addDefaultLocFile(terminal: ITerminal, localizedResourcePath: string, localizedResourceData: ILocalizationFile): IAddDefaultLocFileResult;
313
+ /**
314
+ * @internal
315
+ */
316
+ getDataForSerialNumber(serialNumber: string): IStringSerialNumberData | undefined;
317
+ private _addLocFile;
318
+ private _initializeAndValidateOptions;
319
+ private _getPlaceholderString;
320
+ private _chunkHasLocalizedModules;
321
+ private _convertLocalizationFileToLocData;
322
+ }
323
+
324
+ export { }
@@ -0,0 +1,36 @@
1
+ import * as Webpack from 'webpack';
2
+ import { LocalizationPlugin } from './LocalizationPlugin';
3
+ export interface IProcessAssetOptionsBase {
4
+ plugin: LocalizationPlugin;
5
+ compilation: Webpack.compilation.Compilation;
6
+ assetName: string;
7
+ asset: IAsset;
8
+ chunk: Webpack.compilation.Chunk;
9
+ noStringsLocaleName: string;
10
+ chunkHasLocalizedModules: (chunk: Webpack.compilation.Chunk) => boolean;
11
+ }
12
+ export interface IProcessNonLocalizedAssetOptions extends IProcessAssetOptionsBase {
13
+ }
14
+ export interface IProcessLocalizedAssetOptions extends IProcessAssetOptionsBase {
15
+ locales: Set<string>;
16
+ fillMissingTranslationStrings: boolean;
17
+ defaultLocale: string;
18
+ }
19
+ export interface IAsset {
20
+ size(): number;
21
+ source(): string;
22
+ }
23
+ export interface IProcessAssetResult {
24
+ filename: string;
25
+ asset: IAsset;
26
+ }
27
+ export declare const PLACEHOLDER_REGEX: RegExp;
28
+ export declare class AssetProcessor {
29
+ static processLocalizedAsset(options: IProcessLocalizedAssetOptions): Map<string, IProcessAssetResult>;
30
+ static processNonLocalizedAsset(options: IProcessNonLocalizedAssetOptions): IProcessAssetResult;
31
+ private static _reconstructLocalized;
32
+ private static _reconstructNonLocalized;
33
+ private static _parseStringToReconstructionSequence;
34
+ private static _getJsonpFunction;
35
+ }
36
+ //# sourceMappingURL=AssetProcessor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AssetProcessor.d.ts","sourceRoot":"","sources":["../src/AssetProcessor.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAKnC,OAAO,EAAE,kBAAkB,EAA0C,MAAM,sBAAsB,CAAC;AAgDlG,MAAM,WAAW,wBAAwB;IACvC,MAAM,EAAE,kBAAkB,CAAC;IAC3B,WAAW,EAAE,OAAO,CAAC,WAAW,CAAC,WAAW,CAAC;IAC7C,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,OAAO,CAAC,WAAW,CAAC,KAAK,CAAC;IACjC,mBAAmB,EAAE,MAAM,CAAC;IAC5B,wBAAwB,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,WAAW,CAAC,KAAK,KAAK,OAAO,CAAC;CACzE;AAED,MAAM,WAAW,gCAAiC,SAAQ,wBAAwB;CAAG;AAErF,MAAM,WAAW,6BAA8B,SAAQ,wBAAwB;IAC7E,OAAO,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IACrB,6BAA6B,EAAE,OAAO,CAAC;IACvC,aAAa,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,MAAM;IACrB,IAAI,IAAI,MAAM,CAAC;IACf,MAAM,IAAI,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,mBAAmB;IAClC,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,eAAO,MAAM,iBAAiB,EAAE,MAG/B,CAAC;AAEF,qBAAa,cAAc;WACX,qBAAqB,CACjC,OAAO,EAAE,6BAA6B,GACrC,GAAG,CAAC,MAAM,EAAE,mBAAmB,CAAC;WA2DrB,wBAAwB,CAAC,OAAO,EAAE,gCAAgC,GAAG,mBAAmB;IAiDtG,OAAO,CAAC,MAAM,CAAC,qBAAqB;IAiFpC,OAAO,CAAC,MAAM,CAAC,wBAAwB;IAmDvC,OAAO,CAAC,MAAM,CAAC,oCAAoC;IAyFnD,OAAO,CAAC,MAAM,CAAC,iBAAiB;CAsDjC"}