Skip to content

Commit d03db66

Browse files
dominicbachmanngeromegrignon
authored andcommitted
feat: add and configure @angular/localize
1 parent 5019435 commit d03db66

19 files changed

+296
-64
lines changed

angular.json

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,28 @@
1313
"root": "",
1414
"sourceRoot": "src",
1515
"prefix": "app",
16+
"i18n": {
17+
"sourceLocale": {
18+
"code": "en",
19+
"subPath": ""
20+
},
21+
"locales": {
22+
"de": {
23+
"translation": "src/locale/messages.de.json"
24+
},
25+
"fr": {
26+
"translation": "src/locale/messages.fr.json"
27+
}
28+
}
29+
},
1630
"architect": {
1731
"build": {
1832
"builder": "@angular/build:application",
1933
"options": {
2034
"browser": "src/main.ts",
2135
"index": "src/indexDefault.html",
2236
"tsConfig": "tsconfig.app.json",
37+
"localize": true,
2338
"assets": [
2439
{
2540
"glob": "**/*",
@@ -31,7 +46,10 @@
3146
"outputMode": "server",
3247
"ssr": {
3348
"entry": "src/server.ts"
34-
}
49+
},
50+
"polyfills": [
51+
"@angular/localize/init"
52+
]
3553
},
3654
"configurations": {
3755
"production": {
@@ -82,7 +100,12 @@
82100
"input": "public"
83101
}
84102
],
85-
"styles": ["src/styles.css"]
103+
"styles": [
104+
"src/styles.css"
105+
],
106+
"polyfills": [
107+
"@angular/localize/init"
108+
]
86109
}
87110
}
88111
}

messages.json

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"locale": "en",
3+
"translations": {
4+
"5729418620241283277": "Events",
5+
"4282290715877032507": "Organizers",
6+
"5481284030283031915": "Website",
7+
"8585369201408386550": " Join the community ",
8+
"635264773021131084": " Starting from ",
9+
"7097963028377891250": " To be announced ",
10+
"457763919401259967": " Registration ",
11+
"5891064527381218201": "Free",
12+
"8291262399353359697": "Attendees",
13+
"5260501588919384967": " Register now ",
14+
"6364272713313334628": " No registration available ",
15+
"926352149584380702": "Organized by",
16+
"4862119345478890729": " Listen Now ",
17+
"383604207727627418": "Try adjusting your search terms",
18+
"6380110438893831255": "or browse all events above",
19+
"6257229111292962180": "The Angular community hub for events, communities, and podcasts",
20+
"6910865064463105075": "Communities",
21+
"1984987229407697795": "Podcasts",
22+
"3676011873566441889": "Curated list of Angular communities",
23+
"1229359301315184889": "Curated list of Angular Events",
24+
"3776293039808729401": "No events found",
25+
"4118966711789506787": "We could not find any events matching your search criteria. Try different keywords or browse all available events.",
26+
"8228704013073542414": "No upcoming events",
27+
"5181869256727726277": "There are currently no upcoming Angular events scheduled. New events are added regularly, so please check back soon!",
28+
"2104481506343485854": "Curated list of Angular Communities, Events, Podcasts, and Call for Papers.",
29+
"8162118643101139148": "Developers interested in Angular and related technologies.",
30+
"6829527508389756715": "Angular Events",
31+
"8870711330013548872": "Online",
32+
"6578397717654172779": "Page Not Found",
33+
"1659745110459296080": "Go Back Home",
34+
"5674307105789988119": "Curated list of Angular Talks"
35+
}
36+
}

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
"build": "ng build",
99
"watch": "ng build --watch --configuration development",
1010
"test": "ng test",
11-
"serve:ssr:angular-hub": "node dist/angular-hub/server/server.mjs"
11+
"serve:ssr:angular-hub": "node dist/angular-hub/server/server.mjs",
12+
"i18n:extract": "ng extract-i18n --format json",
13+
"i18n:merge-translations": "node ./scripts/merge-translations.js"
1214
},
1315
"private": true,
1416
"prettier": {
@@ -56,6 +58,7 @@
5658
"@angular/cli": "^20.0.5",
5759
"@angular/compiler-cli": "^20.0.5",
5860
"@angular/language-service": "18.2.0",
61+
"@angular/localize": "20.0.6",
5962
"@commitlint/cli": "^19.3.0",
6063
"@commitlint/config-conventional": "^19.2.2",
6164
"husky": "^9.0.11",

pnpm-lock.yaml

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

scripts/merge-translations.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { readFile, writeFile } from "node:fs/promises";
2+
import config from '../angular.json' with { type: 'json' };
3+
import messagesFile from '../messages.json' with { type: 'json' };
4+
5+
const localesFilePaths = Object.values(config.projects["angular-hub"].i18n.locales).map((locale) => locale.translation);
6+
7+
const messages = Object.entries(messagesFile.translations);
8+
9+
const newLocales = await Promise.all(localesFilePaths.map(async (localeFilePath) => {
10+
const localeFile = await readFile(localeFilePath, { encoding: 'utf-8' });
11+
12+
const localeFileData = JSON.parse(localeFile);
13+
14+
const updatedTranslations = messages.reduce((acc, [key, value]) => {
15+
return {
16+
...acc,
17+
[key]: key in localeFileData.translations ? localeFileData.translations[key] : value
18+
}
19+
}, {});
20+
21+
return {
22+
file: localeFilePath,
23+
data: {
24+
...localeFileData,
25+
translations: updatedTranslations
26+
}
27+
};
28+
}));
29+
30+
await Promise.all(newLocales.map(async (newLocale) => {
31+
return writeFile(newLocale.file, JSON.stringify(newLocale.data, null, "\t"), { encoding: 'utf-8' })
32+
}))
33+

src/app/components/cards/community-card.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import { Community } from '../../../models/community.model';
3232
class="text-sm hover:underline flex items-center gap-2"
3333
>
3434
<i class="pi pi-calendar text-2xl text-[#BF25B9]"></i>
35-
<span>Events</span>
35+
<span i18n>Events</span>
3636
</a>
3737
</li>
3838
}
@@ -44,7 +44,7 @@ import { Community } from '../../../models/community.model';
4444
class="text-sm hover:underline flex items-center gap-2"
4545
>
4646
<i class="pi pi-users text-2xl text-[#0077B5]"></i>
47-
<span>Organizers</span>
47+
<span i18n>Organizers</span>
4848
</a>
4949
</li>
5050
}
@@ -56,7 +56,7 @@ import { Community } from '../../../models/community.model';
5656
class="text-sm hover:underline flex items-center gap-2"
5757
>
5858
<i class="pi pi-globe text-2xl text-[#0077B5]"></i>
59-
<span>Website</span>
59+
<span i18n>Website</span>
6060
</a>
6161
</li>
6262
}
@@ -121,6 +121,7 @@ import { Community } from '../../../models/community.model';
121121
[href]="community().eventsUrl"
122122
target="_blank"
123123
class="w-full flex items-center justify-center text-sm bg-[#26A0D9] text-white p-2 rounded-lg"
124+
i18n
124125
>
125126
Join the community
126127
</a>

0 commit comments

Comments
 (0)