Skip to content

Commit a781019

Browse files
committed
Prototype localization plugin for Webpack.
1 parent 5a8e903 commit a781019

File tree

25 files changed

+776
-49
lines changed

25 files changed

+776
-49
lines changed

apps/rush-lib/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"cli-table": "~0.3.1",
2929
"colors": "~1.2.1",
3030
"git-repo-info": "~2.1.0",
31-
"glob": "~7.0.5",
31+
"glob": "~7.1.4",
3232
"glob-escape": "~0.0.1",
3333
"https-proxy-agent": "~2.2.1",
3434
"inquirer": "~6.2.0",
@@ -49,7 +49,7 @@
4949
"@microsoft/node-library-build": "6.4.3",
5050
"@microsoft/rush-stack-compiler-3.5": "0.4.2",
5151
"@rushstack/eslint-config": "0.5.4",
52-
"@types/glob": "5.0.30",
52+
"@types/glob": "7.1.1",
5353
"@types/inquirer": "0.0.43",
5454
"@types/jest": "23.3.11",
5555
"@types/js-yaml": "3.12.1",

build-tests/localization-plugin-test/build.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ const child_process = require('child_process');
33
const path = require('path');
44
const process = require('process');
55

6+
const { LocJsonPreprocessor } = require('@microsoft/localization-plugin');
7+
68
function executeCommand(command) {
79
console.log('---> ' + command);
810
child_process.execSync(command, { stdio: 'inherit' });
@@ -14,8 +16,10 @@ fsx.emptyDirSync('dist');
1416
fsx.emptyDirSync('lib');
1517
fsx.emptyDirSync('temp');
1618

17-
// Run the TypeScript compiler
18-
executeCommand('node node_modules/typescript/lib/tsc');
19+
LocJsonPreprocessor.preprocessLocJsonFiles({
20+
srcFolder: path.resolve(__dirname, 'src'),
21+
generatedTsFolder: path.resolve(__dirname, 'temp', 'loc-json-ts')
22+
});
1923

2024
// Run Webpack
2125
executeCommand('node node_modules/webpack-cli/bin/cli');
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "localization-plugin-test",
3-
"description": "Building this project is a regression test for @microsoft/localization-plugin",
3+
"description": "Building this project exercises @microsoft/localization-plugin",
44
"version": "0.1.0",
55
"private": true,
66
"scripts": {
@@ -9,9 +9,9 @@
99
"dependencies": {
1010
"webpack": "~4.31.0",
1111
"@microsoft/localization-plugin": "0.1.0",
12-
"typescript": "~3.1.6",
1312
"fs-extra": "~7.0.1",
1413
"@microsoft/rush-stack-compiler-3.5": "0.4.2",
15-
"webpack-cli": "~3.3.2"
14+
"webpack-cli": "~3.3.2",
15+
"ts-loader": "6.0.0"
1616
}
1717
}

build-tests/localization-plugin-test/src/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
console.log('test');
1+
import { string1 } from './strings1.loc.json';
2+
import * as strings2 from './strings3.loc.json';
3+
4+
console.log(string1);
5+
6+
console.log(strings2.string2);
27

38
import(/* webpackChunkName: 'secondary-chunk' */ './secondaryChunk').then(({ SecondaryChunk }) => {
49
const chunk = new SecondaryChunk();
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import * as strings from './strings2.loc.json';
2+
13
export class SecondaryChunk {
24
public doStuff(): void {
3-
console.log('foobar');
5+
console.log(strings.string1);
46
}
57
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"string1": {
3+
"value": "string one",
4+
"comment": "the first string"
5+
}
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"string1": {
3+
"value": "string two",
4+
"comment": "the second string"
5+
}
6+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"string1": {
3+
"value": "string three",
4+
"comment": "the third string"
5+
},
6+
"string2": {
7+
"value": "string four",
8+
"comment": "the fourth string"
9+
}
10+
}
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
{
2-
"extends": "./node_modules/@microsoft/rush-stack-compiler-3.5/includes/tsconfig-web.json"
2+
"extends": "./node_modules/@microsoft/rush-stack-compiler-3.5/includes/tsconfig-web.json",
3+
"compilerOptions": {
4+
"rootDirs": [
5+
"./src",
6+
"./temp/loc-json-ts"
7+
]
8+
}
39
}

build-tests/localization-plugin-test/webpack.config.js

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,26 @@ const { LocalizationPlugin } = require('@microsoft/localization-plugin');
88
module.exports = function(env) {
99
const configuration = {
1010
mode: 'production',
11+
module: {
12+
rules: [
13+
{
14+
test: /\.tsx?$/,
15+
loader: require.resolve('ts-loader'),
16+
exclude: /(node_modules)/,
17+
options: {
18+
compiler: require.resolve('@microsoft/rush-stack-compiler-3.2/node_modules/typescript'),
19+
logLevel: 'ERROR',
20+
configFile: path.resolve(__dirname, 'tsconfig.json')
21+
}
22+
}
23+
]
24+
},
25+
context: path.resolve(__dirname, 'src'),
1126
resolve: {
12-
extensions: ['.js', '.jsx', '.json'],
27+
extensions: ['.js', '.jsx', '.json', '.ts', '.tsx']
1328
},
1429
entry: {
15-
'localization-test': path.join(__dirname, 'lib', 'index.js')
30+
'localization-test': path.join(__dirname, 'src', 'index.ts')
1631
},
1732
output: {
1833
path: path.join(__dirname, 'dist'),
@@ -25,7 +40,32 @@ module.exports = function(env) {
2540
plugins: [
2641
new webpack.optimize.ModuleConcatenationPlugin(),
2742
new LocalizationPlugin({
28-
43+
localizedStrings: {
44+
"en-us": {
45+
"./strings1.loc.json": {
46+
"string1": "the first string"
47+
},
48+
"./strings2.loc.json": {
49+
"string1": "the second string"
50+
},
51+
"./strings3.loc.json": {
52+
"string1": "the third string",
53+
"string2": "the fourth string",
54+
}
55+
},
56+
"es-es": {
57+
"./strings1.loc.json": {
58+
"string1": "la primera cadena"
59+
},
60+
"./strings2.loc.json": {
61+
"string1": "la segunda cadena"
62+
},
63+
"./strings3.loc.json": {
64+
"string1": "la tercera cadena",
65+
"string2": "la cuarta cadena",
66+
}
67+
}
68+
}
2969
})
3070
]
3171
};

0 commit comments

Comments
 (0)