77## Overview
88
99This plugin produces webpack bundles that have multiple locales' variants of strings embedded. It also
10- has OOB support for RESX files in addition to JSON strings files (with the extension ` .loc.json ` ), including
10+ has out-of-box support for RESX files in addition to JSON strings files (with the extension ` .loc.json ` ), including
1111support for generating typings.
1212
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/master/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/master/build-tests/localization-plugin-test-02 )
22+ - This project contains three webpack entrypoints:
23+ - [ ` indexA.ts ` ] ( https://github.com/microsoft/rushstack/tree/master/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/master/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/master/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 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/master/build-tests/localization-plugin-test-03 )
34+ - This project contains four webpack entrypoints:
35+ - [ ` indexA.ts ` ] ( https://github.com/microsoft/rushstack/tree/master/build-tests/localization-plugin-test-03/src/indexA.ts )
36+ directly references two ` .loc.json ` files and one ` .resx ` 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/master/build-tests/localization-plugin-test-03/src/indexB.ts )
39+ directly references two ` .loc.json ` files
40+ - [ ` indexC.ts ` ] ( https://github.com/microsoft/rushstack/tree/master/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/master/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 Spanish translations for all 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 `
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/master/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/master/build-tests/localization-plugin-test-02/src/strings3.loc.json ) .
61+
62+ For most projects, ` .loc.json ` is a simpler format to use. However for large projects, projects that already use
63+ translation services that support ` .resx ` , or engineers who are already experienced .NET developers, ` .resx `
64+ may be more convenient.
65+
1366# Plugin
1467
1568To use the plugin, add it to the ` plugins ` array of your Webpack config. For example:
@@ -19,7 +72,7 @@ import { LocalizationPlugin } from '@rushstack/localization-plugin';
1972
2073{
2174 plugins: [
22- new SetPublicPathPlugin ( /* webpackPublicPathOptions */ )
75+ new LocalizationPlugin ( /* options */ )
2376 ]
2477}
2578```
@@ -175,7 +228,3 @@ If this option is set to `true`, loc modules typings will be exported wrapped in
175228allows strings to be imported by using the ` import strings from './strings.loc.json'; ` syntax instead of
176229the ` import { string1 } from './strings.loc.json'; ` or the ` import * as strings from './strings.loc.json'; `
177230syntax.
178-
179- # License
180-
181- MIT (http://www.opensource.org/licenses/mit-license.php)
0 commit comments