From c349737aecca7a14c553ae9b8475e2770d85bf75 Mon Sep 17 00:00:00 2001 From: Kai Niebes Date: Tue, 10 Nov 2026 08:24:21 +0100 Subject: [PATCH 1/5] Introduce ngx-fluent for translations based on Fluent --- bun.lock | 23 ++- extract-translations.ts | 94 ------------- package.json | 5 +- src/app/app.config.ts | 12 +- src/app/app.fluent-sources.ts | 15 ++ .../actionbar/actionbar.component.html | 54 +++---- .../actionbar/actionbar.component.ts | 4 +- .../combined-form-errors.component.html | 2 +- .../combined-form-errors.component.ts | 5 +- .../compilation-detail.component.html | 20 +-- .../compilation-detail.component.ts | 13 +- .../detail-entity.component.html | 34 ++--- .../detail-entity/detail-entity.component.ts | 4 +- .../detail-institution.component.html | 4 +- .../detail-institution.component.ts | 7 +- .../detail-person.component.html | 4 +- .../detail-person/detail-person.component.ts | 7 +- .../entity-detail/entity-detail.component.ts | 14 +- .../grid-element/grid-element.component.html | 4 +- .../grid-element/grid-element.component.ts | 4 +- .../language-dropdown.component.html | 2 +- .../language-dropdown.component.ts | 29 ++-- .../metadata/address/address.component.html | 24 ++-- .../metadata/address/address.component.ts | 4 +- .../metadata/agents/agents.component.html | 52 +++---- .../metadata/agents/agents.component.ts | 4 +- .../metadata/entity/entity.component.html | 26 ++-- .../metadata/entity/entity.component.ts | 4 +- .../metadata/general/general.component.html | 20 +-- .../metadata/general/general.component.ts | 4 +- .../metadata/licence/licence.component.html | 14 +- .../metadata/licence/licence.component.ts | 4 +- .../biblio-ref/biblio-ref.component.html | 18 +-- .../biblio-ref/biblio-ref.component.ts | 4 +- .../optional/creation/creation.component.html | 12 +- .../optional/creation/creation.component.ts | 4 +- .../dimension/dimension.component.html | 16 +-- .../optional/dimension/dimension.component.ts | 4 +- .../external-ids/external-ids.component.html | 12 +- .../external-ids/external-ids.component.ts | 4 +- .../optional/links/links.component.html | 12 +- .../optional/links/links.component.ts | 4 +- .../metadata-files.component.html | 6 +- .../metadata-files.component.ts | 4 +- .../optional/phys-obj/phys-obj.component.html | 12 +- .../optional/phys-obj/phys-obj.component.ts | 4 +- .../navigation/footer/footer.component.html | 14 +- .../navigation/footer/footer.component.ts | 7 +- .../navigation/navbar/navbar.component.html | 28 ++-- .../navigation/navbar/navbar.component.ts | 4 +- .../sidenav-list/sidenav-list.component.html | 18 +-- .../sidenav-list/sidenav-list.component.ts | 4 +- .../news-card/news-card.component.html | 4 +- .../news-card/news-card.component.ts | 7 +- .../notification-area.component.html | 2 +- .../notification-area.component.ts | 4 +- .../outlined-input.component.html | 8 +- .../outlined-input.component.ts | 4 +- .../pagination/pagination.component.html | 6 +- .../pagination/pagination.component.ts | 4 +- .../search-bar/search-bar.component.html | 2 +- .../search-bar/search-bar.component.ts | 4 +- .../selection-tab.component.html | 4 +- .../selection-tab/selection-tab.component.ts | 4 +- .../sidenav-container.component.html | 2 +- .../sidenav-container.component.ts | 4 +- src/app/components/tabs/tabs.component.html | 2 +- src/app/components/tabs/tabs.component.ts | 4 +- .../components/upload/upload.component.html | 58 ++++---- src/app/components/upload/upload.component.ts | 4 +- .../uploaded-by/uploaded-by.component.html | 4 +- .../uploaded-by/uploaded-by.component.ts | 15 +- .../add-to-compilation.component.html | 26 ++-- .../add-to-compilation.component.ts | 4 +- .../auth-dialog/auth-dialog.component.html | 16 +-- .../auth-dialog/auth-dialog.component.ts | 4 +- .../confirmation-dialog.component.html | 6 +- .../confirmation-dialog.component.ts | 7 +- .../create-or-edit-compilation.component.html | 16 +-- .../create-or-edit-compilation.component.ts | 4 +- .../create-new-entity.component.html | 74 +++++----- .../create-new-entity.component.ts | 4 +- .../embed-object-dialog.component.html | 6 +- .../embed-object-dialog.component.ts | 7 +- .../entity-download-dialog.component.html | 34 ++--- .../entity-download-dialog.component.ts | 4 +- .../forgot-password-dialog.component.html | 8 +- .../forgot-password-dialog.component.ts | 4 +- .../forgot-username-dialog.component.html | 6 +- .../forgot-username-dialog.component.ts | 4 +- .../manage-ownership.component.html | 30 ++-- .../manage-ownership.component.ts | 4 +- .../news-dialog/news-dialog.component.html | 12 +- .../news-dialog/news-dialog.component.ts | 4 +- .../profile-page-edit.component.html | 26 ++-- .../profile-page-edit.component.ts | 4 +- .../register-dialog.component.html | 20 +-- .../register-dialog.component.ts | 4 +- .../remove-from-compilation.component.html | 8 +- .../remove-from-compilation.component.ts | 4 +- .../reset-password-dialog.component.html | 4 +- .../reset-password-dialog.component.ts | 4 +- ...isibility-and-access-dialog.component.html | 22 +-- .../visibility-and-access-dialog.component.ts | 4 +- .../admin-page/admin-page.component.html | 132 +++++++++--------- .../pages/admin-page/admin-page.component.ts | 4 +- src/app/pages/annotate/annotate.component.ts | 6 +- .../detail-page/detail-page.component.html | 6 +- .../detail-page/detail-page.component.ts | 4 +- .../explore-filter-option.component.html | 8 +- .../explore-filter-option.component.ts | 4 +- .../explore-filter-sidenav.component.html | 4 +- .../explore-filter-sidenav.component.ts | 4 +- src/app/pages/explore/explore.component.html | 38 ++--- src/app/pages/explore/explore.component.ts | 4 +- src/app/pages/home/home.component.html | 46 ++---- src/app/pages/home/home.component.ts | 10 +- .../pages/notfound/notfound.component.html | 2 +- src/app/pages/notfound/notfound.component.ts | 4 +- .../compilations/compilations.component.html | 32 ++--- .../compilations/compilations.component.ts | 4 +- .../entities/entities.component.html | 40 +++--- .../entities/entities.component.ts | 4 +- .../profile-page-header.component.html | 4 +- .../profile-page-header.component.ts | 9 +- .../profile-page-help.component.html | 8 +- .../profile-page-help.component.ts | 4 +- .../profile-page/profile-page.component.html | 6 +- .../profile-page/profile-page.component.ts | 4 +- .../profile-public-view.component.html | 6 +- .../profile-public-view.component.ts | 4 +- .../static-pages/about/about.component.ts | 6 +- .../static-pages/imprint/imprint.component.ts | 6 +- .../privacy/privacy.component.html | 54 +++---- .../static-pages/privacy/privacy.component.ts | 11 +- src/app/pipes/translate.pipe.ts | 8 +- src/app/services/translate.service.ts | 105 -------------- src/assets/i18n/de.ftl | 2 + src/assets/i18n/en.ftl | 13 ++ 139 files changed, 854 insertions(+), 989 deletions(-) delete mode 100644 extract-translations.ts create mode 100644 src/app/app.fluent-sources.ts create mode 100644 src/assets/i18n/de.ftl create mode 100644 src/assets/i18n/en.ftl diff --git a/bun.lock b/bun.lock index 434457ca..1a327253 100644 --- a/bun.lock +++ b/bun.lock @@ -15,6 +15,8 @@ "@angular/platform-browser": "22.2.3", "@angular/platform-browser-dynamic": "22.2.3", "@angular/router": "22.2.3", + "@apappas1129/ngx-fluent": "^22.0.3", + "@fluent/bundle": "^0.19.1", "@kompakkt/common": "git+https://github.com/Kompakkt/Common.git#1ff4f862a5464d8cd236755a900f3722202552a9", "@kompakkt/komponents": "git+https://github.com/Kompakkt/Komponents.git#7d4ad1ec8fa03e09ead55bbf667afea5db97f9f7", "@kompakkt/plugins": "git+https://github.com/Kompakkt/Plugins.git#4e2c0f4665f01be50104df4417cc08c5bb97bbba", @@ -42,6 +44,7 @@ "@types/pluralize": "^0.0.33", "@types/spark-md5": "^3.0.5", "concurrently": "^9.2.1", + "ngx-fluent-cli": "https://github.com/HeyItsBATMAN/ngx-fluent-cli", "oxlint": "^1.57.0", "oxlint-tsgolint": "^0.18.1", "ts-node": "~10.9.2", @@ -51,6 +54,8 @@ }, }, "trustedDependencies": [ + "tree-sitter-angular", + "tree-sitter", "@kompakkt/common", "@kompakkt/plugins", ], @@ -104,6 +109,8 @@ "@angular/router": ["@angular/router@22.2.3", "", { "dependencies": { "tslib": "^2.3.0" }, "peerDependencies": { "@angular/common": "22.2.3", "@angular/core": "22.2.3", "@angular/platform-browser": "22.2.3", "rxjs": "^6.5.3 || ^7.4.0" } }, "sha512-h4C3iJ3OXM9HItErmTo9fFrFRDj1DSqbvweHAWl8eYJvyuhDD80gBNgdpN8/5gpt9K1HV+PXk0YbyjyQ0zMfPA=="], + "@apappas1129/ngx-fluent": ["@apappas1129/ngx-fluent@22.0.3", "", { "dependencies": { "tslib": "^2.6.2" }, "peerDependencies": { "@angular/common": "^22.0.0", "@angular/core": "^22.0.0", "@fluent/bundle": ">= 0.18.0 < 1.0.0" } }, "sha512-u9aRuRANJlwDNsBus9MkY4lXpDEDVXeJN5+Eaw4VWwZEGorZNWcqulk5sN0+rMogXitdpaGVu47s1gSr/BcQ0A=="], + "@babel/code-frame": ["@babel/code-frame@8.0.6", "", { "dependencies": { "@babel/helper-validator-identifier": "^8.0.6", "js-tokens": "^10.0.0" } }, "sha512-uMHhvmDmwFiLuiozaoRYTZHqMFuu3fem/X9JY78lohAuLoh8LSGGC8JqUzo2cVuBsBxkjMZNk56CE7ock8Xxkw=="], "@babel/compat-data": ["@babel/compat-data@8.0.5", "", {}, "sha512-YLsYoQMvL8l8WrGpN3Zj7O1wK5LEBN+cQtux7BcuHyxIXve724XG+zuJ1n3U1cUweRtTzQOA4IHbuQw3N34SZw=="], @@ -348,6 +355,8 @@ "@esbuild/win32-x64": ["@esbuild/win32-x64@0.28.2", "", { "os": "win32", "cpu": "x64" }, "sha512-5ebpxr3nWMzrL/rnUI755Jkuee0bHL/Gq0WTF9lvcpv73wAp5eu8MfBUgWK9bhWvZjj7yX8etf/8tI8Ney695g=="], + "@fluent/bundle": ["@fluent/bundle@0.19.1", "", {}, "sha512-SWJLZrPamDPsJlFFOW1nkgN0j0rbPbmSdmK0XAoXlyqKieLtMVl4vzng3aR5pwKoUx0scug8+YY2oct3fdfy9A=="], + "@hapi/address": ["@hapi/address@5.1.1", "", { "dependencies": { "@hapi/hoek": "^11.0.2" } }, "sha512-A+po2d/dVoY7cYajycYI43ZbYMXukuopIsqCjh5QzsBCipDtdofHntljDlpccMjIfTy6UOkg+5KPriwYch2bXA=="], "@hapi/formula": ["@hapi/formula@3.0.2", "", {}, "sha512-hY5YPNXzw1He7s0iqkRQi+uMGh383CGdyyIGYtB+W5N3KHPXoqychklvHhKCC9M3Xtv0OCs/IHw+r4dcHtBYWw=="], @@ -1296,7 +1305,11 @@ "negotiator": ["negotiator@0.6.4", "", {}, "sha512-myRT3DiWPHqho5PrJaIRyaMv2kgYf0mUVgBNOYMuCH5Ki1yEiQaf/ZJuQ62nvpc44wL5WDbTX7yGJi1Neevw8w=="], - "node-addon-api": ["node-addon-api@6.1.0", "", {}, "sha512-+eawOlIgy680F0kBzPUNFhMZGtJ1YmqM6l4+Crf4IkImjYrO/mqPwRMh352g23uIaQKFItcQ64I7KMaJxHgAVA=="], + "ngx-fluent-cli": ["ngx-fluent-cli@github:HeyItsBATMAN/ngx-fluent-cli#cd7749e", { "dependencies": { "@fluent/bundle": "^0.19.1", "tree-sitter": "^0.25.1", "tree-sitter-angular": "^0.9.2" }, "bin": { "ngx-fluent-cli": "./index.ts" } }, "HeyItsBATMAN-ngx-fluent-cli-cd7749e", "sha512-gd3W2mfiAtnmtgX7w1Yb29GTD0+TqwtM4ELJ3r+1lZTgh4i+R6g7BGaK4J3sj9Z1/GKak0zT4VjKXl6rGOXfuQ=="], + + "node-addon-api": ["node-addon-api@8.9.2", "", {}, "sha512-VijLXbi3UACN69I0JVXJsX4tjACjNoQDgv2gTF6sx2wWEi8tkSg2eX8p5gSIFi8z2+DL3oHmY6OyKce38SDolg=="], + + "node-gyp-build": ["node-gyp-build@4.8.4", "", { "bin": { "node-gyp-build": "bin.js", "node-gyp-build-optional": "optional.js", "node-gyp-build-test": "build-test.js" } }, "sha512-LA4ZjwlnUblHVgq0oBF3Jl/6h/Nvs5fzBLwdEF4nuxnFdsfajde4WfxtJr3CaiH+F6ewcIB/q4jQ4UzPyid+CQ=="], "node-gyp-build-optional-packages": ["node-gyp-build-optional-packages@5.2.2", "", { "dependencies": { "detect-libc": "^2.0.1" }, "bin": { "node-gyp-build-optional-packages": "bin.js", "node-gyp-build-optional-packages-optional": "optional.js", "node-gyp-build-optional-packages-test": "build-test.js" } }, "sha512-s+w+rBWnpTMwSFbaE0UXsRlg7hU4FjekKU4eyAih5T8nJuNZT1nNsskXpxmeqSK9UzkBl6UgRlnKc8hz8IEqOw=="], @@ -1576,6 +1589,12 @@ "tree-kill": ["tree-kill@1.2.2", "", { "bin": { "tree-kill": "cli.js" } }, "sha512-L0Orpi8qGpRG//Nd+H90vFB+3iHnue1zSSGmNOOCh1GLJ7rUKVwV2HvijphGQS2UmhUZewS9VgvxYIdgr+fG1A=="], + "tree-sitter": ["tree-sitter@0.25.1", "", { "dependencies": { "node-addon-api": "^8.5.0", "node-gyp-build": "^4.8.4" }, "hasInstallScript": true }, "sha512-mrcEdkYtHfrK1A6fs3O6FxkBo0Qig5XUXqHhxUOQu0bmPo00QF4XaSx4edpazdHwxnSCjlGKGgIqWdaN4dvTLA=="], + + "tree-sitter-angular": ["tree-sitter-angular@0.9.2", "", { "dependencies": { "node-addon-api": "^8.2.2", "node-gyp-build": "^4.8.2", "tree-sitter-html": "^0.23.2" }, "peerDependencies": { "tree-sitter": "^0.21.1", "tree_sitter": "*" }, "optionalPeers": ["tree_sitter"], "hasInstallScript": true }, "sha512-jaC4JFZ2M1t25qlt23DeqLlGbi8mh80It0ZuTXg6OJo8yi24fZiMuNTKkb40av/g6V1RRp6nWrYPE4S6ISbgqg=="], + + "tree-sitter-html": ["tree-sitter-html@0.23.2", "", { "dependencies": { "node-addon-api": "^8.2.2", "node-gyp-build": "^4.8.2" }, "peerDependencies": { "tree-sitter": "^0.21.1" }, "optionalPeers": ["tree-sitter"], "hasInstallScript": true }, "sha512-TN+l+7cCeLx9db/1RhRSqMAZO/266Oh2BHb8J8hMSSFLuzYvFTYP/UnD3S0mny5awzw05KzFNgu2vnwzN9wVJg=="], + "ts-node": ["ts-node@10.9.2", "", { "dependencies": { "@cspotcode/source-map-support": "^0.8.0", "@tsconfig/node10": "^1.0.7", "@tsconfig/node12": "^1.0.7", "@tsconfig/node14": "^1.0.0", "@tsconfig/node16": "^1.0.2", "acorn": "^8.4.1", "acorn-walk": "^8.1.1", "arg": "^4.1.0", "create-require": "^1.1.0", "diff": "^4.0.1", "make-error": "^1.1.1", "v8-compile-cache-lib": "^3.0.1", "yn": "3.1.1" }, "peerDependencies": { "@swc/core": ">=1.2.50", "@swc/wasm": ">=1.2.50", "@types/node": "*", "typescript": ">=2.7" }, "optionalPeers": ["@swc/core", "@swc/wasm"], "bin": { "ts-node": "dist/bin.js", "ts-script": "dist/bin-script-deprecated.js", "ts-node-cwd": "dist/bin-cwd.js", "ts-node-esm": "dist/bin-esm.js", "ts-node-script": "dist/bin-script.js", "ts-node-transpile-only": "dist/bin-transpile.js" } }, "sha512-f0FFpIdcHgn8zcPSbf1dRevwt047YMnaiJM3u2w2RewrB+fob/zePZcrOyQoLMMO7aBIddLcQIEK5dYjkLnGrQ=="], "tslib": ["tslib@2.8.1", "", {}, "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w=="], @@ -1776,6 +1795,8 @@ "less/source-map": ["source-map@0.6.1", "", {}, "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g=="], + "lmdb/node-addon-api": ["node-addon-api@6.1.0", "", {}, "sha512-+eawOlIgy680F0kBzPUNFhMZGtJ1YmqM6l4+Crf4IkImjYrO/mqPwRMh352g23uIaQKFItcQ64I7KMaJxHgAVA=="], + "micromatch/picomatch": ["picomatch@2.3.2", "", {}, "sha512-V7+vQEJ06Z+c5tSye8S+nHUfI51xoXIXjHQ99cQtKUkQqqO1kO/KCJUfZXuB47h/YBlDhah2H3hdUGXn8ie0oA=="], "minimizer-webpack-plugin/schema-utils": ["schema-utils@4.8.1", "", { "dependencies": { "@types/json-schema": "^7.0.15", "ajv": "^8.20.0", "ajv-formats": "^3.0.1", "ajv-keywords": "^5.1.0" }, "peerDependencies": { "webpack": "^5.112.0" }, "optionalPeers": ["webpack"], "bin": { "schema-utils": "bin/schema-utils.js" } }, "sha512-x39pYlJPyH7Uge5QO64B9XGP9zLDc9WNmiQZc+CE3IzZPvMu3lHOuAMGpYNoPixEL7MSWlGhYTg5UlLSL8G6iw=="], diff --git a/extract-translations.ts b/extract-translations.ts deleted file mode 100644 index 69c5db41..00000000 --- a/extract-translations.ts +++ /dev/null @@ -1,94 +0,0 @@ -import { readdir, readFile, stat, writeFile } from 'fs/promises'; -import { extname, join } from 'path'; - -const translateRegex = /\{\{\s*([^{|]+?)(?:\s*\|\s*translate\s*\}\})/gs; -const ternaryRegex = /([\?:]\s?('.+')){1,2}/gs; -const appPath = join(__dirname, 'src', 'app'); -const i18nPath = join(__dirname, 'src', 'assets', 'i18n'); -const languages = ['en', 'mn', 'de', 'fr', 'it', 'es']; - -const removeApostrophe = (str: string) => { - if (str[0] === "'" && str[str.length - 1] === "'") { - return str.substring(1, str.length - 1); - } - return str; -}; - -const extractTranslationsFromFile = async (file: string): Promise => { - const translations = new Array(); - const content = await readFile(file, 'utf8'); - let match; - while ((match = translateRegex.exec(content))) { - const capture = match[1] - .split(/[\n\r]/) - .map(line => line.trim()) - .join(' '); - const ternaryMatch = ternaryRegex.exec(capture); - if (ternaryMatch) { - const ternaryCaptures = ternaryMatch[2].split(':').map(line => line.trim()); - translations.push(...ternaryCaptures); - } else { - translations.push(capture); - } - } - return translations.map(removeApostrophe); -}; - -const aggregateFilePaths = async (directory: string): Promise => { - const files = await readdir(directory); - const filePaths = new Array(); - for (const file of files) { - const path = join(directory, file); - const pathStat = await stat(path); - if (pathStat.isDirectory()) { - filePaths.push(...(await aggregateFilePaths(join(directory, file)))); - } else if (extname(file) === '.html') { - filePaths.push(path); - } - } - return filePaths; -}; - -const fileExists = async (path: string) => { - try { - await stat(path); - return true; - } catch (e) { - return false; - } -}; - -const combineTranslations = async (translations: string[]) => { - const translateObj: Record = {}; - for (const translation of translations) { - translateObj[translation] = translation; - } - - for (const language of languages) { - const path = join(i18nPath, `${language}.json`); - if (!(await fileExists(path))) { - await writeFile(path, JSON.stringify(translateObj, null, 2)); - continue; - } - const content = await readFile(path, 'utf8'); - const parsedContent = JSON.parse(content); - for (const key of Object.keys(translateObj)) { - if (!parsedContent[key]) { - parsedContent[key] = translateObj[key]; - } - } - await writeFile(path, JSON.stringify(parsedContent, null, 2)); - } -}; - -(async () => { - const paths = await aggregateFilePaths(appPath); - const translations = await Promise.all(paths.flatMap(extractTranslationsFromFile)); - const uniqueTranslations = Array.from(new Set(translations.flat())); - const sortedTranslations = uniqueTranslations.sort((a, b) => a.localeCompare(b)); - console.log( - `Found ${translations.flat().length}, unique ${sortedTranslations.length} translation strings`, - ); - await combineTranslations(sortedTranslations); - console.log(`Wrote translations for ${languages.length} languages: ${languages.join(', ')}`); -})(); diff --git a/package.json b/package.json index 2ccf74d5..e7d89771 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ "update:kompakkt:server-openapi": "bun run update-git-dependency.ts -d @kompakkt/server-openapi -o Kompakkt -r Server -b openapi-types", "e2e": "concurrently \"ng serve --port 1503\" \"wait-on http-get://localhost:1503 && npm run cy:run\" --kill-others --success first", "e2e-gui": "concurrently \"ng serve --port 1503\" \"wait-on http-get://localhost:1503 && npm run cy:open\" --kill-others --success first", - "extract-translations": "ts-node --skipProject ./extract-translations.ts" + "i18n:verify": "bun run ngx-fluent-cli --fluent-file-dir ./src/assets/i18n" }, "contributors": [ { @@ -52,6 +52,8 @@ "@angular/platform-browser": "22.2.3", "@angular/platform-browser-dynamic": "22.2.3", "@angular/router": "22.2.3", + "@apappas1129/ngx-fluent": "^22.0.3", + "@fluent/bundle": "^0.19.1", "@kompakkt/common": "git+https://github.com/Kompakkt/Common.git#1ff4f862a5464d8cd236755a900f3722202552a9", "@kompakkt/komponents": "git+https://github.com/Kompakkt/Komponents.git#7d4ad1ec8fa03e09ead55bbf667afea5db97f9f7", "@kompakkt/plugins": "git+https://github.com/Kompakkt/Plugins.git#4e2c0f4665f01be50104df4417cc08c5bb97bbba", @@ -79,6 +81,7 @@ "@types/pluralize": "^0.0.33", "@types/spark-md5": "^3.0.5", "concurrently": "^9.2.1", + "ngx-fluent-cli": "https://github.com/HeyItsBATMAN/ngx-fluent-cli", "oxlint": "^1.57.0", "oxlint-tsgolint": "^0.18.1", "ts-node": "~10.9.2", diff --git a/src/app/app.config.ts b/src/app/app.config.ts index ec227fbd..803526fe 100644 --- a/src/app/app.config.ts +++ b/src/app/app.config.ts @@ -5,8 +5,6 @@ import { ApplicationConfig, LOCALE_ID, importProvidersFrom, - inject, - provideAppInitializer, } from '@angular/core'; import { MatAutocompleteModule } from '@angular/material/autocomplete'; import { MatButtonModule } from '@angular/material/button'; @@ -43,15 +41,16 @@ import { withRouterConfig, withRouterResources, } from '@angular/router'; -import { TranslatePipe } from 'src/app/pipes/translate.pipe'; +import { NgxFluentPipe } from '@apappas1129/ngx-fluent'; import { RouteReuse } from 'src/app/route-reuse-strategy'; import { exploreTimingInterceptor } from 'src/app/services/interceptors/explore-timing-interceptor'; import { httpErrorInterceptor } from 'src/app/services/interceptors/http-error-interceptor'; import { httpOptionsInterceptor } from 'src/app/services/interceptors/http-options-interceptor'; import { jwtInterceptor } from './services/interceptors/jwt-interceptor'; -import { TranslateService } from 'src/app/services/translate.service'; import { pluginProviders } from './app.plugin'; import { routes } from './app.routes'; +import { provideNgxFluent } from '@apappas1129/ngx-fluent'; +import { languageSources } from './app.fluent-sources'; export const appConfig: ApplicationConfig = { providers: [ @@ -86,8 +85,7 @@ export const appConfig: ApplicationConfig = { MatProgressBarModule, MatSortModule, ), - TranslateService, - TranslatePipe, + NgxFluentPipe, { provide: RouteReuseStrategy, useClass: RouteReuse }, provideRouter( routes, @@ -95,7 +93,7 @@ export const appConfig: ApplicationConfig = { withComponentInputBinding(), withRouterResources(), ), - provideAppInitializer(() => inject(TranslateService).requestLanguage('en')), + provideNgxFluent({ defaultLocale: 'en', sources: languageSources }), { provide: DATE_PIPE_DEFAULT_OPTIONS, useValue: { dateFormat: 'full' } }, { provide: LOCALE_ID, useValue: 'en-US' }, provideAnimations(), diff --git a/src/app/app.fluent-sources.ts b/src/app/app.fluent-sources.ts new file mode 100644 index 00000000..9cc51db0 --- /dev/null +++ b/src/app/app.fluent-sources.ts @@ -0,0 +1,15 @@ +export const languageNames = { + en: 'English', + de: 'Deutsch (German)', + fr: 'Français (French)', + it: 'Italiano (Italian)', + es: 'Español (Spanish)', + mn: 'монгол хэл (Mongolian)', +} as const; + +export type LanguageKey = keyof typeof languageNames; + +export const languageSources = { + en: 'assets/i18n/en.ftl', + de: 'assets/i18n/de.ftl', +} as const satisfies Partial>; diff --git a/src/app/components/actionbar/actionbar.component.html b/src/app/components/actionbar/actionbar.component.html index 4041f5b3..2470331b 100644 --- a/src/app/components/actionbar/actionbar.component.html +++ b/src/app/components/actionbar/actionbar.component.html @@ -8,7 +8,7 @@ color="primary" [matTooltip]=" (isPublished() ? 'Published. Click to unpublish!' : 'Not public. Click to publish!') - | translate + | fluent " [disabled]="isUpdatingPublishState()" (click)="togglePublished()" @@ -16,17 +16,17 @@ @if (isUpdatingPublishState()) { - {{ 'Updating' | translate }}... + {{ 'Updating' | fluent }}... } @else if (isPublished()) { flip_to_back - {{ 'Unpublish' | translate }} + {{ 'Unpublish' | fluent }} } @else { publish - {{ 'Publish!' | translate }} + {{ 'Publish!' | fluent }} } @@ -38,14 +38,14 @@
} @else if (isDetailPage()) {
} @@ -64,8 +64,8 @@
@@ -111,7 +111,7 @@ (selectHistory.usedInCompilations.compilations.length === 0 ? 'This object is not used in any collection.' : 'Explore collections containing this object.' - ) | translate + ) | fluent " >
} @@ -171,7 +171,7 @@ > } @@ -182,17 +182,17 @@ } -
+
@@ -200,17 +200,17 @@ @for (compilation of selectHistory.usedInCompilations.compilations; track compilation._id) { } @if (canEditMetadata()) { } @if (isFinished() && canTransferOwnership()) { } } @@ -260,7 +260,7 @@

{{ compilationDescription() }}

{{ entityCount() }} - {{ 'objects' | translate }} + {{ 'objects' | fluent }}

{{ 'Creator: ' }} diff --git a/src/app/components/actionbar/actionbar.component.ts b/src/app/components/actionbar/actionbar.component.ts index 01315574..8b41cfc8 100644 --- a/src/app/components/actionbar/actionbar.component.ts +++ b/src/app/components/actionbar/actionbar.component.ts @@ -22,7 +22,7 @@ import { } from '@kompakkt/common'; import { IsCompilationPipe } from 'src/app/pipes/is-compilation.pipe'; import { IsEntityPipe } from 'src/app/pipes/is-entity.pipe'; -import { TranslatePipe } from '../../pipes/translate.pipe'; +import { NgxFluentPipe } from '@apappas1129/ngx-fluent'; import { MatProgressSpinnerModule } from '@angular/material/progress-spinner'; import { OverlayModule } from '@angular/cdk/overlay'; import { PermissionService } from 'src/app/services/permissions.service'; @@ -50,7 +50,7 @@ import { SelectHistoryService } from 'src/app/services/select-history.service'; OverlayModule, RouterLink, MatMenuModule, - TranslatePipe, + NgxFluentPipe, IsCompilationPipe, IsEntityPipe, ], diff --git a/src/app/components/combined-form-errors/combined-form-errors.component.html b/src/app/components/combined-form-errors/combined-form-errors.component.html index c86d3c1e..b34e0c07 100644 --- a/src/app/components/combined-form-errors/combined-form-errors.component.html +++ b/src/app/components/combined-form-errors/combined-form-errors.component.html @@ -2,7 +2,7 @@ @if (error.fieldTree().touched()) { @if (error.message; as message) {

- {{ message | translate }} + {{ message | fluent }}
} } diff --git a/src/app/components/combined-form-errors/combined-form-errors.component.ts b/src/app/components/combined-form-errors/combined-form-errors.component.ts index 1ba08cac..1b14a825 100644 --- a/src/app/components/combined-form-errors/combined-form-errors.component.ts +++ b/src/app/components/combined-form-errors/combined-form-errors.component.ts @@ -1,9 +1,10 @@ import { Component, computed, input } from '@angular/core'; import { FieldTree } from '@angular/forms/signals'; -import { TranslatePipe } from 'src/app/pipes/translate.pipe'; +import { filter } from 'rxjs'; +import { NgxFluentPipe } from '@apappas1129/ngx-fluent'; @Component({ - imports: [TranslatePipe], + imports: [NgxFluentPipe], selector: 'app-combined-form-errors', styleUrl: './combined-form-errors.component.scss', templateUrl: './combined-form-errors.component.html', diff --git a/src/app/components/compilation-detail/compilation-detail.component.html b/src/app/components/compilation-detail/compilation-detail.component.html index 40dd624a..1567b46f 100644 --- a/src/app/components/compilation-detail/compilation-detail.component.html +++ b/src/app/components/compilation-detail/compilation-detail.component.html @@ -4,16 +4,16 @@

{{ compilation.name }}

{{ compilation.description }}

-

{{ 'Collection information' | translate }}

+

{{ 'Collection information' | fluent }}

- {{ 'Contains' | translate }} {{ entityCount() }} - {{ 'objects across the following types:' | translate }} + {{ 'Contains' | fluent }} {{ entityCount() }} + {{ 'objects across the following types:' | fluent }}

-
image
-
language
-
audiotrack
-
movie
+
image
+
language
+
audiotrack
+
movie
{{ imageCount() }} {{ modelCount() }} {{ audioCount() }} @@ -21,15 +21,15 @@

{{ 'Collection information' | translate }}


- {{ 'Total annotations' | translate }} + {{ 'Total annotations' | fluent }} more {{ annotationCount() }}
@if (entityCount() > 0) {
-

{{ 'Collection objects' | translate }}

- {{ 'Objects in this collection:' | translate }} +

{{ 'Collection objects' | fluent }}

+ {{ 'Objects in this collection:' | fluent }}
@for (entity of entities(); track entity._id) { @if (entity.finished) { diff --git a/src/app/components/compilation-detail/compilation-detail.component.ts b/src/app/components/compilation-detail/compilation-detail.component.ts index d4aa2f13..63695aa5 100644 --- a/src/app/components/compilation-detail/compilation-detail.component.ts +++ b/src/app/components/compilation-detail/compilation-detail.component.ts @@ -1,15 +1,22 @@ -import { Component, computed, input } from '@angular/core'; +import { Component, computed, input, ChangeDetectionStrategy } from '@angular/core'; +import { DatePipe } from '@angular/common'; import { MatIconModule } from '@angular/material/icon'; import { MatTooltipModule } from '@angular/material/tooltip'; import { RouterLink } from '@angular/router'; import { ICompilation, IEntity, isEntity } from '@kompakkt/common'; -import { TranslatePipe } from '../../pipes/translate.pipe'; +import { NgxFluentPipe } from '@apappas1129/ngx-fluent'; @Component({ selector: 'app-compilation-detail', templateUrl: './compilation-detail.component.html', styleUrls: ['./compilation-detail.component.scss'], - imports: [MatTooltipModule, MatIconModule, RouterLink, TranslatePipe], + imports: [ + DatePipe, + MatTooltipModule, + MatIconModule, + RouterLink, + NgxFluentPipe, + ], }) export class CompilationDetailComponent { compilation = input(); diff --git a/src/app/components/entity-detail/detail-entity/detail-entity.component.html b/src/app/components/entity-detail/detail-entity/detail-entity.component.html index 8a4309fa..c24ddb8f 100644 --- a/src/app/components/entity-detail/detail-entity/detail-entity.component.html +++ b/src/app/components/entity-detail/detail-entity/detail-entity.component.html @@ -2,14 +2,14 @@ @if (physicalEntity(); as physicalEntity) { -

{{ 'Reference object' | translate }}

+

{{ 'Reference object' | fluent }}

{{ physicalEntity.title }}

{{ physicalEntity.description }}

@if (physicalEntity.collection) {

{{ physicalEntity.collection }}

} @if (hasDimensions()) { -

{{ 'Dimensions' | translate }}:

+

{{ 'Dimensions' | fluent }}:

@for (dimension of dimensions(); track dimension) {

@@ -22,7 +22,7 @@

{{ physicalEntity.title }}

} @if (address(); as address) {
-

{{ 'Location' | translate }}:

+

{{ 'Location' | fluent }}:

@if (place(); as place) {

{{ place.name }}

} @@ -67,7 +67,7 @@

{{ physicalEntity.title }}

} @if (hasPersonsOrInstitutions()) { -

{{ 'Persons and Institutions' | translate }}:

+

{{ 'Persons and Institutions' | fluent }}:

@if (persons(); as persons) { @for (person of persons; track person) { @@ -82,7 +82,7 @@

{{ physicalEntity.title }}

} @if (hasExternalIds()) { -

{{ 'External identifiers' | translate }}:

+

{{ 'External identifiers' | fluent }}:

@for (identifier of externalIds(); track identifier) {

{{ identifier.type }}: @@ -91,7 +91,7 @@

{{ physicalEntity.title }}

} } @if (hasExternalLinks()) { -

{{ 'External links' | translate }}:

+

{{ 'External links' | fluent }}:

@for (link of externalLinks(); track link) {
@@ -101,7 +101,7 @@

{{ physicalEntity.title }}

} } @if (hasBibRefs()) { -

{{ 'Bibliographic references' | translate }}:

+

{{ 'Bibliographic references' | fluent }}:

@for (ref of bibRefs(); track ref) {
@if (ref.description) { @@ -118,7 +118,7 @@

{{ physicalEntity.title }}

} } @if (hasMetadataFiles()) { -

{{ 'Attached files' | translate }}:

+

{{ 'Attached files' | fluent }}:

@for (file of metadataFiles(); track file) {