Skip to content

Commit 198a6ea

Browse files
committed
feat(i18n): add more config to use transloco
1 parent 1f0c198 commit 198a6ea

File tree

14 files changed

+238
-37
lines changed

14 files changed

+238
-37
lines changed

angular.json

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,42 @@
208208
"devServerTarget": "dark-heresy:serve:development"
209209
}
210210
}
211+
},
212+
"server": {
213+
"builder": "@angular-builders/custom-webpack:server",
214+
"options": {
215+
"customWebpackConfig": {
216+
"path": "./scripts/webpack/custom-webpack-server.config.js",
217+
"replaceDuplicatePlugins": false
218+
},
219+
"outputPath": "dist/server",
220+
"main": "src/main.server.ts",
221+
"tsConfig": "src/tsconfig.server.json"
222+
},
223+
"configurations": {
224+
"production": {
225+
"fileReplacements": [
226+
{
227+
"replace": "src/environments/environment.ts",
228+
"with": "src/environments/server/environment-server.production.ts"
229+
},
230+
{
231+
"replace": "src/manifest.json",
232+
"with": "src/manifests/manifest.production.json"
233+
},
234+
{
235+
"replace": "src/robots.txt",
236+
"with": "src/seo/robots/robots.production.txt"
237+
}
238+
],
239+
"bundleDependencies": "all",
240+
"sourceMap": false,
241+
"optimization": {
242+
"scripts": false,
243+
"styles": true
244+
}
245+
}
246+
}
211247
}
212248
}
213249
}

package-lock.json

Lines changed: 15 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,19 @@
33
"version": "0.0.0",
44
"scripts": {
55
"\n# LOCAL DEV SCRIPTS:": "",
6-
"start": "node --max_old_space_size=8192 node_modules/@angular/cli/bin/ng serve -c development",
6+
"start": "npm run i18n:cache-busting && node --max_old_space_size=8192 node_modules/@angular/cli/bin/ng serve -c development",
7+
"start:ssr": "node dist/server",
78
"\n# BUILD SCRIPTS:": "",
8-
"build": "node --max_old_space_size=8192 node_modules/@angular/cli/bin/ng build",
9-
"build:stats": "node --max_old_space_size=8192 node_modules/@angular/cli/bin/ng build --prod --configuration stats",
10-
"build:browser:production": "node --max_old_space_size=8192 node_modules/@angular/cli/bin/ng build --prod --configuration production",
9+
"build": "npm run transloco:optimize && npm run i18n:cache-busting && node --max_old_space_size=8192 node_modules/@angular/cli/bin/ng build",
10+
"build:stats": "npm run transloco:optimize && npm run i18n:cache-busting && node --max_old_space_size=8192 node_modules/@angular/cli/bin/ng build --prod --configuration stats",
11+
"build:browser:production": "npm run transloco:optimize && npm run i18n:cache-busting && node --max_old_space_size=8192 node_modules/@angular/cli/bin/ng build --prod --configuration production",
12+
"build:server:production": "ng run dark-heresy:server:production",
13+
"build:client-and-server-bundles:production": "concurrently \"npm run build:browser:production\" \"npm run build:server:production\"",
14+
"build:ssr:production": "concurrently \"npm run build:client-and-server-bundles:production\" \"npm run compile:server\"",
15+
"compile:server": "webpack --config webpack.server.config.js --progress --colors",
1116
"\n# TEST SCRIPTS:": "",
1217
"test": "node --max_old_space_size=8192 node_modules/@angular/cli/bin/ng test dark-heresy",
13-
"test:ci": "node --max_old_space_size=8192 node_modules/@angular/cli/bin/ng test dark-heresy --karmaConfig=./src/karma.conf.ci.js",
18+
"test:ci": "npm run i18n:cache-busting && node --max_old_space_size=8192 node_modules/@angular/cli/bin/ng test dark-heresy --karmaConfig=./src/karma.conf.ci.js",
1419
"e2e": "node --max_old_space_size=8192 node_modules/@angular/cli/bin/ng e2e",
1520
"\n# LINT SCRIPTS:": "",
1621
"lint": "concurrently \"npm run stylelint\" \"npm run tslint\"",
@@ -19,10 +24,13 @@
1924
"\n# UTILS SCRIPTS:": "",
2025
"ng": "node --max_old_space_size=8192 node_modules/@angular/cli/bin/ng",
2126
"cz": "git add . && git-cz && git push-upstream",
27+
"akita": "akita",
2228
"semver": "npx semantic-release",
2329
"analyze:stats": "npm run build:stats && webpack-bundle-analyzer dist/browser/stats.json",
2430
"clean": "rimraf coverage dist",
2531
"circular-dependencies-check": "npx madge ./src/ --circular --extensions ts,js --image ./dist/dependencies-graph.svg --warning",
32+
"transloco:optimize": "transloco-optimize dist/browser/assets/i18n",
33+
"i18n:cache-busting": "node ./scripts/node/i18n-cache-busting.js",
2634
"generate-certificate": "openssl req -new -x509 -newkey rsa:2048 -sha256 -nodes -keyout ssl/dark-heresy.key -days 3560 -out ssl/dark-heresy.crt -config ssl/certificate.cnf"
2735
},
2836
"config": {
@@ -76,7 +84,6 @@
7684
"@datorama/akita-cli": "~6.1.0",
7785
"@datorama/akita-ngdevtools": "~3.0.2",
7886
"@ngneat/transloco-optimize": "~1.0.1",
79-
"@ngneat/transloco-scoped-libs": "~1.2.0",
8087
"@semantic-release/changelog": "~5.0.0",
8188
"@semantic-release/git": "~9.0.0",
8289
"@types/core-js": "~2.5.3",
@@ -90,6 +97,7 @@
9097
"concurrently": "~5.1.0",
9198
"cz-customizable": "~6.2.0",
9299
"fibers": "~4.0.2",
100+
"fs-extra": "~8.1.0",
93101
"glob": "~7.1.6",
94102
"graphviz": "0.0.9",
95103
"http-server": "~0.12.1",

scripts/node/i18n-cache-busting.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const crypto = require('crypto');
2+
const fs = require('fs-extra');
3+
const glob = require('glob');
4+
5+
function generateChecksum(str, algorithm, encoding) {
6+
return crypto
7+
.createHash(algorithm || 'md5')
8+
.update(str, 'utf8')
9+
.digest(encoding || 'hex');
10+
}
11+
12+
const result = {};
13+
14+
glob.sync(`src/assets/i18n/**/*.json`).forEach(path => {
15+
const [ _, lang ] = path.split('src/assets/i18n/');
16+
const content = fs.readFileSync(path, {
17+
encoding: 'utf-8'
18+
});
19+
20+
result[ lang.replace('.json', '') ] = generateChecksum(content);
21+
});
22+
23+
fs.writeFileSync('./src/assets/i18n-cache-busting.json', JSON.stringify(result));
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
plugins: []
3+
};

server.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { enableProdMode } from '@angular/core';
2+
import * as express from 'express';
3+
import _ from 'lodash';
4+
import { join } from 'path';
5+
import 'zone.js/dist/zone-node';
6+
import * as mainServer from './dist/server/main';
7+
8+
enableProdMode();
9+
10+
const app = express();
11+
const PORT = 6888;
12+
const DIST_FOLDER = join(process.cwd(), 'dist');
13+
const DIST_BROWSER_FOLDER = join(DIST_FOLDER, 'browser');
14+
15+
const { AppServerModuleNgFactory, LAZY_MODULE_MAP, ngExpressEngine, provideModuleMap }: any = mainServer;
16+
17+
app.engine('html', ngExpressEngine({
18+
bootstrap: AppServerModuleNgFactory,
19+
providers: [
20+
provideModuleMap(LAZY_MODULE_MAP)
21+
]
22+
}));
23+
24+
app.set('view engine', 'html');
25+
app.set('views', DIST_BROWSER_FOLDER);
26+
27+
app.get('*.*', express.static(DIST_BROWSER_FOLDER, {
28+
maxAge: '1y'
29+
}));
30+
31+
app.get('app/*', (req: any, res: any) => {
32+
res.type('html');
33+
34+
res.render('index', {
35+
req
36+
}, (_err: any, html: any) => {
37+
res.send(_.unescape(html));
38+
});
39+
});
40+
41+
app.get('*', (req: any, res: any) => {
42+
res.type('html');
43+
44+
res.render('index', {
45+
req
46+
}, (_err: any, html: any) => {
47+
res.send(_.unescape(html));
48+
});
49+
});
50+
51+
app.listen(PORT, () => {
52+
console.log(`Node Express server listening on http://localhost:${PORT}`);
53+
});
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export function createScript(scriptSource: Readonly<string>): HTMLScriptElement {
2+
const scriptElement: HTMLScriptElement = document.createElement('script');
3+
4+
scriptElement.src = scriptSource;
5+
scriptElement.type = 'text/javascript';
6+
7+
return scriptElement;
8+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function loadScript(script: Readonly<HTMLScriptElement>): void {
2+
document.body.appendChild(script);
3+
}

src/assets/i18n/app/fr.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{
2+
}

src/index.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@
3838
property="og:title">
3939
<meta content="L'application pour le jeu de rôle Dark Heresy"
4040
property="og:description">
41-
<meta content="https://customer-portal:4202"
41+
<meta content="https://dark-heresy:6666"
4242
property="og:url">
43-
<meta content="http://customer-portal:4202/assets/images/seo/home.jpg"
43+
<meta content="/assets/images/seo/home.jpg"
4444
property="og:image">
45-
<meta content="http://customer-portal:4202/assets/images/seo/home.jpg"
45+
<meta content="/assets/images/seo/home.jpg"
4646
property="og:image:url">
47-
<meta content="https://customer-portal:4202/assets/images/seo/home.jpg"
47+
<meta content="/assets/images/seo/home.jpg"
4848
property="og:image:secure_url">
4949
<meta content="1200"
5050
property="og:image:width">
@@ -68,7 +68,7 @@
6868
name="twitter:title">
6969
<meta content="L'application pour le jeu de rôle Dark Heresy"
7070
name="twitter:description">
71-
<meta content="http://customer-portal:4202/assets/images/seo/home.jpg"
71+
<meta content="/assets/images/seo/home.jpg"
7272
name="twitter:image">
7373
<meta content="Pilotes Dark Heresy"
7474
name="twitter:image:alt">
@@ -78,7 +78,7 @@
7878
itemprop="name">
7979
<meta content="L'application pour le jeu de rôle Dark Heresy"
8080
itemprop="description">
81-
<meta content="http://customer-portal:4202/assets/images/seo/home.jpg"
81+
<meta content="/assets/images/seo/home.jpg"
8282
itemprop="image">
8383

8484
<!-- Robots -->

0 commit comments

Comments
 (0)