From 00209ce1370d9f80e2dbaa5c4cd75c4e44504561 Mon Sep 17 00:00:00 2001 From: Gabriel De Los Rios Date: Tue, 20 Jan 2026 22:54:08 -0300 Subject: [PATCH] build: add i18n support --- package-lock.json | 28 ++++++++++++++++++++++++++++ package.json | 4 +++- public/i18n/en.json | 0 public/i18n/es.json | 0 public/i18n/pt.json | 0 src/app/app.config.ts | 10 ++++++++++ src/app/app.ts | 12 ++++++++++-- 7 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 public/i18n/en.json create mode 100644 public/i18n/es.json create mode 100644 public/i18n/pt.json diff --git a/package-lock.json b/package-lock.json index a4bbc6b..4748760 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,6 +17,8 @@ "@angular/platform-browser": "^21.0.0", "@angular/router": "^21.0.0", "@angular/service-worker": "^21.0.6", + "@ngx-translate/core": "^17.0.0", + "@ngx-translate/http-loader": "^17.0.0", "angular-web-sqlite": "^1.0.34", "rxjs": "~7.8.0", "tslib": "^2.3.0" @@ -2698,6 +2700,32 @@ "@tybys/wasm-util": "^0.10.1" } }, + "node_modules/@ngx-translate/core": { + "version": "17.0.0", + "resolved": "https://registry.npmjs.org/@ngx-translate/core/-/core-17.0.0.tgz", + "integrity": "sha512-Rft2D5ns2pq4orLZjEtx1uhNuEBerUdpFUG1IcqtGuipj6SavgB8SkxtNQALNDA+EVlvsNCCjC2ewZVtUeN6rg==", + "license": "MIT", + "dependencies": { + "tslib": "^2.3.0" + }, + "peerDependencies": { + "@angular/common": ">=16", + "@angular/core": ">=16" + } + }, + "node_modules/@ngx-translate/http-loader": { + "version": "17.0.0", + "resolved": "https://registry.npmjs.org/@ngx-translate/http-loader/-/http-loader-17.0.0.tgz", + "integrity": "sha512-hgS8sa0ARjH9ll3PhkLTufeVXNI2DNR2uFKDhBgq13siUXzzVr/a31M6zgecrtwbA34iaBV01hsTMbMS8V7iIw==", + "license": "MIT", + "dependencies": { + "tslib": "^2.3.0" + }, + "peerDependencies": { + "@angular/common": ">=16", + "@angular/core": ">=16" + } + }, "node_modules/@npmcli/agent": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/@npmcli/agent/-/agent-4.0.0.tgz", diff --git a/package.json b/package.json index 2a38b8f..32da7bf 100644 --- a/package.json +++ b/package.json @@ -32,6 +32,8 @@ "@angular/platform-browser": "^21.0.0", "@angular/router": "^21.0.0", "@angular/service-worker": "^21.0.6", + "@ngx-translate/core": "^17.0.0", + "@ngx-translate/http-loader": "^17.0.0", "angular-web-sqlite": "^1.0.34", "rxjs": "~7.8.0", "tslib": "^2.3.0" @@ -45,4 +47,4 @@ "typescript": "~5.9.2", "vitest": "^4.0.8" } -} \ No newline at end of file +} diff --git a/public/i18n/en.json b/public/i18n/en.json new file mode 100644 index 0000000..e69de29 diff --git a/public/i18n/es.json b/public/i18n/es.json new file mode 100644 index 0000000..e69de29 diff --git a/public/i18n/pt.json b/public/i18n/pt.json new file mode 100644 index 0000000..e69de29 diff --git a/src/app/app.config.ts b/src/app/app.config.ts index 670fcd3..b4e023b 100644 --- a/src/app/app.config.ts +++ b/src/app/app.config.ts @@ -11,6 +11,8 @@ import { WebSqlite } from 'angular-web-sqlite'; import { Sqlite } from './services/sqlite'; import { tables } from '../migrations/20260117'; import { provideServiceWorker } from '@angular/service-worker'; +import {provideTranslateService } from "@ngx-translate/core"; +import {provideTranslateHttpLoader} from "@ngx-translate/http-loader"; export const appConfig: ApplicationConfig = { providers: [ @@ -28,5 +30,13 @@ export const appConfig: ApplicationConfig = { enabled: !isDevMode(), registrationStrategy: 'registerWhenStable:30000', }), + provideTranslateService({ + loader: provideTranslateHttpLoader({ + prefix: '/i18n/', + suffix: '.json' + }), + fallbackLang: 'en', + lang: 'en' + }) ], }; diff --git a/src/app/app.ts b/src/app/app.ts index 242caa2..e33cf3e 100644 --- a/src/app/app.ts +++ b/src/app/app.ts @@ -1,5 +1,6 @@ -import { Component } from '@angular/core'; +import { Component, inject } from '@angular/core'; import { RouterOutlet } from '@angular/router'; +import { TranslateService } from '@ngx-translate/core'; @Component({ selector: 'app-root', @@ -7,4 +8,11 @@ import { RouterOutlet } from '@angular/router'; templateUrl: './app.html', styles: [], }) -export class App {} +export class App { + private readonly translate = inject(TranslateService); + constructor() { + this.translate.addLangs(['en', 'es', 'pt']); + this.translate.setFallbackLang('en'); + this.translate.use('en'); + } +}