A learning-focused Angular 19 app that demonstrates runtime internationalization using ngx-translate, language-specific JSON files, placeholder interpolation, and basic RTL/LTR direction handling through small standalone demo components.
- Angular 19
- TypeScript
- SCSS
- RxJS
@ngx-translate/core@ngx-translate/http-loader
- Node.js 18+ (latest LTS recommended)
- npm
npm installnpm startThe app runs at http://localhost:4200/.
npm start- start development servernpm run build- create production buildnpm run watch- build in watch mode (developmentconfig)npm test- run Karma unit tests
src/
app/
components/ # feature/demo components rendered by AppComponent
shared/ # reusable UI components (card, dropdown)
assets/
i18n/ # translation JSON files for each supported language
- The app is bootstrapped with
bootstrapApplicationinsrc/main.ts. AppComponentmanages the selected language, current user name, derived display data, and document text direction.- Runtime translation is configured in
src/app/app.config.tsusingprovideTranslateServiceandprovideTranslateHttpLoader. - Router is configured, but
src/app/app.routes.tscurrently exports an empty route array. - The page is split into standalone components for readability:
translation-previewlanguage-controlshow-it-works
Translation files live in src/assets/i18n:
messages.en.jsonmessages.fr.jsonmessages.es.jsonmessages.de.jsonmessages.hi.jsonmessages.ar.jsonmessages.zh.json
The app loads files using this pattern:
messages.<lang>.json
Current demo keys:
greetingwelcome
From src/app/app.component.html:
translation-preview- shows translated greeting and personalized welcome outputlanguage-controls- updates the user name, switches the active language, and displays locale plus text directionhow-it-works- explains runtime translation flow, shows current JSON values, and demonstrates interpolation
Defined in src/app/shared:
app-card- reusable projected card layout for each demo sectionapp-dropdown- custom language selector used by the controls card
- The app uses runtime translation with
ngx-translate, not Angular build-time@angular/localize. - The selected language is initialized from the browser locale when supported, otherwise it falls back to English.
- The entered user name is stored in
localStorageand restored on reload. - Arabic switches the document direction to RTL; other languages use LTR.
- The explanatory JSON snippet in the UI is derived from component state so the demo remains easy to follow.
