From 8c194ffa3e5bcb5ef43da8cc2bcd08cacf0ca81e Mon Sep 17 00:00:00 2001 From: Tim Fabian Date: Sat, 21 Nov 2026 09:51:09 +0100 Subject: [PATCH] fixed some localization problems --- angular.json | 19 + eslint.config.mjs | 7 + package-lock.json | 1038 ++++++++--------- package.json | 3 +- projects/ngx-auth/README.md | 9 +- .../accept-invitation-config.model.ts | 4 +- .../accept-invitation-config.provider.ts | 54 +- .../accept-invitation.component.ts | 2 +- projects/ngx-auth/auth/auth.service.ts | 8 +- .../change-password-config.provider.ts | 34 +- .../confirm-email-config.provider.ts | 34 +- .../confirm-password-reset-config.provider.ts | 40 +- .../email/email-settings-config.provider.ts | 37 +- .../email/email-settings.component.spec.ts | 17 + .../identities/identities-config.provider.ts | 50 +- .../ngx-auth/login/login-config.provider.ts | 59 +- projects/ngx-auth/package.json | 8 +- .../provider-error-config.provider.ts | 50 +- .../request-password-reset-config.provider.ts | 34 +- .../second-factor-config.provider.ts | 88 +- .../sessions/sessions-config.provider.ts | 42 +- projects/ngx-auth/tsconfig.lib.json | 2 +- projects/ngx-auth/tsconfig.spec.json | 2 +- .../two-factor/two-factor-config.provider.ts | 71 +- projects/ngx-change-sets/README.md | 7 +- .../change-sets/change-set.service.ts | 2 +- .../change-sets-config.provider.ts | 91 +- projects/ngx-change-sets/package.json | 5 +- projects/ngx-change-sets/tsconfig.lib.json | 2 +- projects/ngx-change-sets/tsconfig.spec.json | 2 +- projects/ngx-ecommerce/README.md | 7 +- .../input-extras-config.provider.ts | 39 +- .../order-summary-config.provider.ts | 45 +- projects/ngx-ecommerce/package.json | 5 +- projects/ngx-ecommerce/tsconfig.lib.json | 2 +- projects/ngx-ecommerce/tsconfig.spec.json | 2 +- projects/ngx-entity/README.md | 7 +- .../dialog/entity-dialog-config.provider.ts | 24 +- .../entity-array-field-config.provider.ts | 39 +- .../entity-date-array-field.component.ts | 3 +- ...entity-date-range-field-config.provider.ts | 19 +- .../entity-object-array-field.component.ts | 4 +- .../entity-password-field-config.provider.ts | 19 +- .../form/entity-form-config.provider.ts | 31 +- projects/ngx-entity/package.json | 9 +- .../table/entity-table-config.provider.ts | 38 +- .../table/entity-table.component.ts | 12 +- projects/ngx-entity/tsconfig.lib.json | 2 +- projects/ngx-entity/tsconfig.spec.json | 2 +- .../unsaved-changes-config.provider.ts | 24 +- projects/ngx-error-handling/README.md | 7 +- .../error-dialog/error-dialog.utilities.ts | 42 +- .../show-dialog-error-handler.function.ts | 14 +- projects/ngx-error-handling/package.json | 8 +- projects/ngx-error-handling/tsconfig.lib.json | 2 +- .../ngx-error-handling/tsconfig.spec.json | 2 +- projects/ngx-navigation/README.md | 14 +- .../language-switcher-config.provider.ts | 25 +- .../navbar/navbar-config.provider.ts | 27 +- .../navigation/navigation-config.provider.ts | 25 +- .../not-found/not-found-config.provider.ts | 25 +- projects/ngx-navigation/package.json | 5 +- .../seo-server/seo-server-config.model.ts | 7 +- .../seo-server/seo-server.utilities.spec.ts | 40 +- .../seo-server/seo-server.utilities.ts | 77 +- .../seo-server/seo-site.model.ts | 7 +- projects/ngx-navigation/seo/public-api.ts | 1 + .../ngx-navigation/seo/seo-route.utilities.ts | 41 +- .../seo/seo-sitemap-context.model.ts | 10 +- .../seo/seo-sitemap-route.model.ts | 14 + projects/ngx-navigation/seo/seo.provider.ts | 7 +- projects/ngx-navigation/tsconfig.lib.json | 2 +- projects/ngx-navigation/tsconfig.spec.json | 2 +- projects/ngx-persistence-logger/README.md | 8 +- .../applications-filter.component.ts | 3 +- .../log-history-config.provider.ts | 61 +- projects/ngx-persistence-logger/package.json | 8 +- .../ngx-persistence-logger/tsconfig.lib.json | 2 +- .../ngx-persistence-logger/tsconfig.spec.json | 2 +- projects/ngx-pwa/README.md | 7 +- .../offline-status-bar-config.provider.ts | 27 +- projects/ngx-pwa/package.json | 8 +- .../sync-dialog-config.provider.ts | 72 +- projects/ngx-pwa/tsconfig.lib.json | 2 +- projects/ngx-pwa/tsconfig.spec.json | 2 +- .../updates/updates-config.provider.ts | 37 +- projects/ngx-tracking/README.md | 9 +- .../consent-dialog-config.provider.ts | 54 - .../consent-dialog-ui.service.ts | 4 +- .../consent-dialog.component.spec.ts | 16 +- .../consent-dialog.component.ts | 4 +- .../consent-dialog/consent-dialog.stories.ts | 3 +- .../ngx-tracking/consent-dialog/public-api.ts | 3 - .../consent-dialog-config-changes.model.ts | 0 .../consent-dialog-config.model.ts | 2 +- .../consent/consent-dialog-config.provider.ts | 73 ++ projects/ngx-tracking/consent/public-api.ts | 3 + projects/ngx-tracking/package.json | 5 +- .../privacy-settings-config.provider.ts | 20 +- projects/ngx-tracking/tsconfig.lib.json | 2 +- projects/ngx-tracking/tsconfig.spec.json | 2 +- projects/showcase/tsconfig.app.json | 2 +- projects/ui/.storybook/preview.ts | 2 + projects/ui/.storybook/tsconfig.json | 2 +- projects/ui/README.md | 7 +- .../ui/address/address-config.provider.ts | 27 +- .../back-to-top-config.provider.ts | 20 +- .../breadcrumbs-config.provider.ts | 17 +- projects/ui/byline/byline-config.provider.ts | 21 +- .../ui/callout/callout-config.provider.ts | 49 +- .../check-list/check-list-config.provider.ts | 24 +- .../consent-gate-config.provider.ts | 34 +- .../date-period-config.provider.ts | 24 +- projects/ui/drawer/drawer-config.provider.ts | 23 +- .../event-calendar-config.provider.ts | 63 +- .../expandable-text-config.provider.ts | 21 +- .../filter-tiles-config.provider.ts | 26 +- .../ui/footnotes/footnotes-config.provider.ts | 21 +- .../ui/gallery/gallery-config.provider.ts | 25 +- .../input-autocomplete.component.ts | 12 +- .../ui/input-chips/input-chips.component.ts | 6 +- .../ui/input-date/input-date.utilities.ts | 1 + .../input-time/input-time-config.provider.ts | 23 +- projects/ui/input/input-config.provider.ts | 111 +- projects/ui/link/link-config.provider.ts | 20 +- .../ui/loading/loading-config.provider.ts | 19 +- projects/ui/map/map-config.provider.ts | 25 +- .../news-ticker-config.provider.ts | 27 +- .../opening-hours-config.provider.ts | 39 +- projects/ui/package.json | 3 +- .../pagination/pagination-config.provider.ts | 29 +- projects/ui/price/price-config.provider.ts | 25 +- .../pricing-card-config.provider.ts | 23 +- projects/ui/rating/rating-config.provider.ts | 19 +- .../search-toolbar-config.provider.ts | 25 +- .../showcase-card-config.provider.ts | 19 +- .../spam-protection-config.provider.ts | 23 +- .../ui/spinner/spinner-config.provider.ts | 19 +- .../ui/stepper/stepper-config.provider.ts | 37 +- .../table-of-contents-config.provider.ts | 23 +- projects/ui/table/table-config.provider.ts | 47 +- projects/ui/tsconfig.lib.json | 2 +- projects/ui/tsconfig.spec.json | 2 +- tests/accessibility.spec.ts | 2 +- tests/entity-arrays.spec.ts | 2 +- 145 files changed, 2339 insertions(+), 1649 deletions(-) create mode 100644 projects/ngx-navigation/seo/seo-sitemap-route.model.ts delete mode 100644 projects/ngx-tracking/consent-dialog/consent-dialog-config.provider.ts rename projects/ngx-tracking/{consent-dialog => consent}/consent-dialog-config-changes.model.ts (100%) rename projects/ngx-tracking/{consent-dialog => consent}/consent-dialog-config.model.ts (95%) create mode 100644 projects/ngx-tracking/consent/consent-dialog-config.provider.ts diff --git a/angular.json b/angular.json index 33308d6..61d84f9 100644 --- a/angular.json +++ b/angular.json @@ -22,6 +22,7 @@ "test": { "builder": "@angular/build:unit-test", "options": { + "buildTarget": "testing:test-polyfills", "tsConfig": "projects/ngx-auth/tsconfig.spec.json" } } @@ -48,6 +49,7 @@ "test": { "builder": "@angular/build:unit-test", "options": { + "buildTarget": "testing:test-polyfills", "tsConfig": "projects/ngx-change-sets/tsconfig.spec.json" } } @@ -74,6 +76,7 @@ "test": { "builder": "@angular/build:unit-test", "options": { + "buildTarget": "testing:test-polyfills", "tsConfig": "projects/ngx-ecommerce/tsconfig.spec.json" } } @@ -100,6 +103,7 @@ "test": { "builder": "@angular/build:unit-test", "options": { + "buildTarget": "testing:test-polyfills", "setupFiles": ["projects/ngx-entity/test-setup.ts"], "tsConfig": "projects/ngx-entity/tsconfig.spec.json" } @@ -127,6 +131,7 @@ "test": { "builder": "@angular/build:unit-test", "options": { + "buildTarget": "testing:test-polyfills", "tsConfig": "projects/ngx-error-handling/tsconfig.spec.json" } } @@ -153,6 +158,7 @@ "test": { "builder": "@angular/build:unit-test", "options": { + "buildTarget": "testing:test-polyfills", "tsConfig": "projects/ngx-navigation/tsconfig.spec.json" } } @@ -179,6 +185,7 @@ "test": { "builder": "@angular/build:unit-test", "options": { + "buildTarget": "testing:test-polyfills", "tsConfig": "projects/ngx-persistence-logger/tsconfig.spec.json" } } @@ -205,6 +212,7 @@ "test": { "builder": "@angular/build:unit-test", "options": { + "buildTarget": "testing:test-polyfills", "tsConfig": "projects/ngx-pwa/tsconfig.spec.json" } } @@ -231,6 +239,7 @@ "test": { "builder": "@angular/build:unit-test", "options": { + "buildTarget": "testing:test-polyfills", "tsConfig": "projects/ngx-tracking/tsconfig.spec.json" } } @@ -276,6 +285,7 @@ ], "browser": "projects/showcase/src/main.ts", "outputMode": "static", + "polyfills": ["@angular/localize/init"], "server": "projects/showcase/src/main.server.ts", "styles": ["projects/showcase/src/styles.css"], "tsConfig": "projects/showcase/tsconfig.app.json" @@ -338,6 +348,14 @@ } }, "defaultConfiguration": "production" + }, + "test-polyfills": { + "builder": "@angular/build:application", + "options": { + "browser": "projects/testing/src/public-api.ts", + "polyfills": ["@angular/localize/init"], + "tsConfig": "projects/testing/tsconfig.lib.json" + } } }, "prefix": "lib", @@ -386,6 +404,7 @@ "test": { "builder": "@angular/build:unit-test", "options": { + "buildTarget": "testing:test-polyfills", "setupFiles": ["projects/ui/test-setup.ts"], "tsConfig": "projects/ui/tsconfig.spec.json" } diff --git a/eslint.config.mjs b/eslint.config.mjs index c420d66..cd6e1c2 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -27,6 +27,13 @@ export default [ 'angular/no-call-expression': 'off' } }, + { + files: ['**/*.ts'], + rules: { + // a polyfill is imported for what it defines, like the $localize of the default texts in the stories. + 'eslintImport/no-unassigned-import': ['warn', { allow: ['@angular/localize/init'] }] + } + }, { // the controls pass their autofocus input on to their native element, like every other native attribute. Only a // consumer that asks for it gets it, like a control in a popover, which the browser focuses as the popover opens. diff --git a/package-lock.json b/package-lock.json index 3a02545..0b4471a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -23,13 +23,14 @@ "@angular/build": "^22.2.5", "@angular/cli": "^22.2.5", "@angular/compiler-cli": "^22.2.5", + "@angular/localize": "^22.2.6", "@angular/platform-browser-dynamic": "^22.2.5", "@angular/platform-server": "^22.2.5", "@angular/service-worker": "^22.2.5", "@angular/ssr": "^22.2.6", "@axe-core/playwright": "^4.13.0", "@fortawesome/free-solid-svg-icons": "^7.3.1", - "@service-soft/eslint-config": "^2.1.7", + "@service-soft/eslint-config": "^2.2.2", "@storybook/addon-a11y": "^10.6.2", "@storybook/angular": "^10.6.2", "@tailwindcss/postcss": "^4.3.3", @@ -836,6 +837,69 @@ "rxjs": "^6.5.3 || ^7.4.0" } }, + "node_modules/@angular/localize": { + "version": "22.2.6", + "resolved": "https://registry.npmjs.org/@angular/localize/-/localize-22.2.6.tgz", + "integrity": "sha512-kznz48aOjyEZ7Dn1BDLqV3wHpH7b2DUtcSfbfDZNs173yUthPMLB1z0nHyNsPtsEpfkt0kE9IawfjqusokyYyw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@babel/core": "8.0.1", + "tinyglobby": "^0.2.12", + "yargs": "^18.0.0" + }, + "bin": { + "localize-extract": "tools/bundles/src/extract/cli.js", + "localize-migrate": "tools/bundles/src/migrate/cli.js", + "localize-translate": "tools/bundles/src/translate/cli.js" + }, + "engines": { + "node": "^22.22.3 || ^24.15.0 || >=26.0.0" + }, + "peerDependencies": { + "@angular/compiler": "22.2.6", + "@angular/compiler-cli": "22.2.6" + } + }, + "node_modules/@angular/localize/node_modules/@babel/core": { + "version": "8.0.1", + "resolved": "https://registry.npmjs.org/@babel/core/-/core-8.0.1.tgz", + "integrity": "sha512-5FgxM4dLQpMJHSiVATk8foW263dVHQHBVpXYiimNECVWG01f4nFyEbQixeT6Mwvg7TayREJ2gpKl3o2RoMdnqw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@babel/code-frame": "^8.0.0", + "@babel/generator": "^8.0.0", + "@babel/helper-compilation-targets": "^8.0.0", + "@babel/helpers": "^8.0.0", + "@babel/parser": "^8.0.0", + "@babel/template": "^8.0.0", + "@babel/traverse": "^8.0.0", + "@babel/types": "^8.0.0", + "@types/gensync": "^1.0.5", + "convert-source-map": "^2.0.0", + "empathic": "^2.0.1", + "gensync": "^1.0.0-beta.2", + "import-meta-resolve": "^4.2.0", + "json5": "^2.2.3", + "obug": "^2.1.1", + "semver": "^7.7.3" + }, + "engines": { + "node": "^22.18.0 || >=24.11.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/babel" + } + }, + "node_modules/@angular/localize/node_modules/convert-source-map": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-2.0.0.tgz", + "integrity": "sha512-Kvp459HrV2FEJ1CAsi1Ku+MY3kasH19TFykTz2xWmMeq6bk2NU3XXvfJ+Q61m0xktWwt+1HSYf3JZsTms3aRJg==", + "dev": true, + "license": "MIT" + }, "node_modules/@angular/platform-browser": { "version": "22.2.6", "resolved": "https://registry.npmjs.org/@angular/platform-browser/-/platform-browser-22.2.6.tgz", @@ -1072,9 +1136,9 @@ "license": "MIT" }, "node_modules/@babel/eslint-parser": { - "version": "8.0.7", - "resolved": "https://registry.npmjs.org/@babel/eslint-parser/-/eslint-parser-8.0.7.tgz", - "integrity": "sha512-ik5I+U64QuQQPohw0A1wVWPR+vTRYVfWBDLOLc1KwZQ2SKayQLD52DgoB3W/kmwc4MP1E37qh7nZuDD9xsKYcA==", + "version": "8.1.2", + "resolved": "https://registry.npmjs.org/@babel/eslint-parser/-/eslint-parser-8.1.2.tgz", + "integrity": "sha512-oyB1a5JmJz/Hrw7Qy6c47uAemiD3irqyVyPwGsdzdw7XpdCtKCkmEJqtHnqRSrxiptVJoccrAxU+iDMs9zgeIg==", "dev": true, "license": "MIT", "dependencies": { @@ -2765,9 +2829,9 @@ } }, "node_modules/@cspell/cspell-bundled-dicts": { - "version": "10.4.0", - "resolved": "https://registry.npmjs.org/@cspell/cspell-bundled-dicts/-/cspell-bundled-dicts-10.4.0.tgz", - "integrity": "sha512-ey23dut7NdnOsQQinQhROFZUh4LvLhJnnZCiq7y+KXMngdqXnIAZuEnnwXk3IfdOX+tycDC8OuMssLXDJ3Fnxw==", + "version": "10.5.2", + "resolved": "https://registry.npmjs.org/@cspell/cspell-bundled-dicts/-/cspell-bundled-dicts-10.5.2.tgz", + "integrity": "sha512-1EVGMy+/Ayjpu2r4i4x3K44kWoVbrdramIR+cX75fo5bDMgb1MXf7vIEfFKETY1h4eczd40SxM46twxrCxTwRw==", "dev": true, "license": "MIT", "dependencies": { @@ -2775,20 +2839,20 @@ "@cspell/dict-al": "^1.1.1", "@cspell/dict-aws": "^4.0.17", "@cspell/dict-bash": "^4.2.3", - "@cspell/dict-companies": "^3.2.13", - "@cspell/dict-cpp": "^7.1.3", + "@cspell/dict-companies": "^3.2.14", + "@cspell/dict-cpp": "^7.2.0", "@cspell/dict-cryptocurrencies": "^5.0.5", "@cspell/dict-csharp": "^4.0.8", "@cspell/dict-css": "^4.1.2", "@cspell/dict-dart": "^2.3.2", - "@cspell/dict-data-science": "^2.0.16", + "@cspell/dict-data-science": "^2.0.17", "@cspell/dict-django": "^4.1.7", "@cspell/dict-docker": "^1.1.17", "@cspell/dict-dotnet": "^5.0.15", "@cspell/dict-elixir": "^4.0.8", - "@cspell/dict-en_us": "^4.4.41", - "@cspell/dict-en-common-misspellings": "^2.2.5", - "@cspell/dict-en-gb-mit": "^3.1.30", + "@cspell/dict-en_us": "^4.4.43", + "@cspell/dict-en-common-misspellings": "^2.2.6", + "@cspell/dict-en-gb-mit": "^3.1.32", "@cspell/dict-filetypes": "^3.0.18", "@cspell/dict-flutter": "^1.1.1", "@cspell/dict-fonts": "^4.0.6", @@ -2812,17 +2876,17 @@ "@cspell/dict-markdown": "^2.0.18", "@cspell/dict-monkeyc": "^1.1.2", "@cspell/dict-node": "^5.0.9", - "@cspell/dict-npm": "^5.2.54", + "@cspell/dict-npm": "^5.2.56", "@cspell/dict-php": "^4.1.3", "@cspell/dict-powershell": "^5.0.17", "@cspell/dict-public-licenses": "^2.0.17", - "@cspell/dict-python": "^4.5.2", + "@cspell/dict-python": "^4.5.3", "@cspell/dict-r": "^2.1.1", "@cspell/dict-ruby": "^5.1.4", "@cspell/dict-rust": "^4.1.2", "@cspell/dict-scala": "^5.0.11", "@cspell/dict-shell": "^1.2.0", - "@cspell/dict-software-terms": "^5.4.8", + "@cspell/dict-software-terms": "^5.4.9", "@cspell/dict-sql": "^2.2.1", "@cspell/dict-svelte": "^1.0.7", "@cspell/dict-swift": "^2.0.6", @@ -2836,9 +2900,9 @@ } }, "node_modules/@cspell/cspell-performance-monitor": { - "version": "10.4.0", - "resolved": "https://registry.npmjs.org/@cspell/cspell-performance-monitor/-/cspell-performance-monitor-10.4.0.tgz", - "integrity": "sha512-0hCqI8pR0waFKKOR3SZ4VtWddx7HZTr0v7MPCPG0IpaqMzzaibrXn9AtFCe+9T1+UDQrM109YKS+yr0c6xVvMQ==", + "version": "10.5.2", + "resolved": "https://registry.npmjs.org/@cspell/cspell-performance-monitor/-/cspell-performance-monitor-10.5.2.tgz", + "integrity": "sha512-wQVHhjMd5BCum9oeBmncdu2h3i9FcWLbrKAInQafgAb0ASOLRJiaGMeH3HkjOIWgHXmoJYlrfw/MjWj3iLJp9g==", "dev": true, "license": "MIT", "engines": { @@ -2846,9 +2910,9 @@ } }, "node_modules/@cspell/cspell-pipe": { - "version": "10.4.0", - "resolved": "https://registry.npmjs.org/@cspell/cspell-pipe/-/cspell-pipe-10.4.0.tgz", - "integrity": "sha512-cXHgST9ySpECyiE5ZK7TcwBqrCb3h9X49j/lSDcWNAVp7GkwnPfcdylH+Zq/VfYMlHad24z8CNXd5H91O9DhEA==", + "version": "10.5.2", + "resolved": "https://registry.npmjs.org/@cspell/cspell-pipe/-/cspell-pipe-10.5.2.tgz", + "integrity": "sha512-iwPHCMtFsIskUFijqTmaypLCRkazjjJViolJRreZycWMz+ts6JaY3iE8jtWbLZ8nTMp5nyIca6H4AdYoxuftjA==", "dev": true, "license": "MIT", "engines": { @@ -2856,9 +2920,9 @@ } }, "node_modules/@cspell/cspell-resolver": { - "version": "10.4.0", - "resolved": "https://registry.npmjs.org/@cspell/cspell-resolver/-/cspell-resolver-10.4.0.tgz", - "integrity": "sha512-uyI9qX8hagtcFtRTElYGXXyVhhnVxPBSf1Ltds9AlU9cktPOFYeTXQOfBR+Dpt9dCruzX29ZJbd3hR1i5yryZg==", + "version": "10.5.2", + "resolved": "https://registry.npmjs.org/@cspell/cspell-resolver/-/cspell-resolver-10.5.2.tgz", + "integrity": "sha512-Ia/4+nNqQFECHZo+sSrnO+Ogzom+0FrCUErWEfV660HT8DWX90sR97v6sQsDy9Rc2nI+7lt7Q9vWEk7uhHuV3g==", "dev": true, "license": "MIT", "dependencies": { @@ -2869,9 +2933,9 @@ } }, "node_modules/@cspell/cspell-service-bus": { - "version": "10.4.0", - "resolved": "https://registry.npmjs.org/@cspell/cspell-service-bus/-/cspell-service-bus-10.4.0.tgz", - "integrity": "sha512-IZzx+EWADkN5xbFrW+VS+JQ52+w5tWaZNxDgGa+0Mv79hks6wNa2Vcnce+9vGcBJYgA24VcuAfekI38tYzcDtw==", + "version": "10.5.2", + "resolved": "https://registry.npmjs.org/@cspell/cspell-service-bus/-/cspell-service-bus-10.5.2.tgz", + "integrity": "sha512-SRJU7/dk0wGDaEp4v5VRG7WAxk8nueTIVqzC2uR2YjFSqYvOyGrvE0u2TDyD8j1H4dfam4WLcmCD7yCjl2hSuQ==", "dev": true, "license": "MIT", "engines": { @@ -2879,9 +2943,9 @@ } }, "node_modules/@cspell/cspell-types": { - "version": "10.4.0", - "resolved": "https://registry.npmjs.org/@cspell/cspell-types/-/cspell-types-10.4.0.tgz", - "integrity": "sha512-LTOrZcDSHj5BkeNSvimuV3AMF7gWjxzXUdQ7zYT/h/57/5flHuE6NPKSXS69ty8vJM0WrVh35L5aDxnCPfDzXA==", + "version": "10.5.2", + "resolved": "https://registry.npmjs.org/@cspell/cspell-types/-/cspell-types-10.5.2.tgz", + "integrity": "sha512-vSxzSbGny4eCCWImCEzU2OhxUrNMOkl05KCDVBwkDKEb9JHIzGOeUddoRtgPA6O7e74VOIbzFwedGkJfoiLLxQ==", "dev": true, "license": "MIT", "engines": { @@ -3321,13 +3385,13 @@ "license": "MIT" }, "node_modules/@cspell/dynamic-import": { - "version": "10.4.0", - "resolved": "https://registry.npmjs.org/@cspell/dynamic-import/-/dynamic-import-10.4.0.tgz", - "integrity": "sha512-scSwtJDqpRT/Kqzo64XR8OWzXYfdpp9Yneq99Drhqm5gXXI2BAlgjzhBnMGKa+x7eIJZVM2+D2uFeDI2xQYM2w==", + "version": "10.5.2", + "resolved": "https://registry.npmjs.org/@cspell/dynamic-import/-/dynamic-import-10.5.2.tgz", + "integrity": "sha512-sXOxhv+NoLW9k9YPvsNULjugSkIt2/EPnBnuKLDFrdyG5F0MNcgIM3Y6j/u3OGbRNOD+2OIF+Exh/Lh4E4YVEA==", "dev": true, "license": "MIT", "dependencies": { - "@cspell/url": "10.4.0", + "@cspell/url": "10.5.2", "import-meta-resolve": "^4.2.0" }, "engines": { @@ -3335,16 +3399,16 @@ } }, "node_modules/@cspell/eslint-plugin": { - "version": "10.4.0", - "resolved": "https://registry.npmjs.org/@cspell/eslint-plugin/-/eslint-plugin-10.4.0.tgz", - "integrity": "sha512-fWAx5HqXsl9o840Sp8DKvZxQq6R4fy+zaznivoARB2jSGbYSc8mHZ/l1NGU6DaOxBGI1yJ8mRssm4W0QcRhEwQ==", + "version": "10.5.2", + "resolved": "https://registry.npmjs.org/@cspell/eslint-plugin/-/eslint-plugin-10.5.2.tgz", + "integrity": "sha512-RKpdKNdP9PlsTt2JiIbdT4T/chaKgnQ5BK7X4j8MFJ8O/4ZGrMbg6K9kt7J3vHmzQBgn3LT33FweFhFbv8WHNA==", "dev": true, "license": "MIT", "dependencies": { - "@cspell/cspell-types": "10.4.0", - "@cspell/url": "10.4.0", - "cspell-lib": "10.4.0", - "synckit": "^0.11.13" + "@cspell/cspell-types": "10.5.2", + "@cspell/url": "10.5.2", + "cspell-lib": "10.5.2", + "synckit": "^0.12.3" }, "engines": { "node": ">=22.18.0" @@ -3353,10 +3417,27 @@ "eslint": "^8 || ^9 || ^10" } }, + "node_modules/@cspell/eslint-plugin/node_modules/synckit": { + "version": "0.12.3", + "resolved": "https://registry.npmjs.org/synckit/-/synckit-0.12.3.tgz", + "integrity": "sha512-U+/AXT6LWsxnj2vz9HeUuPWBNgdWxjyIEjEPdbJARC9txmgPzo2VEdqnFo4hHaNyMPtycyVJrSaQYeQv/PoyyA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@dual-bundle/import-meta-resolve": "^4.2.1", + "@pkgr/core": "^0.3.6" + }, + "engines": { + "node": "^14.18.0 || >=16.0.0" + }, + "funding": { + "url": "https://opencollective.com/synckit" + } + }, "node_modules/@cspell/filetypes": { - "version": "10.4.0", - "resolved": "https://registry.npmjs.org/@cspell/filetypes/-/filetypes-10.4.0.tgz", - "integrity": "sha512-ez0MyFxnpYN9eMkH8vGGseQPsCRwD7ZlsR+ivQ2rPx04CX7ctp015nWv71P7m+T6V05AsyAwyEGZP9vrTlB4Ig==", + "version": "10.5.2", + "resolved": "https://registry.npmjs.org/@cspell/filetypes/-/filetypes-10.5.2.tgz", + "integrity": "sha512-AVkl2lf0jobYxXWqxRDAmR73hmAeyEIV8DfdW7xeheC5vZ9SrbzgWhtk3AMtPLCuDGkCEoNvi4ahcDsu3IwQ4A==", "dev": true, "license": "MIT", "engines": { @@ -3364,9 +3445,9 @@ } }, "node_modules/@cspell/rpc": { - "version": "10.4.0", - "resolved": "https://registry.npmjs.org/@cspell/rpc/-/rpc-10.4.0.tgz", - "integrity": "sha512-tX1YLQYPQz+p73U5OTLmOxIrsmRkpaaKrPnfrVIpK5yv3erWE8ELVZD0zK01rursbL1rW3gyOv0ShHlmoE5VNA==", + "version": "10.5.2", + "resolved": "https://registry.npmjs.org/@cspell/rpc/-/rpc-10.5.2.tgz", + "integrity": "sha512-4EBIBqUlaRE8NuwA8MmUR2HsqjlX3anRFiy7Sr+gNwso/njPnqKr6EeTxFapGZOR+ShrwN3dL8En7ROJtyD/kg==", "dev": true, "license": "MIT", "engines": { @@ -3374,9 +3455,9 @@ } }, "node_modules/@cspell/strong-weak-map": { - "version": "10.4.0", - "resolved": "https://registry.npmjs.org/@cspell/strong-weak-map/-/strong-weak-map-10.4.0.tgz", - "integrity": "sha512-y8+Hk90mA3UY4HYEWBJokvNcixQOKkRDLEr+yXSYyOJnt6MhAu8D7N567HjEVNj0e7oirXl62wpNglPfo7qAcQ==", + "version": "10.5.2", + "resolved": "https://registry.npmjs.org/@cspell/strong-weak-map/-/strong-weak-map-10.5.2.tgz", + "integrity": "sha512-8+uJw+DZnN84/Cd1urbb5ETp+2LDX71Xa+gjyrgZne74VRy02oXIC1etk+GwQMpjOe+iE6TQC/hfw/DIlsQ9sg==", "dev": true, "license": "MIT", "engines": { @@ -3384,9 +3465,9 @@ } }, "node_modules/@cspell/url": { - "version": "10.4.0", - "resolved": "https://registry.npmjs.org/@cspell/url/-/url-10.4.0.tgz", - "integrity": "sha512-8NvDv8h3eaxejAvD+crMsSEgGq6LiunfS6iD2TBAcDqskNsIpN43AMHNNRf7T7Fd/3Y413nQDBH4RmsHcNsiqg==", + "version": "10.5.2", + "resolved": "https://registry.npmjs.org/@cspell/url/-/url-10.5.2.tgz", + "integrity": "sha512-Uu02E4n52vivBApl8kLh16+9F6VMNIZheU3G44yg7yZoXyh1R7qtwvyTWtvBfuV091ENSh85EirI4ws4kmJudg==", "dev": true, "license": "MIT", "engines": { @@ -3591,18 +3672,66 @@ "tslib": "^2.4.0" } }, + "node_modules/@es-joy/escodegen": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/@es-joy/escodegen/-/escodegen-5.0.1.tgz", + "integrity": "sha512-0sOnDSVMt7Zg5qmXz4ab1yOXrUi0QmSPqpm5d547puNdJxT0J+Xdip2F/5j07nuE1pW131AX5jFUvOIfZPYNRg==", + "dev": true, + "license": "BSD-2-Clause", + "dependencies": { + "@es-joy/estraverse": "^7.1.1", + "@es-joy/esutils": "^3.0.0", + "@es-joy/jsdoccomment": "^1.1.0", + "@types/estree": "^1.0.10", + "esprima": "^4.0.1", + "optionator": "^0.9.4" + }, + "bin": { + "escodegen": "bin/escodegen.js", + "esgenerate": "bin/esgenerate.js" + }, + "engines": { + "node": "^22.16.0 || >=24.0.0" + }, + "optionalDependencies": { + "source-map": "~0.8.0" + } + }, + "node_modules/@es-joy/estraverse": { + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/@es-joy/estraverse/-/estraverse-7.1.1.tgz", + "integrity": "sha512-h2d737iS0LFAqypZOmXizu54qAbHofI/RpD30Zom03O6BCXKHuFevWKPcGarZbGq82h7qSBb5G6kLdhTMO+caw==", + "dev": true, + "license": "BSD-2-Clause", + "engines": { + "node": ">=4.0" + } + }, + "node_modules/@es-joy/esutils": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/@es-joy/esutils/-/esutils-3.0.0.tgz", + "integrity": "sha512-K8M2b2ixqOiF5B+qYJIWIznFtvbD8biX2mj31pXmXAaTRUUd2x6anAFZk4GVGXz7sX9tOkx+z6TaQc/paeVCeg==", + "dev": true, + "license": "BSD-2-Clause", + "dependencies": { + "@types/estree": "^1.0.9" + }, + "engines": { + "node": "^22.16.0 || >=24.0.0" + } + }, "node_modules/@es-joy/jsdoccomment": { - "version": "0.98.0", - "resolved": "https://registry.npmjs.org/@es-joy/jsdoccomment/-/jsdoccomment-0.98.0.tgz", - "integrity": "sha512-QS+b7I2aaSM+gZfDz1b9E4B367JJ2qTjFXRKF289iKkh9sYdZ21Q5MiF/Duzouy3J0C4VhM3I/8f2F4+zT8gYQ==", + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/@es-joy/jsdoccomment/-/jsdoccomment-1.2.0.tgz", + "integrity": "sha512-EcF8gDd175MRIYEt7ktoe9AUijBba3SSSvnGJ96HQaK1BxjVK8l1QdksVEAY34Lp0byn51FnTszlVMYmD5TI/w==", "dev": true, "license": "MIT", "dependencies": { - "@types/estree": "^1.0.9", - "@typescript-eslint/types": "^8.70.0", + "@types/estree": "^1.0.10", + "@typescript-eslint/types": "^8.72.2", "comment-parser": "1.4.9", "esquery": "^1.7.0", - "jsdoc-type-pratt-parser": "~9.2.2" + "jsdoc-type-pratt-parser": "~9.5.0" }, "engines": { "node": "^22.22.2 || >=24.15.0" @@ -7821,9 +7950,9 @@ } }, "node_modules/@service-soft/eslint-config": { - "version": "2.1.7", - "resolved": "https://registry.npmjs.org/@service-soft/eslint-config/-/eslint-config-2.1.7.tgz", - "integrity": "sha512-opKSB8qGRW7VyOtt5WmTdRstDpKRNNHbvW09eCUkZuo3t11jbA96CPPF4dHMtl8+GYjjqQTBDpmiOQj4wLplFQ==", + "version": "2.2.2", + "resolved": "https://registry.npmjs.org/@service-soft/eslint-config/-/eslint-config-2.2.2.tgz", + "integrity": "sha512-O9UPLSihd7WDaHN3bvjQDqIBfiukXYB56Ms0q4pBJzwIwK5KdRjlwX7HqWX7+YyIrvN9Z2gG22TeHDGhm+nWAA==", "dev": true, "license": "ISC", "dependencies": { @@ -7832,16 +7961,16 @@ "@angular-eslint/eslint-plugin-template": "22", "@angular-eslint/schematics": "22", "@angular-eslint/template-parser": "22", - "@babel/eslint-parser": "8.0.7", + "@babel/eslint-parser": "8.1.2", "@cspell/dict-de-de": "4.1.3", - "@cspell/eslint-plugin": "10.4.0", + "@cspell/eslint-plugin": "10.5.2", "@stylistic/eslint-plugin": "5.10.0", - "@typescript-eslint/eslint-plugin": "8.71.2", - "@typescript-eslint/parser": "8.71.2", - "@typescript-eslint/utils": "8.71.2", + "@typescript-eslint/eslint-plugin": "8.73.0", + "@typescript-eslint/parser": "8.73.0", + "@typescript-eslint/utils": "8.73.0", "eslint-plugin-github": "6.1.2", - "eslint-plugin-import-x": "4.17.1", - "eslint-plugin-jsdoc": "65.3.2", + "eslint-plugin-import-x": "4.18.1", + "eslint-plugin-jsdoc": "65.4.12", "eslint-plugin-jsonc": "3.4.2", "eslint-plugin-promise": "7.3.0", "eslint-plugin-sonarjs": "4.2.2", @@ -9135,17 +9264,17 @@ } }, "node_modules/@typescript-eslint/eslint-plugin": { - "version": "8.71.2", - "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.71.2.tgz", - "integrity": "sha512-K72/pvT7qpm8q3k8G5u93NCSN1RcLxX5h7Gw0bQpbMXviBHeY6Nx1WEwmk9wP+eKTSQ8ecxvcgt/ZX/rB938xQ==", + "version": "8.73.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.73.0.tgz", + "integrity": "sha512-UkygMFer53Yzn29MCYFTHf34hGXf5KJhiDWfIm1tXtXRrym1CS6l5H9Y3yCtPWChpC0/f93H88gdj8tN0dd4kw==", "dev": true, "license": "MIT", "dependencies": { "@eslint-community/regexpp": "^4.12.2", - "@typescript-eslint/scope-manager": "8.71.2", - "@typescript-eslint/type-utils": "8.71.2", - "@typescript-eslint/utils": "8.71.2", - "@typescript-eslint/visitor-keys": "8.71.2", + "@typescript-eslint/scope-manager": "8.73.0", + "@typescript-eslint/type-utils": "8.73.0", + "@typescript-eslint/utils": "8.73.0", + "@typescript-eslint/visitor-keys": "8.73.0", "ignore": "^7.0.5", "natural-compare": "^1.4.0", "ts-api-utils": "^2.5.0" @@ -9158,22 +9287,22 @@ "url": "https://opencollective.com/typescript-eslint" }, "peerDependencies": { - "@typescript-eslint/parser": "^8.71.2", + "@typescript-eslint/parser": "^8.73.0", "eslint": "^8.57.0 || ^9.0.0 || ^10.0.0", "typescript": ">=4.8.4 <6.1.0" } }, "node_modules/@typescript-eslint/parser": { - "version": "8.71.2", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-8.71.2.tgz", - "integrity": "sha512-aTtmZjp/x3gsGHkDs04/1I8kNogBJkpQaeGaN0PfiG43NzDEmW2n+OP5im9wfsvyX0yP1UZWBrAGtDBfH9jEVw==", + "version": "8.73.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-8.73.0.tgz", + "integrity": "sha512-AuL45bVcmssHfZ3Di3cs9Q0l4gBm4ZFVrJOQEE7VpqW+PVgQaEwSwazz4TVIiFabXkk6U51EprYDwqw+HR8ePw==", "dev": true, "license": "MIT", "dependencies": { - "@typescript-eslint/scope-manager": "8.71.2", - "@typescript-eslint/types": "8.71.2", - "@typescript-eslint/typescript-estree": "8.71.2", - "@typescript-eslint/visitor-keys": "8.71.2", + "@typescript-eslint/scope-manager": "8.73.0", + "@typescript-eslint/types": "8.73.0", + "@typescript-eslint/typescript-estree": "8.73.0", + "@typescript-eslint/visitor-keys": "8.73.0", "debug": "^4.4.3" }, "engines": { @@ -9188,29 +9317,15 @@ "typescript": ">=4.8.4 <6.1.0" } }, - "node_modules/@typescript-eslint/parser/node_modules/@typescript-eslint/types": { - "version": "8.71.2", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.71.2.tgz", - "integrity": "sha512-y5Ukl3oVp7e/VGxqIoEXoeb/Roj71PAJ4WG/N/RGj+eeDvKRLM15kGr9MijLbN0i03S52zxu31Z98E5gWChJKw==", - "dev": true, - "license": "MIT", - "engines": { - "node": "^18.18.0 || ^20.9.0 || >=21.1.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" - } - }, "node_modules/@typescript-eslint/project-service": { - "version": "8.71.2", - "resolved": "https://registry.npmjs.org/@typescript-eslint/project-service/-/project-service-8.71.2.tgz", - "integrity": "sha512-Pd68GsLVh5ZXlcEccFPdhSOvtHZ/2WU0XsA8zmXOS3F158lVlcTLhfQ6qvtL1RzbMie0Kp8xtbVwAg4nejKPHw==", + "version": "8.73.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/project-service/-/project-service-8.73.0.tgz", + "integrity": "sha512-/pEf8Rc4Mjk+qJnY0uO1+Gadeal8uv50xpuic+srG2vIVatA0XxvWMUeMtFvs6OCHqftiQ7/+qH4aehG5stzIA==", "dev": true, "license": "MIT", "dependencies": { - "@typescript-eslint/tsconfig-utils": "^8.71.2", - "@typescript-eslint/types": "^8.71.2", + "@typescript-eslint/tsconfig-utils": "^8.73.0", + "@typescript-eslint/types": "^8.73.0", "debug": "^4.4.3" }, "engines": { @@ -9225,29 +9340,15 @@ } }, "node_modules/@typescript-eslint/scope-manager": { - "version": "8.71.2", - "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-8.71.2.tgz", - "integrity": "sha512-YF4wgg5iUX5Obywoac27B56FhozMNFhdJSbh11H5GBAwmBtfyRhmgTQqW9tRNNmHDvsZ2CX6UGzoz+YfYn2Leg==", + "version": "8.73.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-8.73.0.tgz", + "integrity": "sha512-/TjD738Iq2rzj5z0ixVOi+TsvgjAzZPLPaH1yWdDBytR/HTR5gMpyYWZeCe5WTQZLwk3ho8AV7U3muoQCRtXBQ==", "dev": true, "license": "MIT", "dependencies": { - "@typescript-eslint/types": "8.71.2", - "@typescript-eslint/visitor-keys": "8.71.2" - }, - "engines": { - "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + "@typescript-eslint/types": "8.73.0", + "@typescript-eslint/visitor-keys": "8.73.0" }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" - } - }, - "node_modules/@typescript-eslint/scope-manager/node_modules/@typescript-eslint/types": { - "version": "8.71.2", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.71.2.tgz", - "integrity": "sha512-y5Ukl3oVp7e/VGxqIoEXoeb/Roj71PAJ4WG/N/RGj+eeDvKRLM15kGr9MijLbN0i03S52zxu31Z98E5gWChJKw==", - "dev": true, - "license": "MIT", "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" }, @@ -9257,9 +9358,9 @@ } }, "node_modules/@typescript-eslint/tsconfig-utils": { - "version": "8.71.2", - "resolved": "https://registry.npmjs.org/@typescript-eslint/tsconfig-utils/-/tsconfig-utils-8.71.2.tgz", - "integrity": "sha512-jz49TAWokm/7yWD9/o837nYax9DyALxIPOImdImvVzo6canBCZYzin8zJyqNR5k1j9K1DE0bVvr0XYB+99uAdg==", + "version": "8.73.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/tsconfig-utils/-/tsconfig-utils-8.73.0.tgz", + "integrity": "sha512-lmtCFOfYaJfpqZywGuXi4FpNtE+NQ+YLe3T0K9rtEDcW8ZuGWvfI++pj8r05sYMI8vWT2CYK4rWyedmD6Rp4og==", "dev": true, "license": "MIT", "engines": { @@ -9274,15 +9375,15 @@ } }, "node_modules/@typescript-eslint/type-utils": { - "version": "8.71.2", - "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-8.71.2.tgz", - "integrity": "sha512-cC8UaalCViJkb3rH/xLIvidEwoFRtMZMUqDjjJMGEKaTFwYRHYBcoczlEGHuvkHEO8svRDrgZ0yQgOArFmwang==", + "version": "8.73.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-8.73.0.tgz", + "integrity": "sha512-MOC9i4xy1F7KcDde7Ip8jf1SrRiALb2Km4UWxGNjUE2YlhjIEo1ayE27GHIwIQyfWuHTmEonQT14uyurlyC6aA==", "dev": true, "license": "MIT", "dependencies": { - "@typescript-eslint/types": "8.71.2", - "@typescript-eslint/typescript-estree": "8.71.2", - "@typescript-eslint/utils": "8.71.2", + "@typescript-eslint/types": "8.73.0", + "@typescript-eslint/typescript-estree": "8.73.0", + "@typescript-eslint/utils": "8.73.0", "debug": "^4.4.3", "ts-api-utils": "^2.5.0" }, @@ -9298,20 +9399,6 @@ "typescript": ">=4.8.4 <6.1.0" } }, - "node_modules/@typescript-eslint/type-utils/node_modules/@typescript-eslint/types": { - "version": "8.71.2", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.71.2.tgz", - "integrity": "sha512-y5Ukl3oVp7e/VGxqIoEXoeb/Roj71PAJ4WG/N/RGj+eeDvKRLM15kGr9MijLbN0i03S52zxu31Z98E5gWChJKw==", - "dev": true, - "license": "MIT", - "engines": { - "node": "^18.18.0 || ^20.9.0 || >=21.1.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" - } - }, "node_modules/@typescript-eslint/types": { "version": "8.73.0", "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.73.0.tgz", @@ -9327,18 +9414,18 @@ } }, "node_modules/@typescript-eslint/typescript-estree": { - "version": "8.71.2", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-8.71.2.tgz", - "integrity": "sha512-DgNOEsl4pdYzwSL+N/Cl33tX1Hlw3FvId73LnKXfq7jnrF2viOEn7X+P7RBkkSWCVm92gnWd28GIC5vJuLREeA==", + "version": "8.73.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-8.73.0.tgz", + "integrity": "sha512-InjlBkSdWceIwIBWSwS3ENUp+i0O02PGX3Zv2wnihWJC1WDVGvG7mTHuf8b57uAaITj94d6tRPDH+sUEtXdRQQ==", "dev": true, "license": "MIT", "dependencies": { - "@typescript-eslint/project-service": "8.71.2", - "@typescript-eslint/tsconfig-utils": "8.71.2", - "@typescript-eslint/types": "8.71.2", - "@typescript-eslint/visitor-keys": "8.71.2", + "@typescript-eslint/project-service": "8.73.0", + "@typescript-eslint/tsconfig-utils": "8.73.0", + "@typescript-eslint/types": "8.73.0", + "@typescript-eslint/visitor-keys": "8.73.0", "debug": "^4.4.3", - "minimatch": "^10.2.2", + "minimatch": "^11.0.1", "semver": "^7.7.3", "tinyglobby": "^0.2.15", "ts-api-utils": "^2.5.0" @@ -9351,34 +9438,43 @@ "url": "https://opencollective.com/typescript-eslint" }, "peerDependencies": { + "@typescript/native": "npm:typescript@>=7.1.0-dev.20261009.1 || >=7.1.0-beta <7.1.0-dev", "typescript": ">=4.8.4 <6.1.0" + }, + "peerDependenciesMeta": { + "@typescript/native": { + "optional": true + } } }, - "node_modules/@typescript-eslint/typescript-estree/node_modules/@typescript-eslint/types": { - "version": "8.71.2", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.71.2.tgz", - "integrity": "sha512-y5Ukl3oVp7e/VGxqIoEXoeb/Roj71PAJ4WG/N/RGj+eeDvKRLM15kGr9MijLbN0i03S52zxu31Z98E5gWChJKw==", + "node_modules/@typescript-eslint/typescript-estree/node_modules/minimatch": { + "version": "11.0.9", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-11.0.9.tgz", + "integrity": "sha512-KCFkfyjqerNlSstjlhIGNXIKZGA/6O4V4RlhZ+Dsr621SPPw0mzlypE9D9ZOoPiVefHID+j7/XuMMlqfD/F60Q==", "dev": true, - "license": "MIT", + "license": "BlueOak-1.0.0", + "dependencies": { + "@isaacs/nonrecursive-glob-match": "^1.1.0", + "brace-expansion": "^5.0.12" + }, "engines": { - "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + "node": "20 || >=22" }, "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" + "url": "https://github.com/sponsors/isaacs" } }, "node_modules/@typescript-eslint/utils": { - "version": "8.71.2", - "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-8.71.2.tgz", - "integrity": "sha512-RyKa1G1M9rKHDhrk+HJtiF1MvLD5Ux2JW3TSkzw+02pRALdpJb+QzG1Y5em+LvCgzGwgg8H7mBRFKljNz7ImPw==", + "version": "8.73.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-8.73.0.tgz", + "integrity": "sha512-j2SVJJvVkXdUL0WcEzo4vEH1mO1vIi8KlVukcYA2MgMZvYN2LlZR4PmsW+GTSxSW24j6Q/EP7+MOifLtg5hmsA==", "dev": true, "license": "MIT", "dependencies": { "@eslint-community/eslint-utils": "^4.9.1", - "@typescript-eslint/scope-manager": "8.71.2", - "@typescript-eslint/types": "8.71.2", - "@typescript-eslint/typescript-estree": "8.71.2" + "@typescript-eslint/scope-manager": "8.73.0", + "@typescript-eslint/types": "8.73.0", + "@typescript-eslint/typescript-estree": "8.73.0" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -9392,28 +9488,14 @@ "typescript": ">=4.8.4 <6.1.0" } }, - "node_modules/@typescript-eslint/utils/node_modules/@typescript-eslint/types": { - "version": "8.71.2", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.71.2.tgz", - "integrity": "sha512-y5Ukl3oVp7e/VGxqIoEXoeb/Roj71PAJ4WG/N/RGj+eeDvKRLM15kGr9MijLbN0i03S52zxu31Z98E5gWChJKw==", - "dev": true, - "license": "MIT", - "engines": { - "node": "^18.18.0 || ^20.9.0 || >=21.1.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" - } - }, "node_modules/@typescript-eslint/visitor-keys": { - "version": "8.71.2", - "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-8.71.2.tgz", - "integrity": "sha512-zozlN0UA32bSG2zkKAgQyRYSbEISVoyU6vvkKYo2aSny74D8Jh4e+POkJ6Lk0dlezZi5x7TtD+88Xb06IB8nhg==", + "version": "8.73.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-8.73.0.tgz", + "integrity": "sha512-k4lsFVpRZICbltkIEEH4hZRkwXkqDF1GHBpClKQOHQY+RkoZAAuyc1ci3I6p+CB6v3U4jaHIUshc4RzzQXZWLg==", "dev": true, "license": "MIT", "dependencies": { - "@typescript-eslint/types": "8.71.2", + "@typescript-eslint/types": "8.73.0", "eslint-visitor-keys": "^5.0.0" }, "engines": { @@ -9424,20 +9506,6 @@ "url": "https://opencollective.com/typescript-eslint" } }, - "node_modules/@typescript-eslint/visitor-keys/node_modules/@typescript-eslint/types": { - "version": "8.71.2", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.71.2.tgz", - "integrity": "sha512-y5Ukl3oVp7e/VGxqIoEXoeb/Roj71PAJ4WG/N/RGj+eeDvKRLM15kGr9MijLbN0i03S52zxu31Z98E5gWChJKw==", - "dev": true, - "license": "MIT", - "engines": { - "node": "^18.18.0 || ^20.9.0 || >=21.1.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" - } - }, "node_modules/@unrs/resolver-binding-android-arm-eabi": { "version": "1.13.0", "resolved": "https://registry.npmjs.org/@unrs/resolver-binding-android-arm-eabi/-/resolver-binding-android-arm-eabi-1.13.0.tgz", @@ -11789,13 +11857,13 @@ } }, "node_modules/cspell-config-lib": { - "version": "10.4.0", - "resolved": "https://registry.npmjs.org/cspell-config-lib/-/cspell-config-lib-10.4.0.tgz", - "integrity": "sha512-1P0xmWIlGqwsHf8he9BWNdqV2bvRBkxCv5ctj3oHBraRFS6CPjdJBptyjuM0dgTwxmxPFcuWhTG8miTvFMje5g==", + "version": "10.5.2", + "resolved": "https://registry.npmjs.org/cspell-config-lib/-/cspell-config-lib-10.5.2.tgz", + "integrity": "sha512-FJyqkD3eMGjxGSEiXW5V2ayCI/1su/9OHEKBNPq7YvkIb1HXVe27w1up/CXjE8fNSPet9YRz1xTeS6NcRY6mCA==", "dev": true, "license": "MIT", "dependencies": { - "@cspell/cspell-types": "10.4.0", + "@cspell/cspell-types": "10.5.2", "comment-json": "^5.0.0", "smol-toml": "^1.9.1", "yaml": "^2.9.1" @@ -11805,30 +11873,30 @@ } }, "node_modules/cspell-dictionary": { - "version": "10.4.0", - "resolved": "https://registry.npmjs.org/cspell-dictionary/-/cspell-dictionary-10.4.0.tgz", - "integrity": "sha512-FwCQBzqOxjAg+GhymrY288As9DmJqHVrkAr++0tCQ1wWFVw2Nt1W3cCKn9W987Dr+giSuNREdQFpGbQ/cHluTg==", + "version": "10.5.2", + "resolved": "https://registry.npmjs.org/cspell-dictionary/-/cspell-dictionary-10.5.2.tgz", + "integrity": "sha512-mmnvKDVZdbusX6P+wGY+HMiZGvpLbz/kJfWTXsWtWWhEHqoB22cqGXigWaS0lHtYJyoNXJ+SkqO/wvRXfL8C7Q==", "dev": true, "license": "MIT", "dependencies": { - "@cspell/cspell-performance-monitor": "10.4.0", - "@cspell/cspell-pipe": "10.4.0", - "@cspell/cspell-types": "10.4.0", - "cspell-trie-lib": "10.4.0", - "fast-equals": "^6.1.1" + "@cspell/cspell-performance-monitor": "10.5.2", + "@cspell/cspell-pipe": "10.5.2", + "@cspell/cspell-types": "10.5.2", + "cspell-trie-lib": "10.5.2", + "fast-equals": "^6.2.2" }, "engines": { "node": ">=22.18.0" } }, "node_modules/cspell-glob": { - "version": "10.4.0", - "resolved": "https://registry.npmjs.org/cspell-glob/-/cspell-glob-10.4.0.tgz", - "integrity": "sha512-XnctlpRbhln7dTmJyISw7HdsXM38CW+S7Ygm5kkAEixSyceim8RJfRj2rhtofL7B6Ra6YdRmJnm2/PWDOIVzLw==", + "version": "10.5.2", + "resolved": "https://registry.npmjs.org/cspell-glob/-/cspell-glob-10.5.2.tgz", + "integrity": "sha512-dxzd26V9ppHk1NYImqMwF8hZ5bxyLCaLX+35uxua2QUWXTsg0YAMdmLD2A0XKr9manfryBaeVp0RltKsqCGCHw==", "dev": true, "license": "MIT", "dependencies": { - "@cspell/url": "10.4.0", + "@cspell/url": "10.5.2", "picomatch": "^4.0.7" }, "engines": { @@ -11836,14 +11904,14 @@ } }, "node_modules/cspell-grammar": { - "version": "10.4.0", - "resolved": "https://registry.npmjs.org/cspell-grammar/-/cspell-grammar-10.4.0.tgz", - "integrity": "sha512-zWxN9g0oh2tzJDM3C11prpsqF2nTw5AHpXtOslTm3D5d4ZL4BfBHRj5PFxbz3Px4fKz/KptPhxSP5yGDCNtjJg==", + "version": "10.5.2", + "resolved": "https://registry.npmjs.org/cspell-grammar/-/cspell-grammar-10.5.2.tgz", + "integrity": "sha512-wvNktzzcF/yz3WzyaD1cM7QRkSUO01fqWp/XsAakwVtY46v3VA/Ifob6Nbq0RYPyxXMTMK6v7btm2Fx5nfXtHQ==", "dev": true, "license": "MIT", "dependencies": { - "@cspell/cspell-pipe": "10.4.0", - "@cspell/cspell-types": "10.4.0" + "@cspell/cspell-pipe": "10.5.2", + "@cspell/cspell-types": "10.5.2" }, "bin": { "cspell-grammar": "bin.mjs" @@ -11853,47 +11921,47 @@ } }, "node_modules/cspell-io": { - "version": "10.4.0", - "resolved": "https://registry.npmjs.org/cspell-io/-/cspell-io-10.4.0.tgz", - "integrity": "sha512-EunMcHZbgA7PYj6172t2nPFVVWo0L7xi4awIhMay27c3vYGiA+ajowIBtIdy2MLOTSqL+XOfcjkuahXh8L8BzQ==", + "version": "10.5.2", + "resolved": "https://registry.npmjs.org/cspell-io/-/cspell-io-10.5.2.tgz", + "integrity": "sha512-VhNKpbHHGxkDF7O4NWZni/e6HfNzSDsd+VKtJKs5qEmX5NBFcfLwc2/I5N7AxQPTU+vBlSx0LPNoCGWQxAgrnA==", "dev": true, "license": "MIT", "dependencies": { - "@cspell/cspell-service-bus": "10.4.0", - "@cspell/url": "10.4.0" + "@cspell/cspell-service-bus": "10.5.2", + "@cspell/url": "10.5.2" }, "engines": { "node": ">=22.18.0" } }, "node_modules/cspell-lib": { - "version": "10.4.0", - "resolved": "https://registry.npmjs.org/cspell-lib/-/cspell-lib-10.4.0.tgz", - "integrity": "sha512-wfqmn19pfEUjWy7UJ4xPeRwyb/LFXHxFVJ6maX87OLRuSE9fTP+cr74VANpKycd/rieuB2ffKta7l38n+Xhj/Q==", - "dev": true, - "license": "MIT", - "dependencies": { - "@cspell/cspell-bundled-dicts": "10.4.0", - "@cspell/cspell-performance-monitor": "10.4.0", - "@cspell/cspell-pipe": "10.4.0", - "@cspell/cspell-resolver": "10.4.0", - "@cspell/cspell-types": "10.4.0", - "@cspell/dynamic-import": "10.4.0", - "@cspell/filetypes": "10.4.0", - "@cspell/rpc": "10.4.0", - "@cspell/strong-weak-map": "10.4.0", - "@cspell/url": "10.4.0", - "cspell-config-lib": "10.4.0", - "cspell-dictionary": "10.4.0", - "cspell-glob": "10.4.0", - "cspell-grammar": "10.4.0", - "cspell-io": "10.4.0", - "cspell-trie-lib": "10.4.0", + "version": "10.5.2", + "resolved": "https://registry.npmjs.org/cspell-lib/-/cspell-lib-10.5.2.tgz", + "integrity": "sha512-D9WeCDj+ZmHz2Hu+H/Gc6C7PYhsVchJvIXTA8X/sOrG+kvXnsYF6eGcOJV1HGhVGxJpJ3CzFcTWqXUixYdh1ow==", + "dev": true, + "license": "MIT", + "dependencies": { + "@cspell/cspell-bundled-dicts": "10.5.2", + "@cspell/cspell-performance-monitor": "10.5.2", + "@cspell/cspell-pipe": "10.5.2", + "@cspell/cspell-resolver": "10.5.2", + "@cspell/cspell-types": "10.5.2", + "@cspell/dynamic-import": "10.5.2", + "@cspell/filetypes": "10.5.2", + "@cspell/rpc": "10.5.2", + "@cspell/strong-weak-map": "10.5.2", + "@cspell/url": "10.5.2", + "cspell-config-lib": "10.5.2", + "cspell-dictionary": "10.5.2", + "cspell-glob": "10.5.2", + "cspell-grammar": "10.5.2", + "cspell-io": "10.5.2", + "cspell-trie-lib": "10.5.2", "env-paths": "^4.0.0", "gensequence": "^8.0.8", "import-fresh": "^4.0.1", "resolve-from": "^5.0.0", - "vscode-languageserver-textdocument": "^1.0.15", + "vscode-languageserver-textdocument": "^1.0.16", "vscode-uri": "^3.2.0", "xdg-basedir": "^5.1.0" }, @@ -11902,16 +11970,16 @@ } }, "node_modules/cspell-trie-lib": { - "version": "10.4.0", - "resolved": "https://registry.npmjs.org/cspell-trie-lib/-/cspell-trie-lib-10.4.0.tgz", - "integrity": "sha512-3APfmYOrYEcoiDjupm3JsxLWvqa6IbJ76CqUTuIgXQH2EK0nOJ5SRKSTNP6AplDtalCs0o6VllbiRX6S81g8yw==", + "version": "10.5.2", + "resolved": "https://registry.npmjs.org/cspell-trie-lib/-/cspell-trie-lib-10.5.2.tgz", + "integrity": "sha512-cyvmveYXmKxkBVGVO/HzITnuKBqgR1fpFZXqYIRUoz5F8VbVFO0jKOVsFma+cFytWv2e2bQgcRyn3WX8kHNeRw==", "dev": true, "license": "MIT", "engines": { "node": ">=22.18.0" }, "peerDependencies": { - "@cspell/cspell-types": "10.4.0" + "@cspell/cspell-types": "10.5.2" } }, "node_modules/css-loader": { @@ -13269,18 +13337,20 @@ } }, "node_modules/eslint-plugin-import-x": { - "version": "4.17.1", - "resolved": "https://registry.npmjs.org/eslint-plugin-import-x/-/eslint-plugin-import-x-4.17.1.tgz", - "integrity": "sha512-4cdstYkKCyjumM2Q9NSI03K8D2a9F4Ssz33K2lv2hQa4KmR9jPLwk3uWGtNvclfqBrPGfGuMBwsGMbe6dMRbfg==", + "version": "4.18.1", + "resolved": "https://registry.npmjs.org/eslint-plugin-import-x/-/eslint-plugin-import-x-4.18.1.tgz", + "integrity": "sha512-D1h++38NS2Z40zf8jbd2OHqDrnIFRKpdp8sL0jP4xSDGZj6MNwEQua8F+r3tOWjcHrsWuhHOJ7wASWioJ31tfg==", "dev": true, "license": "MIT", "dependencies": { "@typescript-eslint/types": "^8.56.0", + "cjs-module-lexer": "^2.2.1", "comment-parser": "^1.4.1", "debug": "^4.4.1", + "es-module-lexer": "^3.0.3", "eslint-import-context": "^0.1.9", "is-glob": "^4.0.3", - "minimatch": "^9.0.3 || ^10.1.2", + "minimatch": "^9.0.3 || ^10.1.2 || ^11.0.1", "semver": "^7.7.2", "stable-hash-x": "^0.2.0", "unrs-resolver": "^1.9.2" @@ -13305,6 +13375,20 @@ } } }, + "node_modules/eslint-plugin-import-x/node_modules/cjs-module-lexer": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/cjs-module-lexer/-/cjs-module-lexer-2.3.0.tgz", + "integrity": "sha512-lmNyBzi6iYiqyrExTctfmjd8tInx+dHu9PBomTfH5RXS53c27JMFJgzNv5TyAnm3PgGf+MLy0+Ws41/HlVxdKQ==", + "dev": true, + "license": "MIT" + }, + "node_modules/eslint-plugin-import-x/node_modules/es-module-lexer": { + "version": "3.0.5", + "resolved": "https://registry.npmjs.org/es-module-lexer/-/es-module-lexer-3.0.5.tgz", + "integrity": "sha512-RNq2lKJw53c7z9QRHeiKeA6Ez0oikOqiBGdmxQhKDxEiOX1g5QJR4IoFVwicn8uCZcRWNrXC3NZaJihgK7aEbg==", + "dev": true, + "license": "MIT" + }, "node_modules/eslint-plugin-import/node_modules/balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", @@ -13357,15 +13441,16 @@ } }, "node_modules/eslint-plugin-jsdoc": { - "version": "65.3.2", - "resolved": "https://registry.npmjs.org/eslint-plugin-jsdoc/-/eslint-plugin-jsdoc-65.3.2.tgz", - "integrity": "sha512-/wAacMEqm0kqDQlSOqgAPsfpQRs26Lkwacx3U3HGt5h+6Gt01z33PqY5uZdfDqhawUBgEHtGCEkyzAMJKd2xvg==", + "version": "65.4.12", + "resolved": "https://registry.npmjs.org/eslint-plugin-jsdoc/-/eslint-plugin-jsdoc-65.4.12.tgz", + "integrity": "sha512-UY70YInoTCTr3Dt8xtocRSswey+AWMQJ2NS0xtkiAKjbxH5tSwYHRdbp+kVNbdYaxoulAuBRoPENKTfTO+bQrA==", "dev": true, "license": "BSD-3-Clause", "dependencies": { - "@es-joy/jsdoccomment": "~0.98.0", + "@es-joy/escodegen": "^5.0.1", + "@es-joy/jsdoccomment": "~1.2.0", "@es-joy/resolve.exports": "1.2.0", - "@typescript-eslint/utils": "^8.70.1", + "@typescript-eslint/utils": "^8.72.2", "are-docs-informative": "^0.1.1", "comment-parser": "1.4.9", "debug": "^4.4.3", @@ -13375,7 +13460,7 @@ "html-entities": "^2.6.0", "object-deep-merge": "^2.0.1", "parse-imports-exports": "^0.2.4", - "semver": "^7.8.5", + "semver": "^7.8.6", "spdx-expression-parse": "^5.0.0", "to-valid-identifier": "^1.0.0" }, @@ -13423,6 +13508,19 @@ "url": "https://opencollective.com/eslint" } }, + "node_modules/eslint-plugin-jsdoc/node_modules/semver": { + "version": "7.8.6", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.8.6.tgz", + "integrity": "sha512-9lpSSU4Mly3mrtruwLs1eLK6+gzbzqeBFwRNjIjE+9LuDpWdYctrQlQ3ej1Ilgi7gknpsTRnPoLP8DpCHqHIJw==", + "dev": true, + "license": "ISC", + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, "node_modules/eslint-plugin-jsonc": { "version": "3.4.2", "resolved": "https://registry.npmjs.org/eslint-plugin-jsonc/-/eslint-plugin-jsonc-3.4.2.tgz", @@ -13997,9 +14095,9 @@ "license": "Apache-2.0" }, "node_modules/fast-equals": { - "version": "6.2.2", - "resolved": "https://registry.npmjs.org/fast-equals/-/fast-equals-6.2.2.tgz", - "integrity": "sha512-n+XqoarWCgcar0O3om3DeNYx6xTuLWGTUF1bRZ9iuO00tsPepzP1L4V7rqtxxZ4PEya34UCESReimFvxmEVwIA==", + "version": "6.4.0", + "resolved": "https://registry.npmjs.org/fast-equals/-/fast-equals-6.4.0.tgz", + "integrity": "sha512-WueHOj7IYeH9WWwr5lZ0UaDUhG35cz7Dh2SkDMNjiinPy7Dc7CbKP+1aP5YPLjG+BQ7MA1LDxUk78exLMjDxig==", "dev": true, "license": "MIT", "engines": { @@ -14235,24 +14333,24 @@ } }, "node_modules/fork-ts-checker-webpack-plugin": { - "version": "9.2.0", - "resolved": "https://registry.npmjs.org/fork-ts-checker-webpack-plugin/-/fork-ts-checker-webpack-plugin-9.2.0.tgz", - "integrity": "sha512-twjHKpPoZEpSN7+xDIrJgt7R4uOtUsZySNCYVrQH+rLFbp54f70L/rkMIy4h1IkshTjbpbUKEWHgVzStGqafTw==", + "version": "9.1.1", + "resolved": "https://registry.npmjs.org/fork-ts-checker-webpack-plugin/-/fork-ts-checker-webpack-plugin-9.1.1.tgz", + "integrity": "sha512-n/8xNu7kj77qBSN1RvIj2Vu0TtYQYs1urDZq5mrUWQ5qS+F/Y4/NM7ewduyvxX6DzCJlQK8UJAEtrimQoV/9Jw==", "dev": true, "license": "MIT", "dependencies": { - "@babel/code-frame": "^7.29.7", + "@babel/code-frame": "^7.16.7", "chalk": "^4.1.2", - "chokidar": "^4.0.3", - "cosmiconfig": "^9.0.2", - "deepmerge": "^4.3.1", - "fs-extra": "^11.4.1", - "memfs": "^3.6.0", - "minimatch": "^9.0.9", + "chokidar": "^4.0.1", + "cosmiconfig": "^8.2.0", + "deepmerge": "^4.2.2", + "fs-extra": "^10.0.0", + "memfs": "^3.4.1", + "minimatch": "^3.0.4", "node-abort-controller": "^3.0.1", - "schema-utils": "^4.8.3", - "semver": "^7.8.6", - "tapable": "^2.3.4" + "schema-utils": "^3.1.1", + "semver": "^7.3.5", + "tapable": "^2.2.1" }, "engines": { "node": ">=14.21.3" @@ -14287,6 +14385,33 @@ "node": ">=6.9.0" } }, + "node_modules/fork-ts-checker-webpack-plugin/node_modules/ajv": { + "version": "6.15.0", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.15.0.tgz", + "integrity": "sha512-fgFx7Hfoq60ytK2c7DhnF8jIvzYgOMxfugjLOSMHjLIPgenqa7S7oaagATUq99mV6IYvN2tRmC0wnTYX6iPbMw==", + "dev": true, + "license": "MIT", + "dependencies": { + "fast-deep-equal": "^3.1.1", + "fast-json-stable-stringify": "^2.0.0", + "json-schema-traverse": "^0.4.1", + "uri-js": "^4.2.2" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/epoberezkin" + } + }, + "node_modules/fork-ts-checker-webpack-plugin/node_modules/ajv-keywords": { + "version": "3.5.2", + "resolved": "https://registry.npmjs.org/ajv-keywords/-/ajv-keywords-3.5.2.tgz", + "integrity": "sha512-5p6WTN0DdTGVQk6VjcEju19IgaHudalcfabD7yhDGeA6bcQnmL+CpveLJq/3hvfwd1aof6L386Ougkx6RfyMIQ==", + "dev": true, + "license": "MIT", + "peerDependencies": { + "ajv": "^6.9.1" + } + }, "node_modules/fork-ts-checker-webpack-plugin/node_modules/balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", @@ -14295,13 +14420,14 @@ "license": "MIT" }, "node_modules/fork-ts-checker-webpack-plugin/node_modules/brace-expansion": { - "version": "2.1.8", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.1.8.tgz", - "integrity": "sha512-BnlDzDYQoplTsZSvPi86CNzmbcb07X8ufR8fk1zivaiEJlXJkiq1MQyDCVmlWcsWbj6aWXqHnrwwevbrm/Saig==", + "version": "1.1.22", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.22.tgz", + "integrity": "sha512-CKLDTuSsN0+r1ThM0WkzzBI7dnPI6xEGfa/JnVYIK9JNBA1N1NyPwXVHor//NKD/y3sDxp764sZdLhFK7pH8XQ==", "dev": true, "license": "MIT", "dependencies": { - "balanced-match": "^1.0.0" + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" } }, "node_modules/fork-ts-checker-webpack-plugin/node_modules/chokidar": { @@ -14320,6 +14446,50 @@ "url": "https://paulmillr.com/funding/" } }, + "node_modules/fork-ts-checker-webpack-plugin/node_modules/cosmiconfig": { + "version": "8.3.6", + "resolved": "https://registry.npmjs.org/cosmiconfig/-/cosmiconfig-8.3.6.tgz", + "integrity": "sha512-kcZ6+W5QzcJ3P1Mt+83OUv/oHFqZHIx8DuxG6eZ5RGMERoLqp4BuGjhHLYGK+Kf5XVkQvqBSmAy/nGWN3qDgEA==", + "dev": true, + "license": "MIT", + "dependencies": { + "import-fresh": "^3.3.0", + "js-yaml": "^4.1.0", + "parse-json": "^5.2.0", + "path-type": "^4.0.0" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/sponsors/d-fischer" + }, + "peerDependencies": { + "typescript": ">=4.9.5" + }, + "peerDependenciesMeta": { + "typescript": { + "optional": true + } + } + }, + "node_modules/fork-ts-checker-webpack-plugin/node_modules/import-fresh": { + "version": "3.3.1", + "resolved": "https://registry.npmjs.org/import-fresh/-/import-fresh-3.3.1.tgz", + "integrity": "sha512-TR3KfrTZTYLPB6jUjfx6MF9WcWrHL9su5TObK4ZkYgBdWKPOFoSoQIdEuTuR82pmtxH2spWG9h6etwfr1pLBqQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "parent-module": "^1.0.0", + "resolve-from": "^4.0.0" + }, + "engines": { + "node": ">=6" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/fork-ts-checker-webpack-plugin/node_modules/js-tokens": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", @@ -14327,20 +14497,24 @@ "dev": true, "license": "MIT" }, + "node_modules/fork-ts-checker-webpack-plugin/node_modules/json-schema-traverse": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", + "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==", + "dev": true, + "license": "MIT" + }, "node_modules/fork-ts-checker-webpack-plugin/node_modules/minimatch": { - "version": "9.0.9", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.9.tgz", - "integrity": "sha512-OBwBN9AL4dqmETlpS2zasx+vTeWclWzkblfZk7KTA5j3jeOONz/tRCnZomUyvNg83wL5Zv9Ss6HMJXAgL8R2Yg==", + "version": "3.1.5", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.5.tgz", + "integrity": "sha512-VgjWUsnnT6n+NUk6eZq77zeFdpW2LWDzP6zFGrCbHXiYNul5Dzqk2HHQ5uFH2DNW5Xbp8+jVzaeNt94ssEEl4w==", "dev": true, "license": "ISC", "dependencies": { - "brace-expansion": "^2.0.2" + "brace-expansion": "^1.1.7" }, "engines": { - "node": ">=16 || 14 >=14.17" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" + "node": "*" } }, "node_modules/fork-ts-checker-webpack-plugin/node_modules/readdirp": { @@ -14357,6 +14531,35 @@ "url": "https://paulmillr.com/funding/" } }, + "node_modules/fork-ts-checker-webpack-plugin/node_modules/resolve-from": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-4.0.0.tgz", + "integrity": "sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=4" + } + }, + "node_modules/fork-ts-checker-webpack-plugin/node_modules/schema-utils": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/schema-utils/-/schema-utils-3.3.0.tgz", + "integrity": "sha512-pN/yOAvcC+5rQ5nERGuwrjLlYvLTbCibnZ1I7B1LaiAz9BRBlE9GMgE/eqV30P7aJQUf7Ddimy/RsbYO/GrVGg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/json-schema": "^7.0.8", + "ajv": "^6.12.5", + "ajv-keywords": "^3.5.2" + }, + "engines": { + "node": ">= 10.13.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/webpack" + } + }, "node_modules/fork-ts-checker-webpack-plugin/node_modules/semver": { "version": "7.8.6", "resolved": "https://registry.npmjs.org/semver/-/semver-7.8.6.tgz", @@ -14405,9 +14608,9 @@ } }, "node_modules/fs-extra": { - "version": "11.4.1", - "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-11.4.1.tgz", - "integrity": "sha512-KYAb4c9BJQI6QqGKthV68OHe0badztdXJWKo0WtBA9IuCFPTKvE5ZdUBglP833aMjhaSPNO4A5j/EkzZtGlKjA==", + "version": "10.1.0", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-10.1.0.tgz", + "integrity": "sha512-oRXApq54ETRj4eMiFzGnHWGy+zo5raudjuxN0b8H7s/RU2oW0Wvsx9O0ACRN/kRq9E8Vu/ReskGB5o3ji+FzHQ==", "dev": true, "license": "MIT", "dependencies": { @@ -14416,7 +14619,7 @@ "universalify": "^2.0.0" }, "engines": { - "node": ">=14.14" + "node": ">=12" } }, "node_modules/fs-monkey": { @@ -16223,9 +16426,9 @@ } }, "node_modules/jsdoc-type-pratt-parser": { - "version": "9.2.3", - "resolved": "https://registry.npmjs.org/jsdoc-type-pratt-parser/-/jsdoc-type-pratt-parser-9.2.3.tgz", - "integrity": "sha512-xsCb5EbmLWNlQ8v5zQIgSYSyf1rSyVPjh8p9G2xviOl1weHm8a611fHWUOGn7ISquCL6LoBKZvh0tcKmpVGgzw==", + "version": "9.5.0", + "resolved": "https://registry.npmjs.org/jsdoc-type-pratt-parser/-/jsdoc-type-pratt-parser-9.5.0.tgz", + "integrity": "sha512-Qu/AuBJocEUhxq187P4Ud7xGBHB+NhtrclSrS7Utkr6uNeeh8BrZ5+Ax/AGe8VXQLGY+4oYgbUp04hY8iGsIWA==", "dev": true, "license": "MIT", "dependencies": { @@ -18785,6 +18988,16 @@ "url": "https://opencollective.com/express" } }, + "node_modules/path-type": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/path-type/-/path-type-4.0.0.tgz", + "integrity": "sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, "node_modules/pathval": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/pathval/-/pathval-2.0.1.tgz", @@ -22645,235 +22858,6 @@ "typescript": ">=4.8.4 <6.1.0" } }, - "node_modules/typescript-eslint/node_modules/@typescript-eslint/eslint-plugin": { - "version": "8.73.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.73.0.tgz", - "integrity": "sha512-UkygMFer53Yzn29MCYFTHf34hGXf5KJhiDWfIm1tXtXRrym1CS6l5H9Y3yCtPWChpC0/f93H88gdj8tN0dd4kw==", - "dev": true, - "license": "MIT", - "dependencies": { - "@eslint-community/regexpp": "^4.12.2", - "@typescript-eslint/scope-manager": "8.73.0", - "@typescript-eslint/type-utils": "8.73.0", - "@typescript-eslint/utils": "8.73.0", - "@typescript-eslint/visitor-keys": "8.73.0", - "ignore": "^7.0.5", - "natural-compare": "^1.4.0", - "ts-api-utils": "^2.5.0" - }, - "engines": { - "node": "^18.18.0 || ^20.9.0 || >=21.1.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" - }, - "peerDependencies": { - "@typescript-eslint/parser": "^8.73.0", - "eslint": "^8.57.0 || ^9.0.0 || ^10.0.0", - "typescript": ">=4.8.4 <6.1.0" - } - }, - "node_modules/typescript-eslint/node_modules/@typescript-eslint/parser": { - "version": "8.73.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-8.73.0.tgz", - "integrity": "sha512-AuL45bVcmssHfZ3Di3cs9Q0l4gBm4ZFVrJOQEE7VpqW+PVgQaEwSwazz4TVIiFabXkk6U51EprYDwqw+HR8ePw==", - "dev": true, - "license": "MIT", - "dependencies": { - "@typescript-eslint/scope-manager": "8.73.0", - "@typescript-eslint/types": "8.73.0", - "@typescript-eslint/typescript-estree": "8.73.0", - "@typescript-eslint/visitor-keys": "8.73.0", - "debug": "^4.4.3" - }, - "engines": { - "node": "^18.18.0 || ^20.9.0 || >=21.1.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" - }, - "peerDependencies": { - "eslint": "^8.57.0 || ^9.0.0 || ^10.0.0", - "typescript": ">=4.8.4 <6.1.0" - } - }, - "node_modules/typescript-eslint/node_modules/@typescript-eslint/project-service": { - "version": "8.73.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/project-service/-/project-service-8.73.0.tgz", - "integrity": "sha512-/pEf8Rc4Mjk+qJnY0uO1+Gadeal8uv50xpuic+srG2vIVatA0XxvWMUeMtFvs6OCHqftiQ7/+qH4aehG5stzIA==", - "dev": true, - "license": "MIT", - "dependencies": { - "@typescript-eslint/tsconfig-utils": "^8.73.0", - "@typescript-eslint/types": "^8.73.0", - "debug": "^4.4.3" - }, - "engines": { - "node": "^18.18.0 || ^20.9.0 || >=21.1.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" - }, - "peerDependencies": { - "typescript": ">=4.8.4 <6.1.0" - } - }, - "node_modules/typescript-eslint/node_modules/@typescript-eslint/scope-manager": { - "version": "8.73.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-8.73.0.tgz", - "integrity": "sha512-/TjD738Iq2rzj5z0ixVOi+TsvgjAzZPLPaH1yWdDBytR/HTR5gMpyYWZeCe5WTQZLwk3ho8AV7U3muoQCRtXBQ==", - "dev": true, - "license": "MIT", - "dependencies": { - "@typescript-eslint/types": "8.73.0", - "@typescript-eslint/visitor-keys": "8.73.0" - }, - "engines": { - "node": "^18.18.0 || ^20.9.0 || >=21.1.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" - } - }, - "node_modules/typescript-eslint/node_modules/@typescript-eslint/tsconfig-utils": { - "version": "8.73.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/tsconfig-utils/-/tsconfig-utils-8.73.0.tgz", - "integrity": "sha512-lmtCFOfYaJfpqZywGuXi4FpNtE+NQ+YLe3T0K9rtEDcW8ZuGWvfI++pj8r05sYMI8vWT2CYK4rWyedmD6Rp4og==", - "dev": true, - "license": "MIT", - "engines": { - "node": "^18.18.0 || ^20.9.0 || >=21.1.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" - }, - "peerDependencies": { - "typescript": ">=4.8.4 <6.1.0" - } - }, - "node_modules/typescript-eslint/node_modules/@typescript-eslint/type-utils": { - "version": "8.73.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-8.73.0.tgz", - "integrity": "sha512-MOC9i4xy1F7KcDde7Ip8jf1SrRiALb2Km4UWxGNjUE2YlhjIEo1ayE27GHIwIQyfWuHTmEonQT14uyurlyC6aA==", - "dev": true, - "license": "MIT", - "dependencies": { - "@typescript-eslint/types": "8.73.0", - "@typescript-eslint/typescript-estree": "8.73.0", - "@typescript-eslint/utils": "8.73.0", - "debug": "^4.4.3", - "ts-api-utils": "^2.5.0" - }, - "engines": { - "node": "^18.18.0 || ^20.9.0 || >=21.1.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" - }, - "peerDependencies": { - "eslint": "^8.57.0 || ^9.0.0 || ^10.0.0", - "typescript": ">=4.8.4 <6.1.0" - } - }, - "node_modules/typescript-eslint/node_modules/@typescript-eslint/typescript-estree": { - "version": "8.73.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-8.73.0.tgz", - "integrity": "sha512-InjlBkSdWceIwIBWSwS3ENUp+i0O02PGX3Zv2wnihWJC1WDVGvG7mTHuf8b57uAaITj94d6tRPDH+sUEtXdRQQ==", - "dev": true, - "license": "MIT", - "dependencies": { - "@typescript-eslint/project-service": "8.73.0", - "@typescript-eslint/tsconfig-utils": "8.73.0", - "@typescript-eslint/types": "8.73.0", - "@typescript-eslint/visitor-keys": "8.73.0", - "debug": "^4.4.3", - "minimatch": "^11.0.1", - "semver": "^7.7.3", - "tinyglobby": "^0.2.15", - "ts-api-utils": "^2.5.0" - }, - "engines": { - "node": "^18.18.0 || ^20.9.0 || >=21.1.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" - }, - "peerDependencies": { - "@typescript/native": "npm:typescript@>=7.1.0-dev.20261009.1 || >=7.1.0-beta <7.1.0-dev", - "typescript": ">=4.8.4 <6.1.0" - }, - "peerDependenciesMeta": { - "@typescript/native": { - "optional": true - } - } - }, - "node_modules/typescript-eslint/node_modules/@typescript-eslint/utils": { - "version": "8.73.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-8.73.0.tgz", - "integrity": "sha512-j2SVJJvVkXdUL0WcEzo4vEH1mO1vIi8KlVukcYA2MgMZvYN2LlZR4PmsW+GTSxSW24j6Q/EP7+MOifLtg5hmsA==", - "dev": true, - "license": "MIT", - "dependencies": { - "@eslint-community/eslint-utils": "^4.9.1", - "@typescript-eslint/scope-manager": "8.73.0", - "@typescript-eslint/types": "8.73.0", - "@typescript-eslint/typescript-estree": "8.73.0" - }, - "engines": { - "node": "^18.18.0 || ^20.9.0 || >=21.1.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" - }, - "peerDependencies": { - "eslint": "^8.57.0 || ^9.0.0 || ^10.0.0", - "typescript": ">=4.8.4 <6.1.0" - } - }, - "node_modules/typescript-eslint/node_modules/@typescript-eslint/visitor-keys": { - "version": "8.73.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-8.73.0.tgz", - "integrity": "sha512-k4lsFVpRZICbltkIEEH4hZRkwXkqDF1GHBpClKQOHQY+RkoZAAuyc1ci3I6p+CB6v3U4jaHIUshc4RzzQXZWLg==", - "dev": true, - "license": "MIT", - "dependencies": { - "@typescript-eslint/types": "8.73.0", - "eslint-visitor-keys": "^5.0.0" - }, - "engines": { - "node": "^18.18.0 || ^20.9.0 || >=21.1.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" - } - }, - "node_modules/typescript-eslint/node_modules/minimatch": { - "version": "11.0.9", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-11.0.9.tgz", - "integrity": "sha512-KCFkfyjqerNlSstjlhIGNXIKZGA/6O4V4RlhZ+Dsr621SPPw0mzlypE9D9ZOoPiVefHID+j7/XuMMlqfD/F60Q==", - "dev": true, - "license": "BlueOak-1.0.0", - "dependencies": { - "@isaacs/nonrecursive-glob-match": "^1.1.0", - "brace-expansion": "^5.0.12" - }, - "engines": { - "node": "20 || >=22" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, "node_modules/unbox-primitive": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/unbox-primitive/-/unbox-primitive-1.1.0.tgz", diff --git a/package.json b/package.json index a52cce2..c5c31d4 100644 --- a/package.json +++ b/package.json @@ -32,13 +32,14 @@ "@angular/build": "^22.2.5", "@angular/cli": "^22.2.5", "@angular/compiler-cli": "^22.2.5", + "@angular/localize": "^22.2.6", "@angular/platform-browser-dynamic": "^22.2.5", "@angular/platform-server": "^22.2.5", "@angular/service-worker": "^22.2.5", "@angular/ssr": "^22.2.6", "@axe-core/playwright": "^4.13.0", "@fortawesome/free-solid-svg-icons": "^7.3.1", - "@service-soft/eslint-config": "^2.1.7", + "@service-soft/eslint-config": "^2.2.2", "@storybook/addon-a11y": "^10.6.2", "@storybook/angular": "^10.6.2", "@tailwindcss/postcss": "^4.3.3", diff --git a/projects/ngx-auth/README.md b/projects/ngx-auth/README.md index 6f8a31d..7b32a50 100644 --- a/projects/ngx-auth/README.md +++ b/projects/ngx-auth/README.md @@ -21,14 +21,16 @@ Everything works with server-side rendering: on the server nobody is logged in, - [Passwords](#passwords) - [Invitations](#invitations) - [The pages](#the-pages) + - [Translating](#translating) - [Moving from ngx-material-auth](#moving-from-ngx-material-auth) - [License](#license) # Requirements -Angular 22 with the router, and a backend with the `AuthController` of zibri 3.1 or later, 3.2 with `invitationRoutes: true` for [invitations](#invitations). What the routes answer and take, like `CurrentUserProfile`, `UserLogin` and `OtpRegistration`, comes from [zibri-contract](https://www.npmjs.com/package/zibri-contract), the package zibri declares it in. +Angular 22 with the router and `@angular/localize`, which [translates the texts](#translating), and a backend with the `AuthController` of zibri 3.1 or later, 3.2 with `invitationRoutes: true` for [invitations](#invitations). What the routes answer and take, like `CurrentUserProfile`, `UserLogin` and `OtpRegistration`, comes from [zibri-contract](https://www.npmjs.com/package/zibri-contract), the package zibri declares it in. ```sh npm install @service-soft/ngx-auth zibri-contract +ng add @angular/localize ``` [The pages](#the-pages) and [second factors](#second-factors) are built on [@service-soft/ui](https://www.npmjs.com/package/@service-soft/ui). The login and `@service-soft/ngx-auth/two-factor` draw the qr code of an authenticator app with [uqr](https://www.npmjs.com/package/uqr): @@ -285,10 +287,13 @@ A refused attempt shows the message of zibri, in the language of the request, an | Option | Default | |---|---| -| `labels` | English texts. The texts of the second factor are those of `provideSecondFactorConfig`, see [second factors](#second-factors) | +| `labels` | English texts, see [translating](#translating). The texts of the second factor are those of `provideSecondFactorConfig`, see [second factors](#second-factors) | | `requestPasswordResetRoute` of the login and the confirm page | `'/request-password-reset'`. Undefined hides the link of the login, for an app without passwords to reset | | `newPasswordMinLength` | — the `minLength` of zibri's password policy, so the browser checks it before sending | +## Translating +The default texts are `$localize` with an id of their own, like `@@ngx-auth.login.title`, so `ng extract-i18n` puts them into the messages of your app, and you translate them like its own texts. The library needs `@angular/localize` for that, `ng add @angular/localize`, also in an app of one language. A build with `localize` fills the texts in, so no part of `@angular/localize` reaches the browser. The defaults are made once a config is injected, so translations an app loads at runtime with `loadTranslations` apply as well. A text of `provideXConfig` replaces the default in every language. So translate a default in your messages, and change it in the config only to say something else: a default the config replaces stays in your messages, though nothing shows it. The messages zibri refuses a request with come in the language of the request, from zibri. + # Moving from ngx-material-auth - The package is `@service-soft/ngx-auth`, and it works with zibri instead of lbx-jwt: the routes, bodies and errors are zibri's. - `JwtAuthService` with its generics and abstract urls is `AuthService`, which you extend only for the types. The urls are the `apiUrl` and `paths` of `provideAuth`, which also replaces `NGX_AUTH_SERVICE`. diff --git a/projects/ngx-auth/accept-invitation/accept-invitation-config.model.ts b/projects/ngx-auth/accept-invitation/accept-invitation-config.model.ts index c3a5cc7..7f857f6 100644 --- a/projects/ngx-auth/accept-invitation/accept-invitation-config.model.ts +++ b/projects/ngx-auth/accept-invitation/accept-invitation-config.model.ts @@ -7,9 +7,9 @@ export type AcceptInvitationLabels = { */ title: string, /** - * Shown before the invited email. + * Says who is invited, from the invited email. */ - invitedAs: string, + invitedAs: (email: string) => string, /** * Shown when the link doesn't work, like when it was used, revoked or ran out. */ diff --git a/projects/ngx-auth/accept-invitation/accept-invitation-config.provider.ts b/projects/ngx-auth/accept-invitation/accept-invitation-config.provider.ts index 4e8e86a..73a3d2a 100644 --- a/projects/ngx-auth/accept-invitation/accept-invitation-config.provider.ts +++ b/projects/ngx-auth/accept-invitation/accept-invitation-config.provider.ts @@ -3,34 +3,42 @@ import { inject, InjectionToken, Provider } from '@angular/core'; import { AcceptInvitationConfigChanges } from './accept-invitation-config-changes.model'; import { AcceptInvitationConfig } from './accept-invitation-config.model'; -const DEFAULT_ACCEPT_INVITATION_CONFIG: AcceptInvitationConfig = { - labels: { - title: 'Invitation', - invitedAs: 'You are invited as', - invalid: 'This link doesn\'t work. It ran out, or was used or revoked already.', - renewed: 'This link ran out. A new one was mailed to the invited address.', - password: 'Password', - accept: 'Accept invitation', - decline: 'Decline', - loginRequired: 'Log in as the invited account to accept the invitation.', - otherAccount: 'You are logged in with another account. Log out, and log in as the invited one to accept the invitation.', - login: 'Log in', - logout: 'Log out', - accepted: 'The invitation was accepted.', - acceptedWithPassword: 'Your account is ready. Log in with your password.', - continue: 'Continue', - declined: 'The invitation was declined.', - failed: 'Something went wrong. Please try again.' - }, - newPasswordMinLength: undefined -}; +/** + * How the page the link of an invitation opens looks and works when nothing changes it. Its texts are $localize, which + * an app translates like its own, and resolved once the config is injected, so translations an app loads at runtime + * apply as well. + * @returns The default config. + */ +function getDefaultAcceptInvitationConfig(): AcceptInvitationConfig { + return { + labels: { + title: $localize`:@@ngx-auth.accept-invitation.title:Invitation`, + invitedAs: email => $localize`:@@ngx-auth.accept-invitation.invitedAs:You are invited as ${email}:email:`, + invalid: $localize`:@@ngx-auth.accept-invitation.invalid:This link doesn't work. It ran out, or was used or revoked already.`, + renewed: $localize`:@@ngx-auth.accept-invitation.renewed:This link ran out. A new one was mailed to the invited address.`, + password: $localize`:@@ngx-auth.accept-invitation.password:Password`, + accept: $localize`:@@ngx-auth.accept-invitation.accept:Accept invitation`, + decline: $localize`:@@ngx-auth.accept-invitation.decline:Decline`, + loginRequired: $localize`:@@ngx-auth.accept-invitation.loginRequired:Log in as the invited account to accept the invitation.`, + otherAccount: $localize`:@@ngx-auth.accept-invitation.otherAccount:You are logged in with another account. Log out, and log in as the invited one to accept the invitation.`, + login: $localize`:@@ngx-auth.accept-invitation.login:Log in`, + logout: $localize`:@@ngx-auth.accept-invitation.logout:Log out`, + accepted: $localize`:@@ngx-auth.accept-invitation.accepted:The invitation was accepted.`, + acceptedWithPassword: $localize`:@@ngx-auth.accept-invitation.acceptedWithPassword:Your account is ready. Log in with your password.`, + continue: $localize`:@@ngx-auth.accept-invitation.continue:Continue`, + declined: $localize`:@@ngx-auth.accept-invitation.declined:The invitation was declined.`, + failed: $localize`:@@ngx-auth.accept-invitation.failed:Something went wrong. Please try again.` + }, + newPasswordMinLength: undefined + }; +} /** * How the page the link of an invitation opens looks and works. Change it with provideAcceptInvitationConfig. */ export const ACCEPT_INVITATION_CONFIG: InjectionToken = new InjectionToken( 'ACCEPT_INVITATION_CONFIG', - { providedIn: 'root', factory: () => DEFAULT_ACCEPT_INVITATION_CONFIG } + { providedIn: 'root', factory: () => getDefaultAcceptInvitationConfig() } ); /** @@ -44,7 +52,7 @@ export function provideAcceptInvitationConfig(config: AcceptInvitationConfigChan provide: ACCEPT_INVITATION_CONFIG, useFactory: (): AcceptInvitationConfig => { const parent: AcceptInvitationConfig = inject(ACCEPT_INVITATION_CONFIG, { skipSelf: true, optional: true }) - ?? DEFAULT_ACCEPT_INVITATION_CONFIG; + ?? getDefaultAcceptInvitationConfig(); return { ...parent, ...config, labels: { ...parent.labels, ...config.labels } }; } }; diff --git a/projects/ngx-auth/accept-invitation/accept-invitation.component.ts b/projects/ngx-auth/accept-invitation/accept-invitation.component.ts index 4ba1ec8..5730534 100644 --- a/projects/ngx-auth/accept-invitation/accept-invitation.component.ts +++ b/projects/ngx-auth/accept-invitation/accept-invitation.component.ts @@ -99,7 +99,7 @@ export class AcceptInvitationComponent { */ protected readonly paragraphs: Signal = computed(() => { const email: string | undefined = this.validity()?.email; - const invitedAs: string[] = email == undefined ? [] : [`${this.labels.invitedAs} ${email}`]; + const invitedAs: string[] = email == undefined ? [] : [this.labels.invitedAs(email)]; const message: string | undefined = this.resolveMessage(this.state()); return message == undefined ? invitedAs : [...invitedAs, message]; }); diff --git a/projects/ngx-auth/auth/auth.service.ts b/projects/ngx-auth/auth/auth.service.ts index 824adb9..9b41d81 100644 --- a/projects/ngx-auth/auth/auth.service.ts +++ b/projects/ngx-auth/auth/auth.service.ts @@ -514,19 +514,19 @@ export abstract class AuthService< * like the email of a login, once they pick one. Start it when the input shows, if * PasskeyUtilities.isAutofillAvailable, and abort it before anything else asks for a passkey, which the browser * refuses while it waits. - * @param signal - Aborts the waiting request. + * @param abortSignal - Aborts the waiting request. * @param authenticator - The name of the passkey authenticator of zibri. * @returns Whether the user is logged in, or what the login waits for. * @throws {DOMException} An AbortError once the signal aborted it, see PasskeyUtilities.isCancelled. */ - async loginWithPasskeyAutofill(signal: AbortSignal, authenticator: string = 'passkey'): Promise { + async loginWithPasskeyAutofill(abortSignal: AbortSignal, authenticator: string = 'passkey'): Promise { const options: PublicKeyCredentialRequestOptionsJSON = await firstValueFrom(this.http.post( this.resolveUrl('loginOptions', { authenticator }), undefined, this.resolveOwnOptions() )); - signal.throwIfAborted(); - return await this.login({ response: await PasskeyUtilities.resolveAssertion(options, 'conditional', signal) }, authenticator); + abortSignal.throwIfAborted(); + return await this.login({ response: await PasskeyUtilities.resolveAssertion(options, 'conditional', abortSignal) }, authenticator); } /** diff --git a/projects/ngx-auth/change-password/change-password-config.provider.ts b/projects/ngx-auth/change-password/change-password-config.provider.ts index 6773ddc..cde6606 100644 --- a/projects/ngx-auth/change-password/change-password-config.provider.ts +++ b/projects/ngx-auth/change-password/change-password-config.provider.ts @@ -3,24 +3,32 @@ import { inject, InjectionToken, Provider } from '@angular/core'; import { ChangePasswordConfigChanges } from './change-password-config-changes.model'; import { ChangePasswordConfig } from './change-password-config.model'; -const DEFAULT_CHANGE_PASSWORD_CONFIG: ChangePasswordConfig = { - labels: { - title: 'Change your password', - currentPassword: 'Current password', - newPassword: 'New password', - save: 'Change password', - changed: 'Your password was changed. Your other devices were logged out.', - failed: 'Something went wrong. Please try again.' - }, - newPasswordMinLength: undefined -}; +/** + * How the form that changes the password looks and works when nothing changes it. Its texts are $localize, which an app + * translates like its own, and resolved once the config is injected, so translations an app loads at runtime apply as + * well. + * @returns The default config. + */ +function getDefaultChangePasswordConfig(): ChangePasswordConfig { + return { + labels: { + title: $localize`:@@ngx-auth.change-password.title:Change your password`, + currentPassword: $localize`:@@ngx-auth.change-password.currentPassword:Current password`, + newPassword: $localize`:@@ngx-auth.change-password.newPassword:New password`, + save: $localize`:@@ngx-auth.change-password.save:Change password`, + changed: $localize`:@@ngx-auth.change-password.changed:Your password was changed. Your other devices were logged out.`, + failed: $localize`:@@ngx-auth.change-password.failed:Something went wrong. Please try again.` + }, + newPasswordMinLength: undefined + }; +} /** * How the form that changes the password looks and works. Change it with provideChangePasswordConfig. */ export const CHANGE_PASSWORD_CONFIG: InjectionToken = new InjectionToken( 'CHANGE_PASSWORD_CONFIG', - { providedIn: 'root', factory: () => DEFAULT_CHANGE_PASSWORD_CONFIG } + { providedIn: 'root', factory: () => getDefaultChangePasswordConfig() } ); /** @@ -34,7 +42,7 @@ export function provideChangePasswordConfig(config: ChangePasswordConfigChanges) provide: CHANGE_PASSWORD_CONFIG, useFactory: (): ChangePasswordConfig => { const parent: ChangePasswordConfig = inject(CHANGE_PASSWORD_CONFIG, { skipSelf: true, optional: true }) - ?? DEFAULT_CHANGE_PASSWORD_CONFIG; + ?? getDefaultChangePasswordConfig(); return { ...parent, ...config, labels: { ...parent.labels, ...config.labels } }; } }; diff --git a/projects/ngx-auth/confirm-email/confirm-email-config.provider.ts b/projects/ngx-auth/confirm-email/confirm-email-config.provider.ts index 5a9d3d0..87035d7 100644 --- a/projects/ngx-auth/confirm-email/confirm-email-config.provider.ts +++ b/projects/ngx-auth/confirm-email/confirm-email-config.provider.ts @@ -3,24 +3,32 @@ import { inject, InjectionToken, Provider } from '@angular/core'; import { ConfirmEmailConfigChanges } from './confirm-email-config-changes.model'; import { ConfirmEmailConfig } from './confirm-email-config.model'; -const DEFAULT_CONFIRM_EMAIL_CONFIG: ConfirmEmailConfig = { - labels: { - title: 'Your email address', - verified: 'Your email address is verified.', - changed: 'Your email address was changed.', - waitingForOtherLink: 'Thank you. The change waits for you to follow the link we sent to your other email address as well.', - continue: 'Continue', - login: 'Log in', - failed: 'Something went wrong. Please try again.' - } -}; +/** + * What the page the link of an email opens shows when nothing changes it. Its texts are $localize, which an app + * translates like its own, and resolved once the config is injected, so translations an app loads at runtime apply as + * well. + * @returns The default config. + */ +function getDefaultConfirmEmailConfig(): ConfirmEmailConfig { + return { + labels: { + title: $localize`:@@ngx-auth.confirm-email.title:Your email address`, + verified: $localize`:@@ngx-auth.confirm-email.verified:Your email address is verified.`, + changed: $localize`:@@ngx-auth.confirm-email.changed:Your email address was changed.`, + waitingForOtherLink: $localize`:@@ngx-auth.confirm-email.waitingForOtherLink:Thank you. The change waits for you to follow the link we sent to your other email address as well.`, + continue: $localize`:@@ngx-auth.confirm-email.continue:Continue`, + login: $localize`:@@ngx-auth.confirm-email.login:Log in`, + failed: $localize`:@@ngx-auth.confirm-email.failed:Something went wrong. Please try again.` + } + }; +} /** * What the page the link of an email opens shows. Change it with provideConfirmEmailConfig. */ export const CONFIRM_EMAIL_CONFIG: InjectionToken = new InjectionToken('CONFIRM_EMAIL_CONFIG', { providedIn: 'root', - factory: () => DEFAULT_CONFIRM_EMAIL_CONFIG + factory: () => getDefaultConfirmEmailConfig() }); /** @@ -34,7 +42,7 @@ export function provideConfirmEmailConfig(config: ConfirmEmailConfigChanges): Pr provide: CONFIRM_EMAIL_CONFIG, useFactory: (): ConfirmEmailConfig => { const parent: ConfirmEmailConfig = inject(CONFIRM_EMAIL_CONFIG, { skipSelf: true, optional: true }) - ?? DEFAULT_CONFIRM_EMAIL_CONFIG; + ?? getDefaultConfirmEmailConfig(); return { labels: { ...parent.labels, ...config.labels } }; } }; diff --git a/projects/ngx-auth/confirm-password-reset/confirm-password-reset-config.provider.ts b/projects/ngx-auth/confirm-password-reset/confirm-password-reset-config.provider.ts index 3a5ded0..f9bca41 100644 --- a/projects/ngx-auth/confirm-password-reset/confirm-password-reset-config.provider.ts +++ b/projects/ngx-auth/confirm-password-reset/confirm-password-reset-config.provider.ts @@ -3,20 +3,28 @@ import { inject, InjectionToken, Provider } from '@angular/core'; import { ConfirmPasswordResetConfigChanges } from './confirm-password-reset-config-changes.model'; import { ConfirmPasswordResetConfig } from './confirm-password-reset-config.model'; -const DEFAULT_CONFIRM_PASSWORD_RESET_CONFIG: ConfirmPasswordResetConfig = { - labels: { - title: 'Choose a new password', - newPassword: 'New password', - save: 'Save password', - invalid: 'This link doesn\'t work anymore. It ran out, or was used already.', - requestNewLink: 'Get a new link', - changed: 'Your password was changed. Log in with your new password.', - login: 'Log in', - failed: 'Something went wrong. Please try again.' - }, - requestPasswordResetRoute: '/request-password-reset', - newPasswordMinLength: undefined -}; +/** + * How the page that sets a new password with the link of a password reset looks and works when nothing changes it. Its + * texts are $localize, which an app translates like its own, and resolved once the config is injected, so translations + * an app loads at runtime apply as well. + * @returns The default config. + */ +function getDefaultConfirmPasswordResetConfig(): ConfirmPasswordResetConfig { + return { + labels: { + title: $localize`:@@ngx-auth.confirm-password-reset.title:Choose a new password`, + newPassword: $localize`:@@ngx-auth.confirm-password-reset.newPassword:New password`, + save: $localize`:@@ngx-auth.confirm-password-reset.save:Save password`, + invalid: $localize`:@@ngx-auth.confirm-password-reset.invalid:This link doesn't work anymore. It ran out, or was used already.`, + requestNewLink: $localize`:@@ngx-auth.confirm-password-reset.requestNewLink:Get a new link`, + changed: $localize`:@@ngx-auth.confirm-password-reset.changed:Your password was changed. Log in with your new password.`, + login: $localize`:@@ngx-auth.confirm-password-reset.login:Log in`, + failed: $localize`:@@ngx-auth.confirm-password-reset.failed:Something went wrong. Please try again.` + }, + requestPasswordResetRoute: '/request-password-reset', + newPasswordMinLength: undefined + }; +} /** * How the page that sets a new password with the link of a password reset looks and works. Change it with @@ -24,7 +32,7 @@ const DEFAULT_CONFIRM_PASSWORD_RESET_CONFIG: ConfirmPasswordResetConfig = { */ export const CONFIRM_PASSWORD_RESET_CONFIG: InjectionToken = new InjectionToken( 'CONFIRM_PASSWORD_RESET_CONFIG', - { providedIn: 'root', factory: () => DEFAULT_CONFIRM_PASSWORD_RESET_CONFIG } + { providedIn: 'root', factory: () => getDefaultConfirmPasswordResetConfig() } ); /** @@ -38,7 +46,7 @@ export function provideConfirmPasswordResetConfig(config: ConfirmPasswordResetCo provide: CONFIRM_PASSWORD_RESET_CONFIG, useFactory: (): ConfirmPasswordResetConfig => { const parent: ConfirmPasswordResetConfig = inject(CONFIRM_PASSWORD_RESET_CONFIG, { skipSelf: true, optional: true }) - ?? DEFAULT_CONFIRM_PASSWORD_RESET_CONFIG; + ?? getDefaultConfirmPasswordResetConfig(); return { ...parent, ...config, labels: { ...parent.labels, ...config.labels } }; } }; diff --git a/projects/ngx-auth/email/email-settings-config.provider.ts b/projects/ngx-auth/email/email-settings-config.provider.ts index d8289e8..eed6cb2 100644 --- a/projects/ngx-auth/email/email-settings-config.provider.ts +++ b/projects/ngx-auth/email/email-settings-config.provider.ts @@ -3,26 +3,33 @@ import { inject, InjectionToken, Provider } from '@angular/core'; import { EmailSettingsConfigChanges } from './email-settings-config-changes.model'; import { EmailSettingsConfig } from './email-settings-config.model'; -const DEFAULT_EMAIL_SETTINGS_CONFIG: EmailSettingsConfig = { - labels: { - title: 'Email address', - verified: 'verified', - notVerified: 'not verified yet', - sendVerification: 'Send a link to verify it', - verificationSent: 'We sent you a link to verify your email address.', - newEmail: 'New email address', - change: 'Change email address', - changeRequested: newEmail => `We sent a link to ${newEmail}. Your email address changes once you followed it.`, - failed: 'Something went wrong. Please try again.' - } -}; +/** + * What the email of the logged in user shows when nothing changes it. Its texts are $localize, which an app translates + * like its own, and resolved once the config is injected, so translations an app loads at runtime apply as well. + * @returns The default config. + */ +function getDefaultEmailSettingsConfig(): EmailSettingsConfig { + return { + labels: { + title: $localize`:@@ngx-auth.email.title:Email address`, + verified: $localize`:@@ngx-auth.email.verified:verified`, + notVerified: $localize`:@@ngx-auth.email.notVerified:not verified yet`, + sendVerification: $localize`:@@ngx-auth.email.sendVerification:Send a link to verify it`, + verificationSent: $localize`:@@ngx-auth.email.verificationSent:We sent you a link to verify your email address.`, + newEmail: $localize`:@@ngx-auth.email.newEmail:New email address`, + change: $localize`:@@ngx-auth.email.change:Change email address`, + changeRequested: newEmail => $localize`:@@ngx-auth.email.changeRequested:We sent a link to ${newEmail}:newEmail:. Your email address changes once you followed it.`, + failed: $localize`:@@ngx-auth.email.failed:Something went wrong. Please try again.` + } + }; +} /** * What the email of the logged in user shows. Change it with provideEmailSettingsConfig. */ export const EMAIL_SETTINGS_CONFIG: InjectionToken = new InjectionToken('EMAIL_SETTINGS_CONFIG', { providedIn: 'root', - factory: () => DEFAULT_EMAIL_SETTINGS_CONFIG + factory: () => getDefaultEmailSettingsConfig() }); /** @@ -36,7 +43,7 @@ export function provideEmailSettingsConfig(config: EmailSettingsConfigChanges): provide: EMAIL_SETTINGS_CONFIG, useFactory: (): EmailSettingsConfig => { const parent: EmailSettingsConfig = inject(EMAIL_SETTINGS_CONFIG, { skipSelf: true, optional: true }) - ?? DEFAULT_EMAIL_SETTINGS_CONFIG; + ?? getDefaultEmailSettingsConfig(); return { labels: { ...parent.labels, ...config.labels } }; } }; diff --git a/projects/ngx-auth/email/email-settings.component.spec.ts b/projects/ngx-auth/email/email-settings.component.spec.ts index ed86970..0efc12a 100644 --- a/projects/ngx-auth/email/email-settings.component.spec.ts +++ b/projects/ngx-auth/email/email-settings.component.spec.ts @@ -2,6 +2,7 @@ import { provideHttpClient, withInterceptors } from '@angular/common/http'; import { HttpTestingController, provideHttpClientTesting, TestRequest } from '@angular/common/http/testing'; import { Service } from '@angular/core'; import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { clearTranslations, loadTranslations } from '@angular/localize'; import { provideRouter } from '@angular/router'; import { authInterceptor, AuthService, provideAuth } from '@service-soft/ngx-auth/auth'; import { FormTestingUtilities } from 'testing/form'; @@ -47,6 +48,7 @@ async function setup(): Promise<[HTMLElement, ComponentFixture { afterEach(() => { localStorage.clear(); + clearTranslations(); TestBed.inject(HttpTestingController).verify(); }); @@ -73,4 +75,19 @@ describe('EmailSettingsComponent', () => { await vi.waitFor(() => expect(FormTestingUtilities.getText(root, '[role="status"]')).toContain('We sent a link to ada@example.org.')); expect(FormTestingUtilities.findInput(root, 'new-email')?.value).toBe(''); }); + + test('shows the translations an app loaded at runtime, with the new email in its place', async () => { + loadTranslations({ + 'ngx-auth.email.change': 'E-Mail-Adresse ändern', + 'ngx-auth.email.changeRequested': 'Wir haben einen Link an {$newEmail} geschickt.' + }); + const [root, fixture, backend] = await setup(); + + FormTestingUtilities.type(root, 'new-email', 'ada@example.org'); + await fixture.whenStable(); + FormTestingUtilities.click(root, 'E-Mail-Adresse ändern'); + HttpTestingUtilities.flushNoContent(await vi.waitFor(() => backend.expectOne({ method: 'POST', url: `${API}/request-email-change` }))); + + await vi.waitFor(() => expect(FormTestingUtilities.getText(root, '[role="status"]')).toBe('Wir haben einen Link an ada@example.org geschickt.')); + }); }); \ No newline at end of file diff --git a/projects/ngx-auth/identities/identities-config.provider.ts b/projects/ngx-auth/identities/identities-config.provider.ts index 199a8db..446ff56 100644 --- a/projects/ngx-auth/identities/identities-config.provider.ts +++ b/projects/ngx-auth/identities/identities-config.provider.ts @@ -3,32 +3,40 @@ import { inject, InjectionToken, Provider } from '@angular/core'; import { IdentitiesConfigChanges } from './identities-config-changes.model'; import { IdentitiesConfig } from './identities-config.model'; -const DEFAULT_IDENTITIES_CONFIG: IdentitiesConfig = { - labels: { - title: 'Ways to log in', - passkey: 'Passkey', - passkeyAddedOn: date => `added on ${date}`, - notForLogin: 'for its apis only', - connect: name => `Connect ${name}`, - addPasskey: 'Add a passkey', - remove: 'Remove', - removeTitle: 'Remove this way to log in?', - removeMessage: 'You can\'t log in this way anymore. Keep another way to log in, like your password.', - cancel: 'Cancel', - passkeyAdded: 'Passkey added.', - removed: 'Removed.', - failed: 'Something went wrong. Please try again.' - }, - providers: [], - passkeyAuthenticator: undefined -}; +/** + * How the ways to log in of the logged in user look and work when nothing changes it. Its texts are $localize, which an + * app translates like its own, and resolved once the config is injected, so translations an app loads at runtime apply + * as well. + * @returns The default config. + */ +function getDefaultIdentitiesConfig(): IdentitiesConfig { + return { + labels: { + title: $localize`:@@ngx-auth.identities.title:Ways to log in`, + passkey: $localize`:@@ngx-auth.identities.passkey:Passkey`, + passkeyAddedOn: date => $localize`:@@ngx-auth.identities.passkeyAddedOn:added on ${date}:date:`, + notForLogin: $localize`:@@ngx-auth.identities.notForLogin:for its apis only`, + connect: name => $localize`:@@ngx-auth.identities.connect:Connect ${name}:name:`, + addPasskey: $localize`:@@ngx-auth.identities.addPasskey:Add a passkey`, + remove: $localize`:@@ngx-auth.identities.remove:Remove`, + removeTitle: $localize`:@@ngx-auth.identities.removeTitle:Remove this way to log in?`, + removeMessage: $localize`:@@ngx-auth.identities.removeMessage:You can't log in this way anymore. Keep another way to log in, like your password.`, + cancel: $localize`:@@ngx-auth.identities.cancel:Cancel`, + passkeyAdded: $localize`:@@ngx-auth.identities.passkeyAdded:Passkey added.`, + removed: $localize`:@@ngx-auth.identities.removed:Removed.`, + failed: $localize`:@@ngx-auth.identities.failed:Something went wrong. Please try again.` + }, + providers: [], + passkeyAuthenticator: undefined + }; +} /** * How the ways to log in of the logged in user look and work. Change it with provideIdentitiesConfig. */ export const IDENTITIES_CONFIG: InjectionToken = new InjectionToken('IDENTITIES_CONFIG', { providedIn: 'root', - factory: () => DEFAULT_IDENTITIES_CONFIG + factory: () => getDefaultIdentitiesConfig() }); /** @@ -41,7 +49,7 @@ export function provideIdentitiesConfig(config: IdentitiesConfigChanges): Provid return { provide: IDENTITIES_CONFIG, useFactory: (): IdentitiesConfig => { - const parent: IdentitiesConfig = inject(IDENTITIES_CONFIG, { skipSelf: true, optional: true }) ?? DEFAULT_IDENTITIES_CONFIG; + const parent: IdentitiesConfig = inject(IDENTITIES_CONFIG, { skipSelf: true, optional: true }) ?? getDefaultIdentitiesConfig(); return { ...parent, ...config, labels: { ...parent.labels, ...config.labels } }; } }; diff --git a/projects/ngx-auth/login/login-config.provider.ts b/projects/ngx-auth/login/login-config.provider.ts index 613e7a8..92444a7 100644 --- a/projects/ngx-auth/login/login-config.provider.ts +++ b/projects/ngx-auth/login/login-config.provider.ts @@ -3,37 +3,44 @@ import { inject, InjectionToken, Provider } from '@angular/core'; import { LoginConfigChanges } from './login-config-changes.model'; import { LoginConfig } from './login-config.model'; -const DEFAULT_LOGIN_CONFIG: LoginConfig = { - labels: { - title: 'Log in', - email: 'Email', - password: 'Password', - login: 'Log in', - forgotPassword: 'Forgot your password?', - loginWithPasskey: 'Log in with a passkey', - secondFactorTitle: 'Confirm it\'s you', - enrolledMessage: 'Your second factor is on. Confirm it once more to log in, with the next code.', - enrollmentTitle: 'Set up a second factor', - enrollmentMessage: 'Your account needs a second factor before you can log in. Choose how you want to confirm it\'s you.', - back: 'Back', - passwordChangeTitle: 'Choose a new password', - passwordChangeMessage: 'Your password has to be changed before you can go on.', - newPassword: 'New password', - changePassword: 'Change password', - failed: 'Something went wrong. Please try again.' - }, - requestPasswordResetRoute: '/request-password-reset', - passkeyAuthenticator: undefined, - providers: [], - newPasswordMinLength: undefined -}; +/** + * How the login looks and works when nothing changes it. Its texts are $localize, which an app translates like its own, + * and resolved once the config is injected, so translations an app loads at runtime apply as well. + * @returns The default config. + */ +function getDefaultLoginConfig(): LoginConfig { + return { + labels: { + title: $localize`:@@ngx-auth.login.title:Log in`, + email: $localize`:@@ngx-auth.login.email:Email`, + password: $localize`:@@ngx-auth.login.password:Password`, + login: $localize`:@@ngx-auth.login.login:Log in`, + forgotPassword: $localize`:@@ngx-auth.login.forgotPassword:Forgot your password?`, + loginWithPasskey: $localize`:@@ngx-auth.login.loginWithPasskey:Log in with a passkey`, + secondFactorTitle: $localize`:@@ngx-auth.login.secondFactorTitle:Confirm it's you`, + enrolledMessage: $localize`:@@ngx-auth.login.enrolledMessage:Your second factor is on. Confirm it once more to log in, with the next code.`, + enrollmentTitle: $localize`:@@ngx-auth.login.enrollmentTitle:Set up a second factor`, + enrollmentMessage: $localize`:@@ngx-auth.login.enrollmentMessage:Your account needs a second factor before you can log in. Choose how you want to confirm it's you.`, + back: $localize`:@@ngx-auth.login.back:Back`, + passwordChangeTitle: $localize`:@@ngx-auth.login.passwordChangeTitle:Choose a new password`, + passwordChangeMessage: $localize`:@@ngx-auth.login.passwordChangeMessage:Your password has to be changed before you can go on.`, + newPassword: $localize`:@@ngx-auth.login.newPassword:New password`, + changePassword: $localize`:@@ngx-auth.login.changePassword:Change password`, + failed: $localize`:@@ngx-auth.login.failed:Something went wrong. Please try again.` + }, + requestPasswordResetRoute: '/request-password-reset', + passkeyAuthenticator: undefined, + providers: [], + newPasswordMinLength: undefined + }; +} /** * How the login looks and works. Change it with provideLoginConfig. */ export const LOGIN_CONFIG: InjectionToken = new InjectionToken('LOGIN_CONFIG', { providedIn: 'root', - factory: () => DEFAULT_LOGIN_CONFIG + factory: () => getDefaultLoginConfig() }); /** @@ -46,7 +53,7 @@ export function provideLoginConfig(config: LoginConfigChanges): Provider { return { provide: LOGIN_CONFIG, useFactory: (): LoginConfig => { - const parent: LoginConfig = inject(LOGIN_CONFIG, { skipSelf: true, optional: true }) ?? DEFAULT_LOGIN_CONFIG; + const parent: LoginConfig = inject(LOGIN_CONFIG, { skipSelf: true, optional: true }) ?? getDefaultLoginConfig(); return { ...parent, ...config, labels: { ...parent.labels, ...config.labels } }; } }; diff --git a/projects/ngx-auth/package.json b/projects/ngx-auth/package.json index 0c0a3dd..be59e37 100644 --- a/projects/ngx-auth/package.json +++ b/projects/ngx-auth/package.json @@ -1,6 +1,6 @@ { "name": "@service-soft/ngx-auth", - "version": "22.3.0", + "version": "22.3.1", "license": "MIT", "repository": { "type": "git", @@ -21,14 +21,18 @@ "peerDependencies": { "@angular/common": "^22.2.0", "@angular/core": "^22.2.0", + "@angular/localize": "^22.2.0", "@angular/router": "^22.2.0", "@fortawesome/free-solid-svg-icons": "^7.3.1", - "@service-soft/ui": "^22.3.0", + "@service-soft/ui": "^22.3.1", "tailwindcss": "^4.3.3", "uqr": "^0.1.3", "zibri-contract": "^3.2.0" }, "peerDependenciesMeta": { + "@angular/localize": { + "optional": true + }, "@fortawesome/free-solid-svg-icons": { "optional": true }, diff --git a/projects/ngx-auth/provider-error/provider-error-config.provider.ts b/projects/ngx-auth/provider-error/provider-error-config.provider.ts index 8560a4c..3654194 100644 --- a/projects/ngx-auth/provider-error/provider-error-config.provider.ts +++ b/projects/ngx-auth/provider-error/provider-error-config.provider.ts @@ -3,32 +3,40 @@ import { inject, InjectionToken, Provider } from '@angular/core'; import { ProviderErrorConfigChanges } from './provider-error-config-changes.model'; import { ProviderErrorConfig } from './provider-error-config.model'; -const DEFAULT_PROVIDER_ERROR_CONFIG: ProviderErrorConfig = { - labels: { - title: 'Logging in didn\'t work', - // the errors zibri lands a failed login on its errorUrl with - errors: { - cancelled: 'You didn\'t allow the login at the provider.', - provider_error: 'The provider didn\'t answer as expected. Please try again later.', - expired: 'The login took too long, or was started in another browser. Please try again.', - invalid: 'The answer of the provider couldn\'t be checked. Please try again.', - already_linked: 'This account at the provider is connected to another user already.', - not_for_login: 'This account at the provider can\'t be used to log in.', - not_linked: 'The account of this login doesn\'t exist anymore.', - refused: 'You can\'t log in with this account right now.', - failed: 'Logging in didn\'t work. Please try again later.' - }, - backToLogin: 'Back to the login', - backToApp: 'Back' - } -}; +/** + * What the page a failed login at a provider lands on shows when nothing changes it. Its texts are $localize, which an + * app translates like its own, and resolved once the config is injected, so translations an app loads at runtime apply + * as well. + * @returns The default config. + */ +function getDefaultProviderErrorConfig(): ProviderErrorConfig { + return { + labels: { + title: $localize`:@@ngx-auth.provider-error.title:Logging in didn't work`, + // the errors zibri lands a failed login on its errorUrl with + errors: { + cancelled: $localize`:@@ngx-auth.provider-error.errors.cancelled:You didn't allow the login at the provider.`, + provider_error: $localize`:@@ngx-auth.provider-error.errors.provider_error:The provider didn't answer as expected. Please try again later.`, + expired: $localize`:@@ngx-auth.provider-error.errors.expired:The login took too long, or was started in another browser. Please try again.`, + invalid: $localize`:@@ngx-auth.provider-error.errors.invalid:The answer of the provider couldn't be checked. Please try again.`, + already_linked: $localize`:@@ngx-auth.provider-error.errors.already_linked:This account at the provider is connected to another user already.`, + not_for_login: $localize`:@@ngx-auth.provider-error.errors.not_for_login:This account at the provider can't be used to log in.`, + not_linked: $localize`:@@ngx-auth.provider-error.errors.not_linked:The account of this login doesn't exist anymore.`, + refused: $localize`:@@ngx-auth.provider-error.errors.refused:You can't log in with this account right now.`, + failed: $localize`:@@ngx-auth.provider-error.errors.failed:Logging in didn't work. Please try again later.` + }, + backToLogin: $localize`:@@ngx-auth.provider-error.backToLogin:Back to the login`, + backToApp: $localize`:@@ngx-auth.provider-error.backToApp:Back` + } + }; +} /** * What the page a failed login at a provider lands on shows. Change it with provideProviderErrorConfig. */ export const PROVIDER_ERROR_CONFIG: InjectionToken = new InjectionToken( 'PROVIDER_ERROR_CONFIG', - { providedIn: 'root', factory: () => DEFAULT_PROVIDER_ERROR_CONFIG } + { providedIn: 'root', factory: () => getDefaultProviderErrorConfig() } ); /** @@ -42,7 +50,7 @@ export function provideProviderErrorConfig(config: ProviderErrorConfigChanges): provide: PROVIDER_ERROR_CONFIG, useFactory: (): ProviderErrorConfig => { const parent: ProviderErrorConfig = inject(PROVIDER_ERROR_CONFIG, { skipSelf: true, optional: true }) - ?? DEFAULT_PROVIDER_ERROR_CONFIG; + ?? getDefaultProviderErrorConfig(); return { labels: { ...parent.labels, ...config.labels, errors: { ...parent.labels.errors, ...config.labels?.errors } } }; } }; diff --git a/projects/ngx-auth/request-password-reset/request-password-reset-config.provider.ts b/projects/ngx-auth/request-password-reset/request-password-reset-config.provider.ts index f5d2df7..fef12a4 100644 --- a/projects/ngx-auth/request-password-reset/request-password-reset-config.provider.ts +++ b/projects/ngx-auth/request-password-reset/request-password-reset-config.provider.ts @@ -3,24 +3,32 @@ import { inject, InjectionToken, Provider } from '@angular/core'; import { RequestPasswordResetConfigChanges } from './request-password-reset-config-changes.model'; import { RequestPasswordResetConfig } from './request-password-reset-config.model'; -const DEFAULT_REQUEST_PASSWORD_RESET_CONFIG: RequestPasswordResetConfig = { - labels: { - title: 'Reset your password', - message: 'Enter the email of your account, and we send you a link to choose a new password.', - email: 'Email', - send: 'Send link', - sent: 'If an account belongs to this email, we sent it a link. It only works for a short time.', - backToLogin: 'Back to the login', - failed: 'Something went wrong. Please try again.' - } -}; +/** + * What the page that sends a link to reset the password shows when nothing changes it. Its texts are $localize, which + * an app translates like its own, and resolved once the config is injected, so translations an app loads at runtime + * apply as well. + * @returns The default config. + */ +function getDefaultRequestPasswordResetConfig(): RequestPasswordResetConfig { + return { + labels: { + title: $localize`:@@ngx-auth.request-password-reset.title:Reset your password`, + message: $localize`:@@ngx-auth.request-password-reset.message:Enter the email of your account, and we send you a link to choose a new password.`, + email: $localize`:@@ngx-auth.request-password-reset.email:Email`, + send: $localize`:@@ngx-auth.request-password-reset.send:Send link`, + sent: $localize`:@@ngx-auth.request-password-reset.sent:If an account belongs to this email, we sent it a link. It only works for a short time.`, + backToLogin: $localize`:@@ngx-auth.request-password-reset.backToLogin:Back to the login`, + failed: $localize`:@@ngx-auth.request-password-reset.failed:Something went wrong. Please try again.` + } + }; +} /** * What the page that sends a link to reset the password shows. Change it with provideRequestPasswordResetConfig. */ export const REQUEST_PASSWORD_RESET_CONFIG: InjectionToken = new InjectionToken( 'REQUEST_PASSWORD_RESET_CONFIG', - { providedIn: 'root', factory: () => DEFAULT_REQUEST_PASSWORD_RESET_CONFIG } + { providedIn: 'root', factory: () => getDefaultRequestPasswordResetConfig() } ); /** @@ -34,7 +42,7 @@ export function provideRequestPasswordResetConfig(config: RequestPasswordResetCo provide: REQUEST_PASSWORD_RESET_CONFIG, useFactory: (): RequestPasswordResetConfig => { const parent: RequestPasswordResetConfig = inject(REQUEST_PASSWORD_RESET_CONFIG, { skipSelf: true, optional: true }) - ?? DEFAULT_REQUEST_PASSWORD_RESET_CONFIG; + ?? getDefaultRequestPasswordResetConfig(); return { ...parent, labels: { ...parent.labels, ...config.labels } }; } }; diff --git a/projects/ngx-auth/second-factor/second-factor-config.provider.ts b/projects/ngx-auth/second-factor/second-factor-config.provider.ts index 5c64bed..84bc3e5 100644 --- a/projects/ngx-auth/second-factor/second-factor-config.provider.ts +++ b/projects/ngx-auth/second-factor/second-factor-config.provider.ts @@ -3,47 +3,67 @@ import { inject, InjectionToken, Provider } from '@angular/core'; import { SecondFactorConfigChanges } from './second-factor-config-changes.model'; import { SecondFactorConfig } from './second-factor-config.model'; -const DEFAULT_SECOND_FACTOR_CONFIG: SecondFactorConfig = { - labels: { - code: 'Code', - methods: { - otp: { - name: 'Authenticator app', - choose: 'Use your authenticator app', - hint: 'Enter the code your authenticator app shows.' - }, - email: { name: 'Codes by email', choose: 'Get a code by email', hint: 'Enter the code we sent to your email.' }, - sms: { name: 'Codes by text message', choose: 'Get a code by text message', hint: 'Enter the code we sent to your phone.' }, - 'recovery-code': { - name: 'Recovery codes', - choose: 'Use a recovery code', - hint: 'Enter one of the recovery codes you saved.' +/** + * How second factors are asked for and enrolled when nothing changes it. Its texts are $localize, which an app + * translates like its own, and resolved once the config is injected, so translations an app loads at runtime apply as + * well. + * @returns The default config. + */ +function getDefaultSecondFactorConfig(): SecondFactorConfig { + return { + labels: { + code: $localize`:@@ngx-auth.second-factor.code:Code`, + methods: { + otp: { + name: $localize`:@@ngx-auth.second-factor.methods.otp.name:Authenticator app`, + choose: $localize`:@@ngx-auth.second-factor.methods.otp.choose:Use your authenticator app`, + hint: $localize`:@@ngx-auth.second-factor.methods.otp.hint:Enter the code your authenticator app shows.` + }, + email: { + name: $localize`:@@ngx-auth.second-factor.methods.email.name:Codes by email`, + choose: $localize`:@@ngx-auth.second-factor.methods.email.choose:Get a code by email`, + hint: $localize`:@@ngx-auth.second-factor.methods.email.hint:Enter the code we sent to your email.` + }, + sms: { + name: $localize`:@@ngx-auth.second-factor.methods.sms.name:Codes by text message`, + choose: $localize`:@@ngx-auth.second-factor.methods.sms.choose:Get a code by text message`, + hint: $localize`:@@ngx-auth.second-factor.methods.sms.hint:Enter the code we sent to your phone.` + }, + 'recovery-code': { + name: $localize`:@@ngx-auth.second-factor.methods.recovery-code.name:Recovery codes`, + choose: $localize`:@@ngx-auth.second-factor.methods.recovery-code.choose:Use a recovery code`, + hint: $localize`:@@ngx-auth.second-factor.methods.recovery-code.hint:Enter one of the recovery codes you saved.` + }, + passkey: { + name: $localize`:@@ngx-auth.second-factor.methods.passkey.name:Passkeys`, + choose: $localize`:@@ngx-auth.second-factor.methods.passkey.choose:Use a passkey`, + hint: $localize`:@@ngx-auth.second-factor.methods.passkey.hint:Use a passkey of this device, or your security key.` + } }, - passkey: { name: 'Passkeys', choose: 'Use a passkey', hint: 'Use a passkey of this device, or your security key.' } + noMethod: $localize`:@@ngx-auth.second-factor.noMethod:None of your second factors can be used here.`, + sendCode: $localize`:@@ngx-auth.second-factor.sendCode:Send a new code`, + confirm: $localize`:@@ngx-auth.second-factor.confirm:Confirm`, + usePasskey: $localize`:@@ngx-auth.second-factor.usePasskey:Use passkey`, + codeSent: $localize`:@@ngx-auth.second-factor.codeSent:We sent you a code.`, + newCodeSent: $localize`:@@ngx-auth.second-factor.newCodeSent:We sent you a new code.` }, - noMethod: 'None of your second factors can be used here.', - sendCode: 'Send a new code', - confirm: 'Confirm', - usePasskey: 'Use passkey', - codeSent: 'We sent you a code.', - newCodeSent: 'We sent you a new code.' - }, - // the two factor methods of zibri, by the names it gives them. - methods: { - otp: { confirmation: 'code', sendsCode: false, numeric: true, enrollment: 'authenticatorApp' }, - email: { confirmation: 'code', sendsCode: true, numeric: true, enrollment: 'emailCode' }, - sms: { confirmation: 'code', sendsCode: true, numeric: true, enrollment: 'smsCode' }, - 'recovery-code': { confirmation: 'code', sendsCode: false, numeric: false, enrollment: 'recoveryCodes' }, - passkey: { confirmation: 'passkey', sendsCode: false, numeric: false, enrollment: 'passkey' } - } -}; + // the two factor methods of zibri, by the names it gives them. + methods: { + otp: { confirmation: 'code', sendsCode: false, numeric: true, enrollment: 'authenticatorApp' }, + email: { confirmation: 'code', sendsCode: true, numeric: true, enrollment: 'emailCode' }, + sms: { confirmation: 'code', sendsCode: true, numeric: true, enrollment: 'smsCode' }, + 'recovery-code': { confirmation: 'code', sendsCode: false, numeric: false, enrollment: 'recoveryCodes' }, + passkey: { confirmation: 'passkey', sendsCode: false, numeric: false, enrollment: 'passkey' } + } + }; +} /** * How second factors are asked for and enrolled. Change it with provideSecondFactorConfig. */ export const SECOND_FACTOR_CONFIG: InjectionToken = new InjectionToken('SECOND_FACTOR_CONFIG', { providedIn: 'root', - factory: () => DEFAULT_SECOND_FACTOR_CONFIG + factory: () => getDefaultSecondFactorConfig() }); /** @@ -58,7 +78,7 @@ export function provideSecondFactorConfig(config: SecondFactorConfigChanges): Pr provide: SECOND_FACTOR_CONFIG, useFactory: (): SecondFactorConfig => { const parent: SecondFactorConfig = inject(SECOND_FACTOR_CONFIG, { skipSelf: true, optional: true }) - ?? DEFAULT_SECOND_FACTOR_CONFIG; + ?? getDefaultSecondFactorConfig(); return { labels: { ...parent.labels, ...config.labels, methods: { ...parent.labels.methods, ...config.labels?.methods } }, methods: { ...parent.methods, ...config.methods } diff --git a/projects/ngx-auth/sessions/sessions-config.provider.ts b/projects/ngx-auth/sessions/sessions-config.provider.ts index 41ecfc2..d8a468f 100644 --- a/projects/ngx-auth/sessions/sessions-config.provider.ts +++ b/projects/ngx-auth/sessions/sessions-config.provider.ts @@ -3,28 +3,36 @@ import { inject, InjectionToken, Provider } from '@angular/core'; import { SessionsConfigChanges } from './sessions-config-changes.model'; import { SessionsConfig } from './sessions-config.model'; -const DEFAULT_SESSIONS_CONFIG: SessionsConfig = { - labels: { - title: 'Where you\'re logged in', - thisDevice: 'this device', - unknownBrowser: 'Unknown browser', - lastUsedOn: date => `last used on ${date}`, - logout: 'Log out', - logoutEverywhere: 'Log out everywhere', - logoutEverywhereTitle: 'Log out everywhere?', - logoutEverywhereMessage: 'You are logged out on every device, this one too.', - cancel: 'Cancel', - loggedOut: 'Logged out there.', - failed: 'Something went wrong. Please try again.' - } -}; +/** + * What the list of where the logged in user is logged in shows when nothing changes it. Its texts are $localize, which + * an app translates like its own, and resolved once the config is injected, so translations an app loads at runtime + * apply as well. + * @returns The default config. + */ +function getDefaultSessionsConfig(): SessionsConfig { + return { + labels: { + title: $localize`:@@ngx-auth.sessions.title:Where you're logged in`, + thisDevice: $localize`:@@ngx-auth.sessions.thisDevice:this device`, + unknownBrowser: $localize`:@@ngx-auth.sessions.unknownBrowser:Unknown browser`, + lastUsedOn: date => $localize`:@@ngx-auth.sessions.lastUsedOn:last used on ${date}:date:`, + logout: $localize`:@@ngx-auth.sessions.logout:Log out`, + logoutEverywhere: $localize`:@@ngx-auth.sessions.logoutEverywhere:Log out everywhere`, + logoutEverywhereTitle: $localize`:@@ngx-auth.sessions.logoutEverywhereTitle:Log out everywhere?`, + logoutEverywhereMessage: $localize`:@@ngx-auth.sessions.logoutEverywhereMessage:You are logged out on every device, this one too.`, + cancel: $localize`:@@ngx-auth.sessions.cancel:Cancel`, + loggedOut: $localize`:@@ngx-auth.sessions.loggedOut:Logged out there.`, + failed: $localize`:@@ngx-auth.sessions.failed:Something went wrong. Please try again.` + } + }; +} /** * What the list of where the logged in user is logged in shows. Change it with provideSessionsConfig. */ export const SESSIONS_CONFIG: InjectionToken = new InjectionToken('SESSIONS_CONFIG', { providedIn: 'root', - factory: () => DEFAULT_SESSIONS_CONFIG + factory: () => getDefaultSessionsConfig() }); /** @@ -37,7 +45,7 @@ export function provideSessionsConfig(config: SessionsConfigChanges): Provider { return { provide: SESSIONS_CONFIG, useFactory: (): SessionsConfig => { - const parent: SessionsConfig = inject(SESSIONS_CONFIG, { skipSelf: true, optional: true }) ?? DEFAULT_SESSIONS_CONFIG; + const parent: SessionsConfig = inject(SESSIONS_CONFIG, { skipSelf: true, optional: true }) ?? getDefaultSessionsConfig(); return { labels: { ...parent.labels, ...config.labels } }; } }; diff --git a/projects/ngx-auth/tsconfig.lib.json b/projects/ngx-auth/tsconfig.lib.json index 5ed1187..5315f63 100644 --- a/projects/ngx-auth/tsconfig.lib.json +++ b/projects/ngx-auth/tsconfig.lib.json @@ -8,7 +8,7 @@ // the paths of the workspace point to the sources of the other libraries, which the build would then compile // into this one. Without them, they resolve from node_modules like for a consumer, so ui has to be built first. "paths": {}, - "types": [] + "types": ["@angular/localize"] }, "exclude": ["**/*.spec.ts", "**/*.stories.ts"], "extends": "../../tsconfig.json", diff --git a/projects/ngx-auth/tsconfig.spec.json b/projects/ngx-auth/tsconfig.spec.json index cf926c8..d1df25e 100644 --- a/projects/ngx-auth/tsconfig.spec.json +++ b/projects/ngx-auth/tsconfig.spec.json @@ -3,7 +3,7 @@ { "compilerOptions": { "outDir": "../../out-tsc/spec", - "types": ["vitest/globals"] + "types": ["vitest/globals", "@angular/localize"] }, "extends": "../../tsconfig.json", "include": ["**/*.d.ts", "**/*.spec.ts"] diff --git a/projects/ngx-auth/two-factor/two-factor-config.provider.ts b/projects/ngx-auth/two-factor/two-factor-config.provider.ts index 57b2aa0..9bb9fbe 100644 --- a/projects/ngx-auth/two-factor/two-factor-config.provider.ts +++ b/projects/ngx-auth/two-factor/two-factor-config.provider.ts @@ -3,43 +3,50 @@ import { inject, InjectionToken, Provider } from '@angular/core'; import { TwoFactorConfigChanges } from './two-factor-config-changes.model'; import { TwoFactorConfig } from './two-factor-config.model'; -const DEFAULT_TWO_FACTOR_CONFIG: TwoFactorConfig = { - labels: { - dialogTitle: 'Confirm it\'s you', - cancel: 'Cancel', - scanQrCode: 'Scan the QR code with your authenticator app, then enter the code it shows.', - qrCode: 'QR code for your authenticator app', - secret: 'Can\'t scan it? Enter this key in the app instead:', - phoneNumber: 'Phone number', - phoneNumberHint: 'With the country code, like +49 151 12345678.', - sendCode: 'Send code', - saveRecoveryCodes: 'Save these codes somewhere safe, like in a password manager. Each one works once, when you can\'t use ' - + 'your other second factors. You won\'t see them again.', - confirmRecoveryCodes: 'Enter one of the codes, to show that you saved them.', - createPasskeyMessage: 'Your device asks you to confirm the passkey, like with your fingerprint, your face or its PIN.', - createPasskey: 'Create passkey', - turnOn: 'Turn on', - retry: 'Try again', - settingsTitle: 'Two-factor authentication', - on: 'On', - off: 'Off', - setUp: 'Set up', - newRecoveryCodes: 'Get new codes', - turnOff: 'Turn off', - turnOffTitle: 'Turn off this second factor?', - turnOffMessage: 'Your account is less safe with fewer second factors.', - turnedOn: 'Turned on.', - turnedOff: 'Turned off.', - failed: 'Something went wrong. Please try again.' - } -}; +/** + * What the dialog, the enrollment and the settings of two factor methods show when nothing changes it. Its texts are + * $localize, which an app translates like its own, and resolved once the config is injected, so translations an app + * loads at runtime apply as well. + * @returns The default config. + */ +function getDefaultTwoFactorConfig(): TwoFactorConfig { + return { + labels: { + dialogTitle: $localize`:@@ngx-auth.two-factor.dialogTitle:Confirm it's you`, + cancel: $localize`:@@ngx-auth.two-factor.cancel:Cancel`, + scanQrCode: $localize`:@@ngx-auth.two-factor.scanQrCode:Scan the QR code with your authenticator app, then enter the code it shows.`, + qrCode: $localize`:@@ngx-auth.two-factor.qrCode:QR code for your authenticator app`, + secret: $localize`:@@ngx-auth.two-factor.secret:Can't scan it? Enter this key in the app instead:`, + phoneNumber: $localize`:@@ngx-auth.two-factor.phoneNumber:Phone number`, + phoneNumberHint: $localize`:@@ngx-auth.two-factor.phoneNumberHint:With the country code, like +49 151 12345678.`, + sendCode: $localize`:@@ngx-auth.two-factor.sendCode:Send code`, + saveRecoveryCodes: $localize`:@@ngx-auth.two-factor.saveRecoveryCodes:Save these codes somewhere safe, like in a password manager. Each one works once, when you can't use your other second factors. You won't see them again.`, + confirmRecoveryCodes: $localize`:@@ngx-auth.two-factor.confirmRecoveryCodes:Enter one of the codes, to show that you saved them.`, + createPasskeyMessage: $localize`:@@ngx-auth.two-factor.createPasskeyMessage:Your device asks you to confirm the passkey, like with your fingerprint, your face or its PIN.`, + createPasskey: $localize`:@@ngx-auth.two-factor.createPasskey:Create passkey`, + turnOn: $localize`:@@ngx-auth.two-factor.turnOn:Turn on`, + retry: $localize`:@@ngx-auth.two-factor.retry:Try again`, + settingsTitle: $localize`:@@ngx-auth.two-factor.settingsTitle:Two-factor authentication`, + on: $localize`:@@ngx-auth.two-factor.on:On`, + off: $localize`:@@ngx-auth.two-factor.off:Off`, + setUp: $localize`:@@ngx-auth.two-factor.setUp:Set up`, + newRecoveryCodes: $localize`:@@ngx-auth.two-factor.newRecoveryCodes:Get new codes`, + turnOff: $localize`:@@ngx-auth.two-factor.turnOff:Turn off`, + turnOffTitle: $localize`:@@ngx-auth.two-factor.turnOffTitle:Turn off this second factor?`, + turnOffMessage: $localize`:@@ngx-auth.two-factor.turnOffMessage:Your account is less safe with fewer second factors.`, + turnedOn: $localize`:@@ngx-auth.two-factor.turnedOn:Turned on.`, + turnedOff: $localize`:@@ngx-auth.two-factor.turnedOff:Turned off.`, + failed: $localize`:@@ngx-auth.two-factor.failed:Something went wrong. Please try again.` + } + }; +} /** * What the dialog, the enrollment and the settings of two factor methods show. Change it with provideTwoFactorConfig. */ export const TWO_FACTOR_CONFIG: InjectionToken = new InjectionToken('TWO_FACTOR_CONFIG', { providedIn: 'root', - factory: () => DEFAULT_TWO_FACTOR_CONFIG + factory: () => getDefaultTwoFactorConfig() }); /** @@ -53,7 +60,7 @@ export function provideTwoFactorConfig(config: TwoFactorConfigChanges): Provider return { provide: TWO_FACTOR_CONFIG, useFactory: (): TwoFactorConfig => { - const parent: TwoFactorConfig = inject(TWO_FACTOR_CONFIG, { skipSelf: true, optional: true }) ?? DEFAULT_TWO_FACTOR_CONFIG; + const parent: TwoFactorConfig = inject(TWO_FACTOR_CONFIG, { skipSelf: true, optional: true }) ?? getDefaultTwoFactorConfig(); return { labels: { ...parent.labels, ...config.labels } }; } }; diff --git a/projects/ngx-change-sets/README.md b/projects/ngx-change-sets/README.md index 7de0239..3885184 100644 --- a/projects/ngx-change-sets/README.md +++ b/projects/ngx-change-sets/README.md @@ -10,14 +10,16 @@ It is built on [@service-soft/ui](https://www.npmjs.com/package/@service-soft/ui - [Setup](#setup) - [Usage](#usage) - [Configuration](#configuration) + - [Translating](#translating) - [Moving from ngx-material-change-sets](#moving-from-ngx-material-change-sets) - [License](#license) # Requirements -Angular 22 and Tailwind CSS 4. The change sets, like `ChangeSetEntity` and `ChangeSetType`, come from [zibri-contract](https://www.npmjs.com/package/zibri-contract), the package zibri declares them in. +Angular 22 with `@angular/localize`, which [translates the texts](#translating), and Tailwind CSS 4. The change sets, like `ChangeSetEntity` and `ChangeSetType`, come from [zibri-contract](https://www.npmjs.com/package/zibri-contract), the package zibri declares them in. ```sh npm install @service-soft/ngx-change-sets @service-soft/ui zibri-contract +ng add @angular/localize ``` # Setup @@ -95,6 +97,9 @@ provideChangeSetsConfig({ | `labels` | the English texts of the component, to translate them | | `resetConfirmDialogData`, `rollbackConfirmDialogData` | the title, text and buttons of the questions before undoing | +## Translating +The default texts are `$localize` with an id of their own, like `@@ngx-change-sets.change-sets.showMore`, so `ng extract-i18n` puts them into the messages of your app, and you translate them like its own texts. The library needs `@angular/localize` for that, `ng add @angular/localize`, also in an app of one language. A build with `localize` fills the texts in, so no part of `@angular/localize` reaches the browser. The defaults are made once a config is injected, so translations an app loads at runtime with `loadTranslations` apply as well. A text of `provideChangeSetsConfig` replaces the default in every language. So translate a default in your messages, and change it in the config only to say something else: a default the config replaces stays in your messages, though nothing shows it. + # Moving from ngx-material-change-sets - It needs `@service-soft/ui` and Tailwind instead of Angular Material and the Font Awesome packages. Import from `@service-soft/ngx-change-sets/change-sets`. - `` is ``. The `config` input is gone: the labels, formats and dialog texts are set with `provideChangeSetsConfig`, and `canResetAndRollback` and `canOpenCreatedBy` are inputs, which only take booleans. diff --git a/projects/ngx-change-sets/change-sets/change-set.service.ts b/projects/ngx-change-sets/change-sets/change-set.service.ts index db8f0ad..8489dff 100644 --- a/projects/ngx-change-sets/change-sets/change-set.service.ts +++ b/projects/ngx-change-sets/change-sets/change-set.service.ts @@ -53,7 +53,7 @@ export abstract class ChangeSetService { * @returns The createdBy of the change set by default, or 'System' when it has none. */ resolveCreatedByName(changeSet: ChangeSet): string | Promise { - return changeSet.createdBy ?? 'System'; + return changeSet.createdBy ?? $localize`:@@ngx-change-sets.change-sets.system:System`; } /** diff --git a/projects/ngx-change-sets/change-sets/change-sets-config.provider.ts b/projects/ngx-change-sets/change-sets/change-sets-config.provider.ts index b4b004c..1eeeb9e 100644 --- a/projects/ngx-change-sets/change-sets/change-sets-config.provider.ts +++ b/projects/ngx-change-sets/change-sets/change-sets-config.provider.ts @@ -4,47 +4,54 @@ import { ChangeSetType } from 'zibri-contract'; import { ChangeSetsConfigChanges } from './change-sets-config-changes.model'; import { ChangeSetsConfig } from './change-sets-config.model'; -const DEFAULT_CHANGE_SETS_CONFIG: ChangeSetsConfig = { - dateFormat: 'dd.MM.yyyy HH:mm', - valueDateFormat: 'dd.MM.yyyy HH:mm', - pageSize: 10, - canResetAndRollback: true, - canOpenCreatedBy: true, - showEmptyCreatedBy: false, - labels: { - types: { - [ChangeSetType.CREATE]: 'Created', - [ChangeSetType.REPLACE]: 'Replaced', - [ChangeSetType.RESET]: 'Reset', - [ChangeSetType.UPDATE]: 'Updated', - [ChangeSetType.DELETE]: 'Deleted', - [ChangeSetType.RESTORE]: 'Restored' +/** + * The values of the change sets when nothing changes them. Their texts are $localize, which an app translates like its + * own, and resolved once the config is injected, so translations an app loads at runtime apply as well. + * @returns The default config. + */ +function getDefaultChangeSetsConfig(): ChangeSetsConfig { + return { + dateFormat: 'dd.MM.yyyy HH:mm', + valueDateFormat: 'dd.MM.yyyy HH:mm', + pageSize: 10, + canResetAndRollback: true, + canOpenCreatedBy: true, + showEmptyCreatedBy: false, + labels: { + types: { + [ChangeSetType.CREATE]: $localize`:@@ngx-change-sets.change-sets.types.created:Created`, + [ChangeSetType.REPLACE]: $localize`:@@ngx-change-sets.change-sets.types.replaced:Replaced`, + [ChangeSetType.RESET]: $localize`:@@ngx-change-sets.change-sets.types.reset:Reset`, + [ChangeSetType.UPDATE]: $localize`:@@ngx-change-sets.change-sets.types.updated:Updated`, + [ChangeSetType.DELETE]: $localize`:@@ngx-change-sets.change-sets.types.deleted:Deleted`, + [ChangeSetType.RESTORE]: $localize`:@@ngx-change-sets.change-sets.types.restored:Restored` + }, + reset: $localize`:@@ngx-change-sets.change-sets.reset:Reset`, + resetChangeSet: $localize`:@@ngx-change-sets.change-sets.resetChangeSet:This change set`, + rollbackToChangeSet: $localize`:@@ngx-change-sets.change-sets.rollbackToChangeSet:Rollback all to this state`, + key: $localize`:@@ngx-change-sets.change-sets.key:Property`, + previousValue: $localize`:@@ngx-change-sets.change-sets.previousValue:Previous value`, + newValue: $localize`:@@ngx-change-sets.change-sets.newValue:New value`, + showMore: $localize`:@@ngx-change-sets.change-sets.showMore:Show more`, + createdAt: $localize`:@@ngx-change-sets.change-sets.createdAt:Created at`, + createdBy: $localize`:@@ngx-change-sets.change-sets.createdBy:Created by` }, - reset: 'Reset', - resetChangeSet: 'This change set', - rollbackToChangeSet: 'Rollback all to this state', - key: 'Property', - previousValue: 'Previous value', - newValue: 'New value', - showMore: 'Show more', - createdAt: 'Created at', - createdBy: 'Created by' - }, - resetConfirmDialogData: { - title: 'Reset this change set?', - paragraphs: ['This deletes the change set and can\'t be undone. The change sets after it are kept.'], - confirmButtonLabel: 'Reset', - cancelButtonLabel: 'Cancel', - confirmButtonColor: 'error' - }, - rollbackConfirmDialogData: { - title: 'Rollback to the state after this change set?', - paragraphs: ['This undoes and deletes every newer change set and can\'t be undone.'], - confirmButtonLabel: 'Rollback', - cancelButtonLabel: 'Cancel', - confirmButtonColor: 'error' - } -}; + resetConfirmDialogData: { + title: $localize`:@@ngx-change-sets.change-sets.resetConfirmDialogData.title:Reset this change set?`, + paragraphs: [$localize`:@@ngx-change-sets.change-sets.resetConfirmDialogData.paragraphs:This deletes the change set and can't be undone. The change sets after it are kept.`], + confirmButtonLabel: $localize`:@@ngx-change-sets.change-sets.resetConfirmDialogData.confirmButtonLabel:Reset`, + cancelButtonLabel: $localize`:@@ngx-change-sets.change-sets.resetConfirmDialogData.cancelButtonLabel:Cancel`, + confirmButtonColor: 'error' + }, + rollbackConfirmDialogData: { + title: $localize`:@@ngx-change-sets.change-sets.rollbackConfirmDialogData.title:Rollback to the state after this change set?`, + paragraphs: [$localize`:@@ngx-change-sets.change-sets.rollbackConfirmDialogData.paragraphs:This undoes and deletes every newer change set and can't be undone.`], + confirmButtonLabel: $localize`:@@ngx-change-sets.change-sets.rollbackConfirmDialogData.confirmButtonLabel:Rollback`, + cancelButtonLabel: $localize`:@@ngx-change-sets.change-sets.rollbackConfirmDialogData.cancelButtonLabel:Cancel`, + confirmButtonColor: 'error' + } + }; +} /** * The values every change sets component below this injector uses when its inputs are not set. @@ -52,7 +59,7 @@ const DEFAULT_CHANGE_SETS_CONFIG: ChangeSetsConfig = { */ export const CHANGE_SETS_CONFIG: InjectionToken = new InjectionToken('CHANGE_SETS_CONFIG', { providedIn: 'root', - factory: () => DEFAULT_CHANGE_SETS_CONFIG + factory: () => getDefaultChangeSetsConfig() }); /** @@ -66,7 +73,7 @@ export function provideChangeSetsConfig(config: ChangeSetsConfigChanges): Provid return { provide: CHANGE_SETS_CONFIG, useFactory: (): ChangeSetsConfig => { - const parent: ChangeSetsConfig = inject(CHANGE_SETS_CONFIG, { skipSelf: true, optional: true }) ?? DEFAULT_CHANGE_SETS_CONFIG; + const parent: ChangeSetsConfig = inject(CHANGE_SETS_CONFIG, { skipSelf: true, optional: true }) ?? getDefaultChangeSetsConfig(); return { ...parent, ...config, diff --git a/projects/ngx-change-sets/package.json b/projects/ngx-change-sets/package.json index 1147ca6..81032ad 100644 --- a/projects/ngx-change-sets/package.json +++ b/projects/ngx-change-sets/package.json @@ -1,6 +1,6 @@ { "name": "@service-soft/ngx-change-sets", - "version": "22.3.0", + "version": "22.3.1", "license": "MIT", "repository": { "type": "git", @@ -21,8 +21,9 @@ "peerDependencies": { "@angular/common": "^22.2.0", "@angular/core": "^22.2.0", + "@angular/localize": "^22.2.0", "@fortawesome/free-solid-svg-icons": "^7.3.1", - "@service-soft/ui": "^22.3.0", + "@service-soft/ui": "^22.3.1", "tailwindcss": "^4.3.3", "zibri-contract": "^3.1.0" }, diff --git a/projects/ngx-change-sets/tsconfig.lib.json b/projects/ngx-change-sets/tsconfig.lib.json index 5ed1187..5315f63 100644 --- a/projects/ngx-change-sets/tsconfig.lib.json +++ b/projects/ngx-change-sets/tsconfig.lib.json @@ -8,7 +8,7 @@ // the paths of the workspace point to the sources of the other libraries, which the build would then compile // into this one. Without them, they resolve from node_modules like for a consumer, so ui has to be built first. "paths": {}, - "types": [] + "types": ["@angular/localize"] }, "exclude": ["**/*.spec.ts", "**/*.stories.ts"], "extends": "../../tsconfig.json", diff --git a/projects/ngx-change-sets/tsconfig.spec.json b/projects/ngx-change-sets/tsconfig.spec.json index cf926c8..d1df25e 100644 --- a/projects/ngx-change-sets/tsconfig.spec.json +++ b/projects/ngx-change-sets/tsconfig.spec.json @@ -3,7 +3,7 @@ { "compilerOptions": { "outDir": "../../out-tsc/spec", - "types": ["vitest/globals"] + "types": ["vitest/globals", "@angular/localize"] }, "extends": "../../tsconfig.json", "include": ["**/*.d.ts", "**/*.spec.ts"] diff --git a/projects/ngx-ecommerce/README.md b/projects/ngx-ecommerce/README.md index f59a938..13167bc 100644 --- a/projects/ngx-ecommerce/README.md +++ b/projects/ngx-ecommerce/README.md @@ -11,13 +11,15 @@ It is built on [@service-soft/ui](https://www.npmjs.com/package/@service-soft/ui - [Input extras](#input-extras) - [Order summary](#order-summary) - [How it calculates](#how-it-calculates) +- [Translating](#translating) - [License](#license) # Requirements -Angular 22 and Tailwind CSS 4. +Angular 22 with `@angular/localize`, which [translates the texts](#translating), and Tailwind CSS 4. ```sh npm install @service-soft/ngx-ecommerce @service-soft/ui +ng add @angular/localize ``` ```css @@ -134,5 +136,8 @@ Change the defaults and the texts with `provideOrderSummaryConfig`, like `provid A backend that calculates differently, like the tax per line, can end up a cent apart from the summary, so calculate it the same way there. +# Translating +The default texts are `$localize` with an id of their own, like `@@ngx-ecommerce.order-summary.total`, so `ng extract-i18n` puts them into the messages of your app, and you translate them like its own texts. The library needs `@angular/localize` for that, `ng add @angular/localize`, also in an app of one language. A build with `localize` fills the texts in, so no part of `@angular/localize` reaches the browser. The defaults are made once a config is injected, so translations an app loads at runtime with `loadTranslations` apply as well. A text of `provideInputExtrasConfig` or `provideOrderSummaryConfig` replaces the default in every language. So translate a default in your messages, and change it in the config only to say something else: a default the config replaces stays in your messages, though nothing shows it. + # License MIT. \ No newline at end of file diff --git a/projects/ngx-ecommerce/input-extras/input-extras-config.provider.ts b/projects/ngx-ecommerce/input-extras/input-extras-config.provider.ts index 9c3a319..49be99d 100644 --- a/projects/ngx-ecommerce/input-extras/input-extras-config.provider.ts +++ b/projects/ngx-ecommerce/input-extras/input-extras-config.provider.ts @@ -3,20 +3,27 @@ import { inject, InjectionToken, Provider } from '@angular/core'; import { InputExtrasConfigChanges } from './input-extras-config-changes.model'; import { InputExtrasConfig } from './input-extras-config.model'; -const DEFAULT_INPUT_EXTRAS_CONFIG: InputExtrasConfig = { - appearance: 'checkbox', - showTotal: false, - labels: { - units: { - once: 'once', - perItem: 'each', - perDay: 'per day' - }, - decrease: 'Remove one', - increase: 'Add one', - total: 'Extras' - } -}; +/** + * The values of an extras input when nothing changes them. Its texts are $localize, which an app translates like its + * own, and resolved once the config is injected, so translations an app loads at runtime apply as well. + * @returns The default config. + */ +function getDefaultInputExtrasConfig(): InputExtrasConfig { + return { + appearance: 'checkbox', + showTotal: false, + labels: { + units: { + once: $localize`:@@ngx-ecommerce.input-extras.units.once:once`, + perItem: $localize`:@@ngx-ecommerce.input-extras.units.perItem:each`, + perDay: $localize`:@@ngx-ecommerce.input-extras.units.perDay:per day` + }, + decrease: $localize`:@@ngx-ecommerce.input-extras.decrease:Remove one`, + increase: $localize`:@@ngx-ecommerce.input-extras.increase:Add one`, + total: $localize`:@@ngx-ecommerce.input-extras.total:Extras` + } + }; +} /** * The values every extras input below this injector uses when its inputs are not set. @@ -24,7 +31,7 @@ const DEFAULT_INPUT_EXTRAS_CONFIG: InputExtrasConfig = { */ export const INPUT_EXTRAS_CONFIG: InjectionToken = new InjectionToken('INPUT_EXTRAS_CONFIG', { providedIn: 'root', - factory: () => DEFAULT_INPUT_EXTRAS_CONFIG + factory: () => getDefaultInputExtrasConfig() }); /** @@ -39,7 +46,7 @@ export function provideInputExtrasConfig(config: InputExtrasConfigChanges): Prov provide: INPUT_EXTRAS_CONFIG, useFactory: (): InputExtrasConfig => { const parent: InputExtrasConfig = inject(INPUT_EXTRAS_CONFIG, { skipSelf: true, optional: true }) - ?? DEFAULT_INPUT_EXTRAS_CONFIG; + ?? getDefaultInputExtrasConfig(); return { ...parent, ...config, diff --git a/projects/ngx-ecommerce/order-summary/order-summary-config.provider.ts b/projects/ngx-ecommerce/order-summary/order-summary-config.provider.ts index a5e77cb..c75d6a8 100644 --- a/projects/ngx-ecommerce/order-summary/order-summary-config.provider.ts +++ b/projects/ngx-ecommerce/order-summary/order-summary-config.provider.ts @@ -3,23 +3,30 @@ import { inject, InjectionToken, Provider } from '@angular/core'; import { OrderSummaryConfigChanges } from './order-summary-config-changes.model'; import { OrderSummaryConfig } from './order-summary-config.model'; -const DEFAULT_ORDER_SUMMARY_CONFIG: OrderSummaryConfig = { - variant: 'compact', - taxMode: 'gross', - taxRate: undefined, - labels: { - caption: 'Order summary', - item: 'Item', - quantity: 'Quantity', - unitPrice: 'Unit price', - amount: 'Amount', - subtotal: 'Subtotal', - netTotal: 'Net total', - tax: 'VAT', - includedTax: 'Includes VAT', - total: 'Total' - } -}; +/** + * The values of an order summary when nothing changes them. Its texts are $localize, which an app translates like its + * own, and resolved once the config is injected, so translations an app loads at runtime apply as well. + * @returns The default config. + */ +function getDefaultOrderSummaryConfig(): OrderSummaryConfig { + return { + variant: 'compact', + taxMode: 'gross', + taxRate: undefined, + labels: { + caption: $localize`:@@ngx-ecommerce.order-summary.caption:Order summary`, + item: $localize`:@@ngx-ecommerce.order-summary.item:Item`, + quantity: $localize`:@@ngx-ecommerce.order-summary.quantity:Quantity`, + unitPrice: $localize`:@@ngx-ecommerce.order-summary.unitPrice:Unit price`, + amount: $localize`:@@ngx-ecommerce.order-summary.amount:Amount`, + subtotal: $localize`:@@ngx-ecommerce.order-summary.subtotal:Subtotal`, + netTotal: $localize`:@@ngx-ecommerce.order-summary.netTotal:Net total`, + tax: $localize`:@@ngx-ecommerce.order-summary.tax:VAT`, + includedTax: $localize`:@@ngx-ecommerce.order-summary.includedTax:Includes VAT`, + total: $localize`:@@ngx-ecommerce.order-summary.total:Total` + } + }; +} /** * The values every order summary below this injector uses when its inputs are not set. @@ -29,7 +36,7 @@ export const ORDER_SUMMARY_CONFIG: InjectionToken = new Inje 'ORDER_SUMMARY_CONFIG', { providedIn: 'root', - factory: () => DEFAULT_ORDER_SUMMARY_CONFIG + factory: () => getDefaultOrderSummaryConfig() } ); @@ -45,7 +52,7 @@ export function provideOrderSummaryConfig(config: OrderSummaryConfigChanges): Pr provide: ORDER_SUMMARY_CONFIG, useFactory: (): OrderSummaryConfig => { const parent: OrderSummaryConfig = inject(ORDER_SUMMARY_CONFIG, { skipSelf: true, optional: true }) - ?? DEFAULT_ORDER_SUMMARY_CONFIG; + ?? getDefaultOrderSummaryConfig(); return { ...parent, ...config, labels: { ...parent.labels, ...config.labels } }; } }; diff --git a/projects/ngx-ecommerce/package.json b/projects/ngx-ecommerce/package.json index eddc6e0..4663ced 100644 --- a/projects/ngx-ecommerce/package.json +++ b/projects/ngx-ecommerce/package.json @@ -1,6 +1,6 @@ { "name": "@service-soft/ngx-ecommerce", - "version": "22.3.0", + "version": "22.3.1", "license": "MIT", "repository": { "type": "git", @@ -21,8 +21,9 @@ "peerDependencies": { "@angular/common": "^22.2.0", "@angular/core": "^22.2.0", + "@angular/localize": "^22.2.0", "@fortawesome/free-solid-svg-icons": "^7.3.1", - "@service-soft/ui": "^22.3.0", + "@service-soft/ui": "^22.3.1", "tailwindcss": "^4.3.3" }, "sideEffects": false diff --git a/projects/ngx-ecommerce/tsconfig.lib.json b/projects/ngx-ecommerce/tsconfig.lib.json index 5ed1187..5315f63 100644 --- a/projects/ngx-ecommerce/tsconfig.lib.json +++ b/projects/ngx-ecommerce/tsconfig.lib.json @@ -8,7 +8,7 @@ // the paths of the workspace point to the sources of the other libraries, which the build would then compile // into this one. Without them, they resolve from node_modules like for a consumer, so ui has to be built first. "paths": {}, - "types": [] + "types": ["@angular/localize"] }, "exclude": ["**/*.spec.ts", "**/*.stories.ts"], "extends": "../../tsconfig.json", diff --git a/projects/ngx-ecommerce/tsconfig.spec.json b/projects/ngx-ecommerce/tsconfig.spec.json index cf926c8..d1df25e 100644 --- a/projects/ngx-ecommerce/tsconfig.spec.json +++ b/projects/ngx-ecommerce/tsconfig.spec.json @@ -3,7 +3,7 @@ { "compilerOptions": { "outDir": "../../out-tsc/spec", - "types": ["vitest/globals"] + "types": ["vitest/globals", "@angular/localize"] }, "extends": "../../tsconfig.json", "include": ["**/*.d.ts", "**/*.spec.ts"] diff --git a/projects/ngx-entity/README.md b/projects/ngx-entity/README.md index 0c0bc30..6cc592a 100644 --- a/projects/ngx-entity/README.md +++ b/projects/ngx-entity/README.md @@ -27,14 +27,16 @@ A table shows the entities a page at a time from the server, with the columns, o - [Leaving unsaved changes](#leaving-unsaved-changes) - [Fields of your own](#fields-of-your-own) - [Configuration](#configuration) + - [Translating](#translating) - [Moving from ngx-material-entity](#moving-from-ngx-material-entity) - [License](#license) # Requirements -Angular 22 and Tailwind CSS 4. The models shared with zibri, like `PaginationResult`, `FilterConfig` and `ValidationProblem`, come from [zibri-contract](https://www.npmjs.com/package/zibri-contract). +Angular 22 with `@angular/localize`, which [translates the texts](#translating), and Tailwind CSS 4. The models shared with zibri, like `PaginationResult`, `FilterConfig` and `ValidationProblem`, come from [zibri-contract](https://www.npmjs.com/package/zibri-contract). ```sh npm install @service-soft/ngx-entity @service-soft/ui @service-soft/ngx-error-handling zibri-contract +ng add @angular/localize ``` The decorators need `"experimentalDecorators": true` in your `tsconfig.json`, like zibri. To [work offline](#working-offline), install `@service-soft/ngx-pwa` as well. @@ -340,6 +342,9 @@ color!: string; The texts of the fields themselves, like the error messages, come from `provideInputConfig` of `@service-soft/ui/input`, and those of the tables from `provideTableConfig` of `@service-soft/ui/table`. +## Translating +The default texts are `$localize` with an id of their own, like `@@ngx-entity.table.deleteLabel`, so `ng extract-i18n` puts them into the messages of your app, and you translate them like its own texts. The library needs `@angular/localize` for that, `ng add @angular/localize`, also in an app of one language. A build with `localize` fills the texts in, so no part of `@angular/localize` reaches the browser. The defaults are made once a config is injected, so translations an app loads at runtime with `loadTranslations` apply as well. A text of `provideXConfig` replaces the default in every language. So translate a default in your messages, and change it in the config only to say something else: a default the config replaces stays in your messages, though nothing shows it. + # Moving from ngx-material-entity It is not finished: many-to-many relations and files (which wait for the next major version of zibri) are still to come. What changed so far: - Import and export are `canImport` and `canExport` of the table instead of `allowJsonImport` and the multi select actions. The import posts to the same `/import` route with the same `import` field. diff --git a/projects/ngx-entity/dialog/entity-dialog-config.provider.ts b/projects/ngx-entity/dialog/entity-dialog-config.provider.ts index 82036fc..1c0e2ec 100644 --- a/projects/ngx-entity/dialog/entity-dialog-config.provider.ts +++ b/projects/ngx-entity/dialog/entity-dialog-config.provider.ts @@ -2,12 +2,20 @@ import { inject, InjectionToken, Provider } from '@angular/core'; import { EntityDialogConfig } from './entity-dialog-config.model'; -const DEFAULT_ENTITY_DIALOG_CONFIG: EntityDialogConfig = { - deleteTitle: 'Delete this?', - deleteParagraphs: ['This can\'t be undone.'], - deleteLabel: 'Delete', - keepLabel: 'Cancel' -}; +/** + * The texts of the question before deleting an entity when nothing changes them. They are $localize, which an app + * translates like its own texts, and resolved once the config is injected, so translations an app loads at runtime + * apply as well. + * @returns The default config. + */ +function getDefaultEntityDialogConfig(): EntityDialogConfig { + return { + deleteTitle: $localize`:@@ngx-entity.dialog.deleteTitle:Delete this?`, + deleteParagraphs: [$localize`:@@ngx-entity.dialog.deleteParagraphs:This can't be undone.`], + deleteLabel: $localize`:@@ngx-entity.dialog.deleteLabel:Delete`, + keepLabel: $localize`:@@ngx-entity.dialog.keepLabel:Cancel` + }; +} /** * The texts of the question before deleting an entity, below this injector. Change them with @@ -15,7 +23,7 @@ const DEFAULT_ENTITY_DIALOG_CONFIG: EntityDialogConfig = { */ export const ENTITY_DIALOG_CONFIG: InjectionToken = new InjectionToken('ENTITY_DIALOG_CONFIG', { providedIn: 'root', - factory: () => DEFAULT_ENTITY_DIALOG_CONFIG + factory: () => getDefaultEntityDialogConfig() }); /** @@ -29,7 +37,7 @@ export function provideEntityDialogConfig(config: Partial): return { provide: ENTITY_DIALOG_CONFIG, useFactory: (): EntityDialogConfig => ({ - ...inject(ENTITY_DIALOG_CONFIG, { skipSelf: true, optional: true }) ?? DEFAULT_ENTITY_DIALOG_CONFIG, + ...inject(ENTITY_DIALOG_CONFIG, { skipSelf: true, optional: true }) ?? getDefaultEntityDialogConfig(), ...config }) }; diff --git a/projects/ngx-entity/field-base/entity-array-field-config.provider.ts b/projects/ngx-entity/field-base/entity-array-field-config.provider.ts index c9cf9ca..a4d69e8 100644 --- a/projects/ngx-entity/field-base/entity-array-field-config.provider.ts +++ b/projects/ngx-entity/field-base/entity-array-field-config.provider.ts @@ -2,20 +2,27 @@ import { inject, InjectionToken, Provider } from '@angular/core'; import { EntityArrayFieldConfig } from './entity-array-field-config.model'; -const DEFAULT_ENTITY_ARRAY_FIELD_CONFIG: EntityArrayFieldConfig = { - addLabel: 'Add', - editLabel: 'Edit', - removeLabel: 'Remove', - dateLabel: 'Date', - startLabel: 'Start', - endLabel: 'End', - addTitle: displayName => `Add to ${displayName}`, - editTitle: displayName => `Edit in ${displayName}`, - saveLabel: 'Save', - cancelLabel: 'Cancel', - yesLabel: 'Yes', - noLabel: 'No' -}; +/** + * The texts of the tables of arrays when nothing changes them. They are $localize, which an app translates like its + * own texts, and resolved once the config is injected, so translations an app loads at runtime apply as well. + * @returns The default config. + */ +function getDefaultEntityArrayFieldConfig(): EntityArrayFieldConfig { + return { + addLabel: $localize`:@@ngx-entity.field-base.addLabel:Add`, + editLabel: $localize`:@@ngx-entity.field-base.editLabel:Edit`, + removeLabel: $localize`:@@ngx-entity.field-base.removeLabel:Remove`, + dateLabel: $localize`:@@ngx-entity.field-base.dateLabel:Date`, + startLabel: $localize`:@@ngx-entity.field-base.startLabel:Start`, + endLabel: $localize`:@@ngx-entity.field-base.endLabel:End`, + addTitle: displayName => $localize`:@@ngx-entity.field-base.addTitle:Add to ${displayName}:displayName:`, + editTitle: displayName => $localize`:@@ngx-entity.field-base.editTitle:Edit in ${displayName}:displayName:`, + saveLabel: $localize`:@@ngx-entity.field-base.saveLabel:Save`, + cancelLabel: $localize`:@@ngx-entity.field-base.cancelLabel:Cancel`, + yesLabel: $localize`:@@ngx-entity.field-base.yesLabel:Yes`, + noLabel: $localize`:@@ngx-entity.field-base.noLabel:No` + }; +} /** * The texts of every table of an array in entity forms below this injector. Change them with @@ -23,7 +30,7 @@ const DEFAULT_ENTITY_ARRAY_FIELD_CONFIG: EntityArrayFieldConfig = { */ export const ENTITY_ARRAY_FIELD_CONFIG: InjectionToken = new InjectionToken( 'ENTITY_ARRAY_FIELD_CONFIG', - { providedIn: 'root', factory: () => DEFAULT_ENTITY_ARRAY_FIELD_CONFIG } + { providedIn: 'root', factory: () => getDefaultEntityArrayFieldConfig() } ); /** @@ -37,7 +44,7 @@ export function provideEntityArrayFieldConfig(config: Partial ({ - ...inject(ENTITY_ARRAY_FIELD_CONFIG, { skipSelf: true, optional: true }) ?? DEFAULT_ENTITY_ARRAY_FIELD_CONFIG, + ...inject(ENTITY_ARRAY_FIELD_CONFIG, { skipSelf: true, optional: true }) ?? getDefaultEntityArrayFieldConfig(), ...config }) }; diff --git a/projects/ngx-entity/field-date-array/entity-date-array-field.component.ts b/projects/ngx-entity/field-date-array/entity-date-array-field.component.ts index 1ec2bd8..aa5d3dc 100644 --- a/projects/ngx-entity/field-date-array/entity-date-array-field.component.ts +++ b/projects/ngx-entity/field-date-array/entity-date-array-field.component.ts @@ -142,7 +142,8 @@ export class EntityDateArrayFieldComponent extends BaseEntityF * @returns The name. */ protected resolveRemoveLabel(item: EntityDateArrayItem): string { - return `${this.labels.removeLabel} ${EntityTextUtilities.resolveItemText(this.items(), item, this.labels, this.locale)}`; + const value: string = EntityTextUtilities.resolveItemText(this.items(), item, this.labels, this.locale); + return $localize`:@@ngx-entity.field-date-array.removeItemLabel:${this.labels.removeLabel}:removeLabel: ${value}:value:`; } private resolveDateText(date: Date | undefined): string { diff --git a/projects/ngx-entity/field-date-range/entity-date-range-field-config.provider.ts b/projects/ngx-entity/field-date-range/entity-date-range-field-config.provider.ts index 855e709..8790a79 100644 --- a/projects/ngx-entity/field-date-range/entity-date-range-field-config.provider.ts +++ b/projects/ngx-entity/field-date-range/entity-date-range-field-config.provider.ts @@ -2,17 +2,24 @@ import { inject, InjectionToken, Provider } from '@angular/core'; import { EntityDateRangeFieldConfig } from './entity-date-range-field-config.model'; -const DEFAULT_ENTITY_DATE_RANGE_FIELD_CONFIG: EntityDateRangeFieldConfig = { - startLabel: 'Start', - endLabel: 'End' -}; +/** + * The texts of the fields of date ranges when nothing changes them. They are $localize, which an app translates like + * its own texts, and resolved once the config is injected, so translations an app loads at runtime apply as well. + * @returns The default config. + */ +function getDefaultEntityDateRangeFieldConfig(): EntityDateRangeFieldConfig { + return { + startLabel: $localize`:@@ngx-entity.field-date-range.startLabel:Start`, + endLabel: $localize`:@@ngx-entity.field-date-range.endLabel:End` + }; +} /** * The texts of every field of a date range below this injector. Change them with provideEntityDateRangeFieldConfig. */ export const ENTITY_DATE_RANGE_FIELD_CONFIG: InjectionToken = new InjectionToken( 'ENTITY_DATE_RANGE_FIELD_CONFIG', - { providedIn: 'root', factory: () => DEFAULT_ENTITY_DATE_RANGE_FIELD_CONFIG } + { providedIn: 'root', factory: () => getDefaultEntityDateRangeFieldConfig() } ); /** @@ -26,7 +33,7 @@ export function provideEntityDateRangeFieldConfig(config: Partial ({ - ...inject(ENTITY_DATE_RANGE_FIELD_CONFIG, { skipSelf: true, optional: true }) ?? DEFAULT_ENTITY_DATE_RANGE_FIELD_CONFIG, + ...inject(ENTITY_DATE_RANGE_FIELD_CONFIG, { skipSelf: true, optional: true }) ?? getDefaultEntityDateRangeFieldConfig(), ...config }) }; diff --git a/projects/ngx-entity/field-object-array/entity-object-array-field.component.ts b/projects/ngx-entity/field-object-array/entity-object-array-field.component.ts index 66707d7..934f44c 100644 --- a/projects/ngx-entity/field-object-array/entity-object-array-field.component.ts +++ b/projects/ngx-entity/field-object-array/entity-object-array-field.component.ts @@ -142,7 +142,9 @@ export class EntityObjectArrayFieldComponent extends BaseEntit */ protected resolveActionLabel(action: string, item: object): string { const first: LocalTableColumn | undefined = this.columns()[0]; - return first == undefined ? action : `${action} ${first.value(item)}`; + return first == undefined + ? action + : $localize`:@@ngx-entity.field-object-array.actionLabel:${action}:action: ${first.value(item)}:value:`; } private async openDialog( diff --git a/projects/ngx-entity/field-password/entity-password-field-config.provider.ts b/projects/ngx-entity/field-password/entity-password-field-config.provider.ts index 346f5fe..f3c981f 100644 --- a/projects/ngx-entity/field-password/entity-password-field-config.provider.ts +++ b/projects/ngx-entity/field-password/entity-password-field-config.provider.ts @@ -2,17 +2,24 @@ import { inject, InjectionToken, Provider } from '@angular/core'; import { EntityPasswordFieldConfig } from './entity-password-field-config.model'; -const DEFAULT_ENTITY_PASSWORD_FIELD_CONFIG: EntityPasswordFieldConfig = { - confirmationLabel: displayName => `Repeat ${displayName}`, - mismatchMessage: 'The passwords differ.' -}; +/** + * The texts of the fields of passwords when nothing changes them. They are $localize, which an app translates like its + * own texts, and resolved once the config is injected, so translations an app loads at runtime apply as well. + * @returns The default config. + */ +function getDefaultEntityPasswordFieldConfig(): EntityPasswordFieldConfig { + return { + confirmationLabel: displayName => $localize`:@@ngx-entity.field-password.confirmationLabel:Repeat ${displayName}:displayName:`, + mismatchMessage: $localize`:@@ngx-entity.field-password.mismatchMessage:The passwords differ.` + }; +} /** * The texts of every field of a password below this injector. Change them with provideEntityPasswordFieldConfig. */ export const ENTITY_PASSWORD_FIELD_CONFIG: InjectionToken = new InjectionToken( 'ENTITY_PASSWORD_FIELD_CONFIG', - { providedIn: 'root', factory: () => DEFAULT_ENTITY_PASSWORD_FIELD_CONFIG } + { providedIn: 'root', factory: () => getDefaultEntityPasswordFieldConfig() } ); /** @@ -26,7 +33,7 @@ export function provideEntityPasswordFieldConfig(config: Partial ({ - ...inject(ENTITY_PASSWORD_FIELD_CONFIG, { skipSelf: true, optional: true }) ?? DEFAULT_ENTITY_PASSWORD_FIELD_CONFIG, + ...inject(ENTITY_PASSWORD_FIELD_CONFIG, { skipSelf: true, optional: true }) ?? getDefaultEntityPasswordFieldConfig(), ...config }) }; diff --git a/projects/ngx-entity/form/entity-form-config.provider.ts b/projects/ngx-entity/form/entity-form-config.provider.ts index 58aa624..af65252 100644 --- a/projects/ngx-entity/form/entity-form-config.provider.ts +++ b/projects/ngx-entity/form/entity-form-config.provider.ts @@ -2,15 +2,24 @@ import { inject, InjectionToken, Provider } from '@angular/core'; import { EntityFormConfig } from './entity-form-config.model'; -const DEFAULT_ENTITY_FORM_CONFIG: EntityFormConfig = { - // the first tab is where every field without a tab goes, so it is the one that is left unnamed without anyone - // choosing to: it holds what the entity is about. Another tab was given its number on purpose, and should be named. - tabLabel: tab => tab === 1 ? 'General' : `Tab ${tab}`, - createTitle: 'Create', - editTitle: 'Edit', - saveLabel: 'Save', - cancelLabel: 'Cancel' -}; +/** + * The texts of entity forms when nothing changes them. They are $localize, which an app translates like its own texts, + * and resolved once the config is injected, so translations an app loads at runtime apply as well. + * @returns The default config. + */ +function getDefaultEntityFormConfig(): EntityFormConfig { + return { + // the first tab is where every field without a tab goes, so it is the one that is left unnamed without anyone + // choosing to: it holds what the entity is about. Another tab was given its number on purpose, and should be named. + tabLabel: tab => tab === 1 + ? $localize`:@@ngx-entity.form.tabLabel.first:General` + : $localize`:@@ngx-entity.form.tabLabel.other:Tab ${tab}:tab:`, + createTitle: $localize`:@@ngx-entity.form.createTitle:Create`, + editTitle: $localize`:@@ngx-entity.form.editTitle:Edit`, + saveLabel: $localize`:@@ngx-entity.form.saveLabel:Save`, + cancelLabel: $localize`:@@ngx-entity.form.cancelLabel:Cancel` + }; +} /** * The texts of every entity form below this injector, and of the dialogs and pages they are in. Change them with @@ -18,7 +27,7 @@ const DEFAULT_ENTITY_FORM_CONFIG: EntityFormConfig = { */ export const ENTITY_FORM_CONFIG: InjectionToken = new InjectionToken('ENTITY_FORM_CONFIG', { providedIn: 'root', - factory: () => DEFAULT_ENTITY_FORM_CONFIG + factory: () => getDefaultEntityFormConfig() }); /** @@ -32,7 +41,7 @@ export function provideEntityFormConfig(config: Partial): Prov return { provide: ENTITY_FORM_CONFIG, useFactory: (): EntityFormConfig => ({ - ...inject(ENTITY_FORM_CONFIG, { skipSelf: true, optional: true }) ?? DEFAULT_ENTITY_FORM_CONFIG, + ...inject(ENTITY_FORM_CONFIG, { skipSelf: true, optional: true }) ?? getDefaultEntityFormConfig(), ...config }) }; diff --git a/projects/ngx-entity/package.json b/projects/ngx-entity/package.json index 0d372c1..3e07d24 100644 --- a/projects/ngx-entity/package.json +++ b/projects/ngx-entity/package.json @@ -1,6 +1,6 @@ { "name": "@service-soft/ngx-entity", - "version": "22.3.0", + "version": "22.3.1", "license": "MIT", "repository": { "type": "git", @@ -21,10 +21,11 @@ "peerDependencies": { "@angular/common": "^22.2.0", "@angular/core": "^22.2.0", + "@angular/localize": "^22.2.0", "@angular/router": "^22.2.0", - "@service-soft/ngx-error-handling": "^22.3.0", - "@service-soft/ngx-pwa": "^22.3.0", - "@service-soft/ui": "^22.3.0", + "@service-soft/ngx-error-handling": "^22.3.1", + "@service-soft/ngx-pwa": "^22.3.1", + "@service-soft/ui": "^22.3.1", "tailwindcss": "^4.3.3", "zibri-contract": "^3.1.0" }, diff --git a/projects/ngx-entity/table/entity-table-config.provider.ts b/projects/ngx-entity/table/entity-table-config.provider.ts index db52f22..138ebdd 100644 --- a/projects/ngx-entity/table/entity-table-config.provider.ts +++ b/projects/ngx-entity/table/entity-table-config.provider.ts @@ -2,17 +2,29 @@ import { inject, InjectionToken, Provider } from '@angular/core'; import { EntityTableConfig } from './entity-table-config.model'; -const DEFAULT_ENTITY_TABLE_CONFIG: EntityTableConfig = { - yesLabel: 'Yes', - noLabel: 'No', - createLabel: 'Create', - deleteLabel: 'Delete', - createFirstLabel: 'These can be added once this is saved.', - importLabel: 'Import', - exportLabels: { json: 'Export as JSON', csv: 'Export as CSV', xml: 'Export as XML' }, - exportFileName: 'export', - csvSeparator: ',' -}; +/** + * The texts of entity tables when nothing changes them. They are $localize, which an app translates like its own + * texts, and resolved once the config is injected, so translations an app loads at runtime apply as well. + * @returns The default config. + */ +function getDefaultEntityTableConfig(): EntityTableConfig { + return { + yesLabel: $localize`:@@ngx-entity.table.yesLabel:Yes`, + noLabel: $localize`:@@ngx-entity.table.noLabel:No`, + createLabel: $localize`:@@ngx-entity.table.createLabel:Create`, + deleteLabel: $localize`:@@ngx-entity.table.deleteLabel:Delete`, + createFirstLabel: $localize`:@@ngx-entity.table.createFirstLabel:These can be added once this is saved.`, + importLabel: $localize`:@@ngx-entity.table.importLabel:Import`, + exportLabels: { + json: $localize`:@@ngx-entity.table.exportLabels.json:Export as JSON`, + csv: $localize`:@@ngx-entity.table.exportLabels.csv:Export as CSV`, + xml: $localize`:@@ngx-entity.table.exportLabels.xml:Export as XML` + }, + // the name of the file the user downloads, which they see. + exportFileName: $localize`:@@ngx-entity.table.exportFileName:export`, + csvSeparator: ',' + }; +} /** * The texts of every entity table below this injector. Change them with provideEntityTableConfig. The texts of the @@ -20,7 +32,7 @@ const DEFAULT_ENTITY_TABLE_CONFIG: EntityTableConfig = { */ export const ENTITY_TABLE_CONFIG: InjectionToken = new InjectionToken('ENTITY_TABLE_CONFIG', { providedIn: 'root', - factory: () => DEFAULT_ENTITY_TABLE_CONFIG + factory: () => getDefaultEntityTableConfig() }); /** @@ -34,7 +46,7 @@ export function provideEntityTableConfig(config: Partial): Pr return { provide: ENTITY_TABLE_CONFIG, useFactory: (): EntityTableConfig => ({ - ...inject(ENTITY_TABLE_CONFIG, { skipSelf: true, optional: true }) ?? DEFAULT_ENTITY_TABLE_CONFIG, + ...inject(ENTITY_TABLE_CONFIG, { skipSelf: true, optional: true }) ?? getDefaultEntityTableConfig(), ...config }) }; diff --git a/projects/ngx-entity/table/entity-table.component.ts b/projects/ngx-entity/table/entity-table.component.ts index a84348d..d8ac8fa 100644 --- a/projects/ngx-entity/table/entity-table.component.ts +++ b/projects/ngx-entity/table/entity-table.component.ts @@ -262,7 +262,9 @@ export class EntityTableComponent< */ protected resolveDeleteLabel(row: T): string { const first: TableColumn | undefined = this.tableColumns()[0]; - return first == undefined ? this.labels.deleteLabel : `${this.labels.deleteLabel} ${first.value(row)}`; + return first == undefined + ? this.labels.deleteLabel + : $localize`:@@ngx-entity.table.deleteRowLabel:${this.labels.deleteLabel}:deleteLabel: ${first.value(row)}:value:`; } /** @@ -304,12 +306,12 @@ export class EntityTableComponent< /** * Imports the entities of the json file the user chose, and loads the page again. A refused file goes to the * ErrorHandler. - * @param input - The file input. + * @param inputElement - The file input. */ - protected async import(input: HTMLInputElement): Promise { - const file: File | undefined = input.files?.[0]; + protected async import(inputElement: HTMLInputElement): Promise { + const file: File | undefined = inputElement.files?.[0]; // empty, so the same file can be chosen again - input.value = ''; + inputElement.value = ''; if (file == undefined) { return; } diff --git a/projects/ngx-entity/tsconfig.lib.json b/projects/ngx-entity/tsconfig.lib.json index 477529a..6408ce9 100644 --- a/projects/ngx-entity/tsconfig.lib.json +++ b/projects/ngx-entity/tsconfig.lib.json @@ -8,7 +8,7 @@ // the paths of the workspace point to the sources of the other libraries, which the build would then compile // into this one. Without them, they resolve from node_modules like for a consumer, so ui has to be built first. "paths": {}, - "types": [] + "types": ["@angular/localize"] }, "exclude": ["**/*.spec.ts", "**/*.stories.ts", "test-setup.ts"], "extends": "../../tsconfig.json", diff --git a/projects/ngx-entity/tsconfig.spec.json b/projects/ngx-entity/tsconfig.spec.json index 88ee701..6be3646 100644 --- a/projects/ngx-entity/tsconfig.spec.json +++ b/projects/ngx-entity/tsconfig.spec.json @@ -3,7 +3,7 @@ { "compilerOptions": { "outDir": "../../out-tsc/spec", - "types": ["vitest/globals"] + "types": ["vitest/globals", "@angular/localize"] }, "extends": "../../tsconfig.json", "include": ["**/*.d.ts", "**/*.spec.ts", "test-setup.ts"] diff --git a/projects/ngx-entity/unsaved-changes/unsaved-changes-config.provider.ts b/projects/ngx-entity/unsaved-changes/unsaved-changes-config.provider.ts index d8f519a..ee4c895 100644 --- a/projects/ngx-entity/unsaved-changes/unsaved-changes-config.provider.ts +++ b/projects/ngx-entity/unsaved-changes/unsaved-changes-config.provider.ts @@ -2,12 +2,20 @@ import { inject, InjectionToken, Provider } from '@angular/core'; import { UnsavedChangesConfig } from './unsaved-changes-config.model'; -const DEFAULT_UNSAVED_CHANGES_CONFIG: UnsavedChangesConfig = { - title: 'Discard your changes?', - paragraphs: ['What you changed hasn\'t been saved and will be lost.'], - discardLabel: 'Discard', - keepEditingLabel: 'Keep editing' -}; +/** + * The texts of the question before changes are lost when nothing changes them. They are $localize, which an app + * translates like its own texts, and resolved once the config is injected, so translations an app loads at runtime + * apply as well. + * @returns The default config. + */ +function getDefaultUnsavedChangesConfig(): UnsavedChangesConfig { + return { + title: $localize`:@@ngx-entity.unsaved-changes.title:Discard your changes?`, + paragraphs: [$localize`:@@ngx-entity.unsaved-changes.paragraphs:What you changed hasn't been saved and will be lost.`], + discardLabel: $localize`:@@ngx-entity.unsaved-changes.discardLabel:Discard`, + keepEditingLabel: $localize`:@@ngx-entity.unsaved-changes.keepEditingLabel:Keep editing` + }; +} /** * The texts of the question before changes are lost, below this injector. Change them with @@ -15,7 +23,7 @@ const DEFAULT_UNSAVED_CHANGES_CONFIG: UnsavedChangesConfig = { */ export const UNSAVED_CHANGES_CONFIG: InjectionToken = new InjectionToken( 'UNSAVED_CHANGES_CONFIG', - { providedIn: 'root', factory: () => DEFAULT_UNSAVED_CHANGES_CONFIG } + { providedIn: 'root', factory: () => getDefaultUnsavedChangesConfig() } ); /** @@ -29,7 +37,7 @@ export function provideUnsavedChangesConfig(config: Partial ({ - ...inject(UNSAVED_CHANGES_CONFIG, { skipSelf: true, optional: true }) ?? DEFAULT_UNSAVED_CHANGES_CONFIG, + ...inject(UNSAVED_CHANGES_CONFIG, { skipSelf: true, optional: true }) ?? getDefaultUnsavedChangesConfig(), ...config }) }; diff --git a/projects/ngx-error-handling/README.md b/projects/ngx-error-handling/README.md index a93392e..af88140 100644 --- a/projects/ngx-error-handling/README.md +++ b/projects/ngx-error-handling/README.md @@ -7,15 +7,17 @@ Handles the errors of Angular apps that nothing caught: hands each of them to se - [Requirements](#requirements) - [Several handlers for one error](#several-handlers-for-one-error) - [The error dialog](#the-error-dialog) + - [Translating](#translating) - [The error body of zibri](#the-error-body-of-zibri) - [Moving from ngx-material-auth](#moving-from-ngx-material-auth) - [License](#license) # Requirements -Angular 22. The dialog is built on [@service-soft/ui](https://www.npmjs.com/package/@service-soft/ui), which `@service-soft/ngx-error-handling/error-handler` doesn't need. The error body, `ErrorResponseBody` with its `ValidationProblem`s, comes from [zibri-contract](https://www.npmjs.com/package/zibri-contract), the package zibri declares it in. +Angular 22. The dialog is built on [@service-soft/ui](https://www.npmjs.com/package/@service-soft/ui) and needs `@angular/localize`, which [translates its texts](#translating); `@service-soft/ngx-error-handling/error-handler` needs neither. The error body, `ErrorResponseBody` with its `ValidationProblem`s, comes from [zibri-contract](https://www.npmjs.com/package/zibri-contract), the package zibri declares it in. ```sh npm install @service-soft/ngx-error-handling @service-soft/ui zibri-contract +ng add @angular/localize ``` # Several handlers for one error @@ -63,6 +65,9 @@ Errors your code catches show none, like the ones the forms of [@service-soft/ng | `ignoredStatuses` | `[401]`: zibri refused the login, and the auth sends the user to the login | | `isIgnored` | — a function that says an error shows no dialog, like one your app tells the user of itself | +## Translating +The default texts are `$localize` with an id of their own, like `@@ngx-error-handling.error-dialog.failedTitle`, so `ng extract-i18n` puts them into the messages of your app, and you translate them like its own texts. The dialog needs `@angular/localize` for that, `ng add @angular/localize`, also in an app of one language. A build with `localize` fills the texts in, so no part of `@angular/localize` reaches the browser. The defaults are made once an error is handled, so translations an app loads at runtime with `loadTranslations` apply as well. A text of `showDialogErrorHandler` replaces the default in every language. So translate a default in your messages, and change it in the config only to say something else: a default the config replaces stays in your messages, though nothing shows it. + # The error body of zibri `@service-soft/ngx-error-handling/error-response` reads what zibri answers a refused or failed request with, without any ui: diff --git a/projects/ngx-error-handling/error-dialog/error-dialog.utilities.ts b/projects/ngx-error-handling/error-dialog/error-dialog.utilities.ts index 0d25b3e..32cb4b5 100644 --- a/projects/ngx-error-handling/error-dialog/error-dialog.utilities.ts +++ b/projects/ngx-error-handling/error-dialog/error-dialog.utilities.ts @@ -12,21 +12,28 @@ const NO_CONNECTION: number = 0; // the first status of the errors of the server, after the refusals of the request. const FIRST_SERVER_ERROR: number = 500; -const DEFAULT_ERROR_DIALOG_CONFIG: ErrorDialogConfig = { - labels: { - refusedTitle: 'That didn\'t work', - failedTitle: 'Something went wrong', - offlineTitle: 'No connection', - failedParagraphs: ['Something went wrong. Please try again later.'], - offlineParagraphs: ['Check your connection and try again.'], - problem: (key, message) => `${key}: ${message}`, - reference: traceId => `Reference: ${traceId}`, - close: 'OK' - }, - // the auth ends a login zibri refuses, and sends the user to the login - ignoredStatuses: [HttpStatusCode.Unauthorized], - isIgnored: () => false -}; +/** + * Which errors the dialog shows, and how, when nothing changes it. Its texts are $localize, which an app translates + * like its own, and resolved once an error is handled, so translations an app loads at runtime apply as well. + * @returns The default config. + */ +function getDefaultErrorDialogConfig(): ErrorDialogConfig { + return { + labels: { + refusedTitle: $localize`:@@ngx-error-handling.error-dialog.refusedTitle:That didn't work`, + failedTitle: $localize`:@@ngx-error-handling.error-dialog.failedTitle:Something went wrong`, + offlineTitle: $localize`:@@ngx-error-handling.error-dialog.offlineTitle:No connection`, + failedParagraphs: [$localize`:@@ngx-error-handling.error-dialog.failedParagraphs:Something went wrong. Please try again later.`], + offlineParagraphs: [$localize`:@@ngx-error-handling.error-dialog.offlineParagraphs:Check your connection and try again.`], + problem: (key, message) => $localize`:@@ngx-error-handling.error-dialog.problem:${key}:key:: ${message}:message:`, + reference: traceId => $localize`:@@ngx-error-handling.error-dialog.reference:Reference: ${traceId}:traceId:`, + close: $localize`:@@ngx-error-handling.error-dialog.close:OK` + }, + // the auth ends a login zibri refuses, and sends the user to the login + ignoredStatuses: [HttpStatusCode.Unauthorized], + isIgnored: () => false + }; +} /** * Utilities for the dialog that shows an error. @@ -38,10 +45,11 @@ export abstract class ErrorDialogUtilities { * @returns The config. */ static resolveConfig(changes: ErrorDialogConfigChanges): ErrorDialogConfig { + const defaults: ErrorDialogConfig = getDefaultErrorDialogConfig(); return { - ...DEFAULT_ERROR_DIALOG_CONFIG, + ...defaults, ...changes, - labels: { ...DEFAULT_ERROR_DIALOG_CONFIG.labels, ...changes.labels } + labels: { ...defaults.labels, ...changes.labels } }; } diff --git a/projects/ngx-error-handling/error-dialog/show-dialog-error-handler.function.ts b/projects/ngx-error-handling/error-dialog/show-dialog-error-handler.function.ts index bb28385..c7d535c 100644 --- a/projects/ngx-error-handling/error-dialog/show-dialog-error-handler.function.ts +++ b/projects/ngx-error-handling/error-dialog/show-dialog-error-handler.function.ts @@ -16,7 +16,6 @@ import { ErrorDialogUtilities } from './error-dialog.utilities'; * @returns The handler, for provideErrorHandler. */ export function showDialogErrorHandler(changes: ErrorDialogConfigChanges = {}): ErrorHandlerFn { - const config: ErrorDialogConfig = ErrorDialogUtilities.resolveConfig(changes); // an error that follows another, like every request of a page without a connection, would stack dialogs. The // handler belongs to the app config it is provided in, so this is one flag per app. let showing: boolean = false; @@ -25,8 +24,9 @@ export function showDialogErrorHandler(changes: ErrorDialogConfigChanges = {}): * Shows the dialog of an error until the user closes it. * @param dialogService - Opens the dialog. * @param error - The error to show. + * @param config - How the dialog shows it. */ - async function showDialog(dialogService: DialogService, error: unknown): Promise { + async function showDialog(dialogService: DialogService, error: unknown, config: ErrorDialogConfig): Promise { // set before the first await, so an error right after this one finds it showing showing = true; try { @@ -43,10 +43,16 @@ export function showDialogErrorHandler(changes: ErrorDialogConfigChanges = {}): } return error => { - if (!isPlatformBrowser(inject(PLATFORM_ID)) || showing || ErrorDialogUtilities.isIgnored(error, config)) { + if (!isPlatformBrowser(inject(PLATFORM_ID)) || showing) { + return; + } + // resolved for each error rather than once above: showDialogErrorHandler runs when the app config is created, + // which can be before the translations an app loads at runtime, and its default texts are $localize. + const config: ErrorDialogConfig = ErrorDialogUtilities.resolveConfig(changes); + if (ErrorDialogUtilities.isIgnored(error, config)) { return; } // injected here, as inject() only works until the first await - void showDialog(inject(DialogService), error); + void showDialog(inject(DialogService), error, config); }; } \ No newline at end of file diff --git a/projects/ngx-error-handling/package.json b/projects/ngx-error-handling/package.json index 4fdfd42..967216b 100644 --- a/projects/ngx-error-handling/package.json +++ b/projects/ngx-error-handling/package.json @@ -1,6 +1,6 @@ { "name": "@service-soft/ngx-error-handling", - "version": "22.3.0", + "version": "22.3.1", "license": "MIT", "repository": { "type": "git", @@ -21,11 +21,15 @@ "peerDependencies": { "@angular/common": "^22.2.0", "@angular/core": "^22.2.0", - "@service-soft/ui": "^22.3.0", + "@angular/localize": "^22.2.0", + "@service-soft/ui": "^22.3.1", "tailwindcss": "^4.3.3", "zibri-contract": "^3.1.0" }, "peerDependenciesMeta": { + "@angular/localize": { + "optional": true + }, "@service-soft/ui": { "optional": true }, diff --git a/projects/ngx-error-handling/tsconfig.lib.json b/projects/ngx-error-handling/tsconfig.lib.json index 5ed1187..5315f63 100644 --- a/projects/ngx-error-handling/tsconfig.lib.json +++ b/projects/ngx-error-handling/tsconfig.lib.json @@ -8,7 +8,7 @@ // the paths of the workspace point to the sources of the other libraries, which the build would then compile // into this one. Without them, they resolve from node_modules like for a consumer, so ui has to be built first. "paths": {}, - "types": [] + "types": ["@angular/localize"] }, "exclude": ["**/*.spec.ts", "**/*.stories.ts"], "extends": "../../tsconfig.json", diff --git a/projects/ngx-error-handling/tsconfig.spec.json b/projects/ngx-error-handling/tsconfig.spec.json index cf926c8..d1df25e 100644 --- a/projects/ngx-error-handling/tsconfig.spec.json +++ b/projects/ngx-error-handling/tsconfig.spec.json @@ -3,7 +3,7 @@ { "compilerOptions": { "outDir": "../../out-tsc/spec", - "types": ["vitest/globals"] + "types": ["vitest/globals", "@angular/localize"] }, "extends": "../../tsconfig.json", "include": ["**/*.d.ts", "**/*.spec.ts"] diff --git a/projects/ngx-navigation/README.md b/projects/ngx-navigation/README.md index 9a28715..792e3da 100644 --- a/projects/ngx-navigation/README.md +++ b/projects/ngx-navigation/README.md @@ -28,10 +28,11 @@ It is built on [@service-soft/ui](https://www.npmjs.com/package/@service-soft/ui - [License](#license) # Requirements -Angular 22 with its router, and Tailwind CSS 4. `@angular/ssr` for the [server part of the SEO](#the-server-sitemap-robotstxt-and-llmstxt). +Angular 22 with its router and `@angular/localize`, which [translates the texts](#translating), and Tailwind CSS 4. `@angular/ssr` for the [server part of the SEO](#the-server-sitemap-robotstxt-and-llmstxt). ```sh npm install @service-soft/ngx-navigation @service-soft/ui +ng add @angular/localize ``` # Setup @@ -313,11 +314,12 @@ Each build knows its language by its `LOCALE_ID`. Then the canonical url of a pa - the routes of the router config, children and lazily loaded children included; - without redirects, the route of unknown urls, matchers, and routes whose `robots` holds `noindex`; - the render mode of each page by the first of the server routes that matches it, `RenderMode.Server` when none does; -- for a route with parameters, the pages Angular prerendered for it, and the ones `sitemap` in its data lists, like the articles of a database. A route with parameters that has neither is returned in `unlistedRoutes`, so the server can log it. - - `sitemap` runs in the app, in an injection context of its root, so it reads them like the pages do. For that, `resolvePages` has the app engine render one page on the server, which hands the app a `REQUEST_CONTEXT` that only the server can give. `provideSeoConfig` runs every `sitemap` before that page renders. The page is an unknown url, so it needs the route of unknown urls to render on the server, which a 404 needs anyway: `{ path: '**', renderMode: RenderMode.Server, status: 404 }`. Without it, the first page without parameters that renders on the server is used, and `resolvePages` throws when there is none; +- without a route whose server route answers with an error, like one with no server route of its own that falls under the 404 of the route of unknown urls. It is returned in `errorRoutes`, so the server can log it; +- for a route with parameters, the pages Angular prerendered for it, and the ones `sitemap` in its data lists, like the articles of a database. `sitemap` runs in the app, in an injection context of its root, so it reads them like the pages do. A route with parameters that has neither is returned in `unlistedRoutes`; - the title and description of each page in each language, read from its html as the app engine answers it, prerendered or rendered once. A page only a browser renders, `RenderMode.Client`, has neither, as search engines see little more of it. +The app hands the server its routes, as the server can't import them: in a site in several languages their texts are `$localize`, which only the build of each language fills in. For that, `resolvePages` has the app engine render one page on the server, which hands the app a `REQUEST_CONTEXT` that only the server can give. `provideSeoConfig` puts the routes into it, after running every `sitemap`, before that page renders. The page is an unknown url, so the route of unknown urls has to render on the server, which a 404 needs anyway: `{ path: '**', renderMode: RenderMode.Server, status: 404 }`. Without it, the first server route without parameters that renders on the server is used, and `resolvePages` throws when there is none. + ```ts { path: 'news/:article', title: 'Article', component: ArticlePage, data: { sitemap: async () => { @@ -335,7 +337,6 @@ const appEngine: AngularNodeAppEngine = new AngularNodeAppEngine(); const locales: SeoLocale[] = [{ code: 'en', subPath: 'en' }, { code: 'de', subPath: 'de' }]; const site: Promise = SeoServerUtilities.resolvePages({ origin: 'https://club.example', - routes, serverRoutes, // written next to the browser and server folders by the build prerenderedRoutes: Object.keys(JSON.parse(readFileSync(join(import.meta.dirname, '../prerendered-routes.json'), 'utf8')).routes), @@ -373,6 +374,9 @@ Every part reads its defaults and texts from a config, which `provideXConfig` ch The navbar and the anchors also take their label as an input: ``. +## Translating +The default texts are `$localize` with an id of their own, like `@@ngx-navigation.not-found.title`, so `ng extract-i18n` puts them into the messages of your app, and you translate them like its own texts. The library needs `@angular/localize` for that, `ng add @angular/localize`, also in an app of one language. A build with `localize` fills the texts in, so no part of `@angular/localize` reaches the browser. The defaults are made once a config is injected, so translations an app loads at runtime with `loadTranslations` apply as well. A text of `provideXConfig` replaces the default in every language. So translate a default in your messages, and change it in the config only to say something else: a default the config replaces stays in your messages, though nothing shows it. + # Moving from ngx-material-navigation The package was ngx-material-navigation, built on Angular Material. It is built on `@service-soft/ui` now, without Material and the cdk: diff --git a/projects/ngx-navigation/language-switcher/language-switcher-config.provider.ts b/projects/ngx-navigation/language-switcher/language-switcher-config.provider.ts index 8ef9bd1..601dbf3 100644 --- a/projects/ngx-navigation/language-switcher/language-switcher-config.provider.ts +++ b/projects/ngx-navigation/language-switcher/language-switcher-config.provider.ts @@ -3,13 +3,20 @@ import { faGlobe } from '@fortawesome/free-solid-svg-icons'; import { LanguageSwitcherConfig } from './language-switcher-config.model'; -const DEFAULT_LANGUAGE_SWITCHER_CONFIG: LanguageSwitcherConfig = { - appearance: 'menu', - label: 'Language', - icon: faGlobe, - // a build for every language under its own path, like Angular's i18n makes them: /de/orders and /en/orders. - href: (url, code, subPath) => `/${subPath}${url}` -}; +/** + * The values of a language switcher when nothing changes them. Its label is $localize, which an app translates like + * its own texts, and resolved once the config is injected, so translations an app loads at runtime apply as well. + * @returns The default config. + */ +function getDefaultLanguageSwitcherConfig(): LanguageSwitcherConfig { + return { + appearance: 'menu', + label: $localize`:@@ngx-navigation.language-switcher.label:Language`, + icon: faGlobe, + // a build for every language under its own path, like Angular's i18n makes them: /de/orders and /en/orders. + href: (url, code, subPath) => `/${subPath}${url}` + }; +} /** * The values every language switcher below this injector uses when its inputs are not set. @@ -19,7 +26,7 @@ export const LANGUAGE_SWITCHER_CONFIG: InjectionToken = 'LANGUAGE_SWITCHER_CONFIG', { providedIn: 'root', - factory: () => DEFAULT_LANGUAGE_SWITCHER_CONFIG + factory: () => getDefaultLanguageSwitcherConfig() } ); @@ -35,7 +42,7 @@ export function provideLanguageSwitcherConfig(config: Partial ({ - ...inject(LANGUAGE_SWITCHER_CONFIG, { skipSelf: true, optional: true }) ?? DEFAULT_LANGUAGE_SWITCHER_CONFIG, + ...inject(LANGUAGE_SWITCHER_CONFIG, { skipSelf: true, optional: true }) ?? getDefaultLanguageSwitcherConfig(), ...config }) }; diff --git a/projects/ngx-navigation/navbar/navbar-config.provider.ts b/projects/ngx-navigation/navbar/navbar-config.provider.ts index f9cc731..9fedf62 100644 --- a/projects/ngx-navigation/navbar/navbar-config.provider.ts +++ b/projects/ngx-navigation/navbar/navbar-config.provider.ts @@ -3,14 +3,21 @@ import { faBars } from '@fortawesome/free-solid-svg-icons'; import { NavbarConfig, NavbarConfigChanges } from './navbar-config.model'; -const DEFAULT_NAVBAR_CONFIG: NavbarConfig = { - labels: { - navigation: 'Navigation', - openNavigation: 'Open the navigation' - }, - collapse: 'sm', - menuIcon: faBars -}; +/** + * The values of the navbar when nothing changes them. Its texts are $localize, which an app translates like its own, + * and resolved once the config is injected, so translations an app loads at runtime apply as well. + * @returns The default config. + */ +function getDefaultNavbarConfig(): NavbarConfig { + return { + labels: { + navigation: $localize`:@@ngx-navigation.navbar.navigation:Navigation`, + openNavigation: $localize`:@@ngx-navigation.navbar.openNavigation:Open the navigation` + }, + collapse: 'sm', + menuIcon: faBars + }; +} /** * The values every navbar below this injector uses when its inputs or those of its elements are not set, and its texts. @@ -18,7 +25,7 @@ const DEFAULT_NAVBAR_CONFIG: NavbarConfig = { */ export const NAVBAR_CONFIG: InjectionToken = new InjectionToken('NAVBAR_CONFIG', { providedIn: 'root', - factory: () => DEFAULT_NAVBAR_CONFIG + factory: () => getDefaultNavbarConfig() }); /** @@ -33,7 +40,7 @@ export function provideNavbarConfig(config: NavbarConfigChanges): Provider { return { provide: NAVBAR_CONFIG, useFactory: (): NavbarConfig => { - const parent: NavbarConfig = inject(NAVBAR_CONFIG, { skipSelf: true, optional: true }) ?? DEFAULT_NAVBAR_CONFIG; + const parent: NavbarConfig = inject(NAVBAR_CONFIG, { skipSelf: true, optional: true }) ?? getDefaultNavbarConfig(); return { ...parent, ...config, labels: { ...parent.labels, ...config.labels } }; } }; diff --git a/projects/ngx-navigation/navigation/navigation-config.provider.ts b/projects/ngx-navigation/navigation/navigation-config.provider.ts index 598fec4..6e0d926 100644 --- a/projects/ngx-navigation/navigation/navigation-config.provider.ts +++ b/projects/ngx-navigation/navigation/navigation-config.provider.ts @@ -2,20 +2,27 @@ import { inject, InjectionToken, Provider } from '@angular/core'; import { NavigationConfig, NavigationConfigChanges } from './navigation-config.model'; -const DEFAULT_NAVIGATION_CONFIG: NavigationConfig = { - labels: { - home: 'Home', - anchors: 'On this page' - }, - routeCondition: () => true -}; +/** + * What the navigation shares when nothing changes it. Its texts are $localize, which an app translates like its own, + * and resolved once the config is injected, so translations an app loads at runtime apply as well. + * @returns The default config. + */ +function getDefaultNavigationConfig(): NavigationConfig { + return { + labels: { + home: $localize`:@@ngx-navigation.navigation.home:Home`, + anchors: $localize`:@@ngx-navigation.navigation.anchors:On this page` + }, + routeCondition: () => true + }; +} /** * What every part of the navigation below this injector shares, like its texts. Change it with provideNavigationConfig. */ export const NAVIGATION_CONFIG: InjectionToken = new InjectionToken('NAVIGATION_CONFIG', { providedIn: 'root', - factory: () => DEFAULT_NAVIGATION_CONFIG + factory: () => getDefaultNavigationConfig() }); /** @@ -29,7 +36,7 @@ export function provideNavigationConfig(config: NavigationConfigChanges): Provid return { provide: NAVIGATION_CONFIG, useFactory: (): NavigationConfig => { - const parent: NavigationConfig = inject(NAVIGATION_CONFIG, { skipSelf: true, optional: true }) ?? DEFAULT_NAVIGATION_CONFIG; + const parent: NavigationConfig = inject(NAVIGATION_CONFIG, { skipSelf: true, optional: true }) ?? getDefaultNavigationConfig(); return { ...parent, labels: { ...parent.labels, ...config.labels }, diff --git a/projects/ngx-navigation/not-found/not-found-config.provider.ts b/projects/ngx-navigation/not-found/not-found-config.provider.ts index ba50b85..141aa62 100644 --- a/projects/ngx-navigation/not-found/not-found-config.provider.ts +++ b/projects/ngx-navigation/not-found/not-found-config.provider.ts @@ -3,20 +3,27 @@ import { faSignsPost } from '@fortawesome/free-solid-svg-icons'; import { NotFoundConfig } from './not-found-config.model'; -const DEFAULT_NOT_FOUND_CONFIG: NotFoundConfig = { - title: 'Page not found', - message: 'The page you are looking for might have been removed, had its name changed or is temporarily unavailable.', - homeLabel: 'Back to the start page', - homeRoute: '/', - icon: faSignsPost -}; +/** + * What the page for unknown urls shows when nothing changes it. Its texts are $localize, which an app translates like + * its own, and resolved once the config is injected, so translations an app loads at runtime apply as well. + * @returns The default config. + */ +function getDefaultNotFoundConfig(): NotFoundConfig { + return { + title: $localize`:@@ngx-navigation.not-found.title:Page not found`, + message: $localize`:@@ngx-navigation.not-found.message:The page you are looking for might have been removed, had its name changed or is temporarily unavailable.`, + homeLabel: $localize`:@@ngx-navigation.not-found.homeLabel:Back to the start page`, + homeRoute: '/', + icon: faSignsPost + }; +} /** * What every page for unknown urls below this injector shows. Change it with provideNotFoundConfig. */ export const NOT_FOUND_CONFIG: InjectionToken = new InjectionToken('NOT_FOUND_CONFIG', { providedIn: 'root', - factory: () => DEFAULT_NOT_FOUND_CONFIG + factory: () => getDefaultNotFoundConfig() }); /** @@ -30,7 +37,7 @@ export function provideNotFoundConfig(config: Partial): Provider return { provide: NOT_FOUND_CONFIG, useFactory: (): NotFoundConfig => ({ - ...inject(NOT_FOUND_CONFIG, { skipSelf: true, optional: true }) ?? DEFAULT_NOT_FOUND_CONFIG, + ...inject(NOT_FOUND_CONFIG, { skipSelf: true, optional: true }) ?? getDefaultNotFoundConfig(), ...config }) }; diff --git a/projects/ngx-navigation/package.json b/projects/ngx-navigation/package.json index 01b1307..db95e81 100644 --- a/projects/ngx-navigation/package.json +++ b/projects/ngx-navigation/package.json @@ -1,6 +1,6 @@ { "name": "@service-soft/ngx-navigation", - "version": "22.3.0", + "version": "22.3.1", "license": "MIT", "repository": { "type": "git", @@ -21,11 +21,12 @@ "peerDependencies": { "@angular/common": "^22.2.0", "@angular/core": "^22.2.0", + "@angular/localize": "^22.2.0", "@angular/platform-browser": "^22.2.0", "@angular/router": "^22.2.0", "@angular/ssr": "^22.2.0", "@fortawesome/free-solid-svg-icons": "^7.3.1", - "@service-soft/ui": "^22.3.0", + "@service-soft/ui": "^22.3.1", "tailwindcss": "^4.3.3" }, "peerDependenciesMeta": { diff --git a/projects/ngx-navigation/seo-server/seo-server-config.model.ts b/projects/ngx-navigation/seo-server/seo-server-config.model.ts index ee01114..3125619 100644 --- a/projects/ngx-navigation/seo-server/seo-server-config.model.ts +++ b/projects/ngx-navigation/seo-server/seo-server-config.model.ts @@ -1,21 +1,16 @@ -import { Routes } from '@angular/router'; import { ServerRoute } from '@angular/ssr'; import { SeoLocale } from '@service-soft/ngx-navigation/seo'; import { SeoAppEngine } from './seo-app-engine.model'; /** - * Where resolvePages finds the pages of a site: its routes, how Angular renders them, and what its build wrote. + * Where resolvePages finds the pages of a site: the app, how Angular renders them, and what its build wrote. */ export type SeoServerConfig = { /** * The origin of the site, like 'https://example.com', without a slash at its end. */ origin: string, - /** - * The routes of the app, the same that provideRouter gets. - */ - routes: Routes, /** * The server routes of the app, the same that withRoutes of provideServerRendering gets, which say how each page * renders. diff --git a/projects/ngx-navigation/seo-server/seo-server.utilities.spec.ts b/projects/ngx-navigation/seo-server/seo-server.utilities.spec.ts index 5e881d2..7677285 100644 --- a/projects/ngx-navigation/seo-server/seo-server.utilities.spec.ts +++ b/projects/ngx-navigation/seo-server/seo-server.utilities.spec.ts @@ -123,7 +123,6 @@ describe('SeoServerUtilities', () => { const requests: string[] = []; const site: SeoSite = await SeoServerUtilities.resolvePages({ origin: ORIGIN, - routes: ROUTES, serverRoutes: SERVER_ROUTES, prerenderedRoutes: PRERENDERED_ROUTES, appEngine: createAppEngine(requests), @@ -140,8 +139,9 @@ describe('SeoServerUtilities', () => { ['/news/season', RenderMode.Server, undefined] ]); expect(site.unlistedRoutes).toEqual(['/members/:member']); - // data.sitemap ran in the app, rendered for the first page without parameters that renders on the server, as - // the route of unknown urls is prerendered here + expect(site.errorRoutes).toEqual([]); + // the app handed the routes over, rendered for the first server route without parameters that renders on the + // server, as the route of unknown urls is prerendered here expect(requests[0]).toBe('https://club.example/en/news'); expect(site.pages[0]?.localized).toEqual([ @@ -164,12 +164,16 @@ describe('SeoServerUtilities', () => { }); test('finds the pages of a site of one language at the urls without a prefix', async () => { + const routes: Routes = [{ path: '', component: PageComponent }, { path: 'teams/:team', component: PageComponent }]; const site: SeoSite = await SeoServerUtilities.resolvePages({ origin: ORIGIN, - routes: [{ path: '', component: PageComponent }, { path: 'teams/:team', component: PageComponent }], - serverRoutes: [{ path: '**', renderMode: RenderMode.Prerender }], + serverRoutes: [ + { path: '', renderMode: RenderMode.Prerender }, + { path: 'teams/:team', renderMode: RenderMode.Prerender }, + { path: '**', renderMode: RenderMode.Server, status: 404 } + ], prerenderedRoutes: ['/', '/teams/juniors'], - appEngine: createAppEngine([]), + appEngine: createAppEngine([], routes), locales: [{ code: 'en-US', subPath: '' }] }); @@ -185,8 +189,7 @@ describe('SeoServerUtilities', () => { ]; const site: SeoSite = await SeoServerUtilities.resolvePages({ origin: ORIGIN, - routes, - serverRoutes: [{ path: '**', renderMode: RenderMode.Server, status: 404 }], + serverRoutes: [{ path: 'news/:article', renderMode: RenderMode.Server }, { path: '**', renderMode: RenderMode.Server, status: 404 }], prerenderedRoutes: [], appEngine: createAppEngine(requests, routes), locales: LOCALES @@ -196,14 +199,29 @@ describe('SeoServerUtilities', () => { expect(site.pages.map(p => [p.path, p.lastModified])).toEqual([['/news/opening', new Date('2026-10-01')], ['/news/season', undefined]]); }); - test('tells why data.sitemap cannot run when no page renders on the server', async () => { + test('leaves out a page that answers with an error, like one that falls under the 404 of the route of unknown urls', async () => { const routes: Routes = [ { path: '', component: PageComponent }, - { path: 'news/:article', component: PageComponent, data: { sitemap: () => Promise.resolve(inject(ARTICLES)) } } + // added to the routes, but not to the server routes + { path: 'contact', component: PageComponent }, + { path: '**', component: PageComponent } ]; + const site: SeoSite = await SeoServerUtilities.resolvePages({ + origin: ORIGIN, + serverRoutes: [{ path: '', renderMode: RenderMode.Prerender }, { path: '**', renderMode: RenderMode.Server, status: 404 }], + prerenderedRoutes: ['/en', '/de'], + appEngine: createAppEngine([], routes), + locales: LOCALES + }); + + expect(site.pages.map(p => p.path)).toEqual(['/']); + expect(site.errorRoutes).toEqual(['/contact']); + }); + + test('tells why the pages cannot be read when no page renders on the server', async () => { + const routes: Routes = [{ path: '', component: PageComponent }]; const pages: Promise = SeoServerUtilities.resolvePages({ origin: ORIGIN, - routes, serverRoutes: [{ path: '**', renderMode: RenderMode.Prerender }], prerenderedRoutes: [], appEngine: createAppEngine([], routes), diff --git a/projects/ngx-navigation/seo-server/seo-server.utilities.ts b/projects/ngx-navigation/seo-server/seo-server.utilities.ts index c86e217..ce30e75 100644 --- a/projects/ngx-navigation/seo-server/seo-server.utilities.ts +++ b/projects/ngx-navigation/seo-server/seo-server.utilities.ts @@ -1,6 +1,6 @@ import { RenderMode, ServerRoute } from '@angular/ssr'; import { NavSitemapEntry } from '@service-soft/ngx-navigation/navigation'; -import { SeoLocale, SeoPageRoute, SeoRouteUtilities, SeoSitemapContext, SeoUrlUtilities } from '@service-soft/ngx-navigation/seo'; +import { SeoLocale, SeoSitemapContext, SeoSitemapRoute, SeoUrlUtilities } from '@service-soft/ngx-navigation/seo'; import { SeoLocalizedPage } from './seo-localized-page.model'; import { SeoPage } from './seo-page.model'; @@ -19,8 +19,8 @@ const MAX_SITEMAP_BYTES: number = 50 * 1024 * 1024; const SITEMAP_PATH: string = '/sitemap.xml'; -// the page resolvePages has the app render to run the data.sitemap of its routes: an unknown one, which the route of -// unknown urls renders on the server, to answer 404 +// the page resolvePages has the app render to get the routes of its pages: an unknown one, which the route of unknown +// urls renders on the server, to answer 404 const SITEMAP_REQUEST_PATH: string = '/__ngx-seo-sitemap'; // the files a server answers itself, which are the same in every language and redirect to none @@ -39,23 +39,30 @@ export abstract class SeoServerUtilities { /** * Finds every page of a site that search engines may index, in every language: the routes of the router config, * children and lazily loaded children included, without redirects, without the route of unknown urls and without - * routes whose data.robots holds noindex. A route with parameters gets the pages Angular prerendered for it, and the - * ones its data.sitemap lists, which the app runs as the app engine renders a page on the server. Its title and - * description in each language are read from the page as that language renders it, as the app engine answers it: - * prerendered, or rendered once now. A page only a browser renders has neither. + * routes whose data.robots holds noindex. The app hands them over as the app engine renders a page on the server, + * as only the app has them with its texts. A route with parameters gets the pages Angular prerendered for it, and + * the ones its data.sitemap lists, which the app runs then. A route whose server route answers with an error, like + * the 404 of the route of unknown urls, is left out. The title and description of a page in each language are read + * from the page as that language renders it, as the app engine answers it: prerendered, or rendered once now. A + * page only a browser renders has neither. * @param config - Where the pages are found. - * @returns The pages, and the routes with parameters whose pages could not be listed. - * @throws {Error} When a route has a data.sitemap, but no page renders on the server to run it. + * @returns The pages, the routes with parameters whose pages could not be listed, and the routes that answer with + * an error. + * @throws {Error} When no page renders on the server for the app to hand the routes over. */ static async resolvePages(config: SeoServerConfig): Promise { const prerenderedPaths: string[] = this.findPrerenderedPaths(config); - const routes: SeoPageRoute[] = await SeoRouteUtilities.findPageRoutes(config.routes); - const listed: Record = await this.resolveListedPages(config, routes); const pages: SeoPage[] = []; const unlistedRoutes: string[] = []; - for (const route of routes) { - const renderMode: RenderMode = this.findRenderMode(config.serverRoutes, route.path); - const entries: NavSitemapEntry[] = this.resolveEntries(route, listed[route.path] ?? [], prerenderedPaths); + const errorRoutes: string[] = []; + for (const route of await this.resolveSitemapRoutes(config)) { + const serverRoute: ServerRoute | undefined = this.findServerRoute(config.serverRoutes, route.path); + if (this.hasErrorStatus(serverRoute)) { + errorRoutes.push(`/${route.path}`); + continue; + } + const renderMode: RenderMode = serverRoute?.renderMode ?? RenderMode.Server; + const entries: NavSitemapEntry[] = this.resolveEntries(route, prerenderedPaths); if (!entries.length) { unlistedRoutes.push(`/${route.path}`); } @@ -70,7 +77,7 @@ export abstract class SeoServerUtilities { }); } } - return { pages, unlistedRoutes }; + return { pages, unlistedRoutes, errorRoutes }; } /** @@ -218,37 +225,37 @@ export abstract class SeoServerUtilities { return `${SeoUrlUtilities.normalizePath(urlPath)}${queryStart === -1 ? '' : url.slice(queryStart)}`; } - // the data.sitemap of the routes, which the app runs as it renders a page on the server for a request with the - // context. Only a page rendered for each request gets it: the route of unknown urls, or else a page without - // parameters that renders on the server - private static async resolveListedPages(config: SeoServerConfig, routes: SeoPageRoute[]): Promise> { - if (!routes.some(route => route.data.sitemap != undefined)) { - return {}; - } - const candidates: string[] = [ - SITEMAP_REQUEST_PATH, - ...routes.filter(route => !this.hasParameters(route.path)).map(route => `/${route.path}`) - ].filter(candidate => this.findRenderMode(config.serverRoutes, candidate) === RenderMode.Server); + // the routes of the pages, which the app hands over as it renders a page on the server for a request with the + // context, once it ran their data.sitemap. Only a page rendered for each request gets it: the route of unknown + // urls, or else a server route without parameters that renders on the server + private static async resolveSitemapRoutes(config: SeoServerConfig): Promise { + const staticPaths: string[] = config.serverRoutes + .map(serverRoute => `/${serverRoute.path}`) + .filter(path => !this.hasParameters(path) && !path.includes('*')); + const candidates: string[] = [SITEMAP_REQUEST_PATH, ...staticPaths].filter(candidate => { + return (this.findServerRoute(config.serverRoutes, candidate)?.renderMode ?? RenderMode.Server) === RenderMode.Server; + }); for (const candidate of candidates) { const context: SeoSitemapContext = { ngxSeoSitemap: undefined }; const url: string = SeoUrlUtilities.resolveUrl(config.origin, candidate, config.locales[0]); const response: Response | null = await config.appEngine.handle(new Request(url), context); - // the app has run them once the page is rendered + // the app has handed them over once the page is rendered await response?.text(); if (context.ngxSeoSitemap != undefined) { return context.ngxSeoSitemap; } } - throw new Error('The data.sitemap of a route runs in the app as the server renders a page, which needs one with ' + throw new Error('The app hands the server the routes of its pages as the server renders a page, which needs one with ' + 'RenderMode.Server, like the route of unknown urls: { path: \'**\', renderMode: RenderMode.Server, status: 404 }. ' + 'And the app needs provideSeoConfig.'); } // the pages of a route: the one of its path, or the ones of its parameters, listed or prerendered - private static resolveEntries(route: SeoPageRoute, listed: NavSitemapEntry[], prerenderedPaths: string[]): NavSitemapEntry[] { + private static resolveEntries(route: SeoSitemapRoute, prerenderedPaths: string[]): NavSitemapEntry[] { if (!this.hasParameters(route.path)) { return [{ path: `/${route.path}` }]; } + const listed: NavSitemapEntry[] = route.listed ?? []; const prerendered: NavSitemapEntry[] = prerenderedPaths .filter(prerenderedPath => this.matchesPattern(route.path, prerenderedPath)) .filter(prerenderedPath => !listed.some(entry => SeoUrlUtilities.normalizePath(entry.path) === prerenderedPath)) @@ -299,9 +306,15 @@ export abstract class SeoServerUtilities { return [...new Set(paths)]; } - // by the first server route that matches, like the router of @angular/ssr finds it, and on the server when none does - private static findRenderMode(serverRoutes: ServerRoute[], routePath: string): RenderMode { - return serverRoutes.find(serverRoute => this.matchesPattern(serverRoute.path, routePath))?.renderMode ?? RenderMode.Server; + // the first server route that matches, like the router of @angular/ssr finds it. A page renders on the server when + // none does + private static findServerRoute(serverRoutes: ServerRoute[], routePath: string): ServerRoute | undefined { + return serverRoutes.find(serverRoute => this.matchesPattern(serverRoute.path, routePath)); + } + + // like a route without a server route of its own, which falls under the 404 of the route of unknown urls + private static hasErrorStatus(serverRoute: ServerRoute | undefined): boolean { + return serverRoute != undefined && 'status' in serverRoute && serverRoute.status != undefined && serverRoute.status >= 400; } // whether a path matches a pattern of routes, like 'teams/:team', '*' or '**'. A parameter of the path matches a diff --git a/projects/ngx-navigation/seo-server/seo-site.model.ts b/projects/ngx-navigation/seo-server/seo-site.model.ts index 72b7473..bf0ea5d 100644 --- a/projects/ngx-navigation/seo-server/seo-site.model.ts +++ b/projects/ngx-navigation/seo-server/seo-site.model.ts @@ -12,5 +12,10 @@ export type SeoSite = { * The routes with parameters whose pages could not be listed: Angular prerendered none of them, and their data has * no sitemap. Their pages are missing from the sitemap, which a server can warn about. */ - unlistedRoutes: string[] + unlistedRoutes: string[], + /** + * The routes whose server route answers with an error, like one without a server route of its own that falls + * under the 404 of the route of unknown urls. They are left out of the sitemap, which a server can warn about. + */ + errorRoutes: string[] }; \ No newline at end of file diff --git a/projects/ngx-navigation/seo/public-api.ts b/projects/ngx-navigation/seo/public-api.ts index 8e973b6..301cba0 100644 --- a/projects/ngx-navigation/seo/public-api.ts +++ b/projects/ngx-navigation/seo/public-api.ts @@ -5,5 +5,6 @@ export * from './seo-locale.model'; export * from './seo-page-route.model'; export * from './seo-route.utilities'; export * from './seo-sitemap-context.model'; +export * from './seo-sitemap-route.model'; export * from './seo-url.utilities'; export * from './seo.provider'; \ No newline at end of file diff --git a/projects/ngx-navigation/seo/seo-route.utilities.ts b/projects/ngx-navigation/seo/seo-route.utilities.ts index 5bb3027..67b9963 100644 --- a/projects/ngx-navigation/seo/seo-route.utilities.ts +++ b/projects/ngx-navigation/seo/seo-route.utilities.ts @@ -1,47 +1,38 @@ import { EnvironmentInjector, runInInjectionContext } from '@angular/core'; import { Route, Routes } from '@angular/router'; -import { NavRouteData, NavSitemapEntry } from '@service-soft/ngx-navigation/navigation'; +import { NavRouteData } from '@service-soft/ngx-navigation/navigation'; import { SeoPageRoute } from './seo-page-route.model'; import { SeoSitemapContext } from './seo-sitemap-context.model'; +import { SeoSitemapRoute } from './seo-sitemap-route.model'; /** - * Finds the pages of the routes of an app, the same way in the app and on its server, which lists them for the - * sitemap. + * Finds the pages of the routes of an app, in the app, which hands them to its server for the sitemap. The server + * can't import the routes itself: in a site in several languages their texts are $localize, which only the build of + * each language fills in. */ export abstract class SeoRouteUtilities { /** - * Finds the routes that render a page search engines may index, depth first: children and lazily loaded children + * Resolves the routes that render a page search engines may index, depth first: children and lazily loaded children * included, without redirects, without the route of unknown urls and matchers, and without routes whose data.robots - * holds noindex. + * holds noindex. Each with the pages its data.sitemap lists, which runs in an injection context of the app, so it + * can inject what it reads them with, like the HttpClient. * @param routes - The routes of the app, the same that provideRouter gets. - * @returns The routes of the pages, by their whole path. - */ - static async findPageRoutes(routes: Routes): Promise { - return this.findChildPageRoutes(routes, '', {}); - } - - /** - * Resolves the pages that the data.sitemap of each route lists, in an injection context of the app, so they can - * inject what they read them with, like the HttpClient. - * @param routes - The routes of the app. * @param injector - The injector of the app. - * @returns The pages, by the path of their route, like 'news/:article'. + * @returns The routes of the pages, by their whole path. */ - static async resolveListedPages(routes: Routes, injector: EnvironmentInjector): Promise> { - const listed: Record = {}; - for (const route of await this.findPageRoutes(routes)) { + static async resolveSitemapRoutes(routes: Routes, injector: EnvironmentInjector): Promise { + const sitemapRoutes: SeoSitemapRoute[] = []; + for (const route of await this.findChildPageRoutes(routes, '', {})) { const sitemap: NavRouteData['sitemap'] = route.data.sitemap; - if (sitemap != undefined) { - listed[route.path] = await runInInjectionContext(injector, sitemap); - } + sitemapRoutes.push({ ...route, listed: sitemap == undefined ? undefined : await runInInjectionContext(injector, sitemap) }); } - return listed; + return sitemapRoutes; } /** - * Whether the REQUEST_CONTEXT of a request is the one SeoServerUtilities.resolvePages renders a page with, to run - * the data.sitemap of the routes. + * Whether the REQUEST_CONTEXT of a request is the one SeoServerUtilities.resolvePages renders a page with, to get + * the routes of the pages. * @param context - The REQUEST_CONTEXT, null in the browser and for a page rendered for any other request. * @returns Whether it is. */ diff --git a/projects/ngx-navigation/seo/seo-sitemap-context.model.ts b/projects/ngx-navigation/seo/seo-sitemap-context.model.ts index d53c5e2..f2c4b40 100644 --- a/projects/ngx-navigation/seo/seo-sitemap-context.model.ts +++ b/projects/ngx-navigation/seo/seo-sitemap-context.model.ts @@ -1,12 +1,12 @@ -import { NavSitemapEntry } from '@service-soft/ngx-navigation/navigation'; +import { SeoSitemapRoute } from './seo-sitemap-route.model'; /** - * The REQUEST_CONTEXT of the request SeoServerUtilities.resolvePages renders a page for, in which provideSeoConfig runs - * the data.sitemap of every route in the app, before the page renders. + * The REQUEST_CONTEXT of the request SeoServerUtilities.resolvePages renders a page for, in which provideSeoConfig hands + * the server the routes of the pages of the app, with what their data.sitemap lists, before the page renders. */ export type SeoSitemapContext = { /** - * The pages data.sitemap lists, by the path of their route, like 'news/:article'. Undefined until the app ran them. + * The routes of the pages. Undefined until the app handed them over. */ - ngxSeoSitemap: Record | undefined + ngxSeoSitemap: SeoSitemapRoute[] | undefined }; \ No newline at end of file diff --git a/projects/ngx-navigation/seo/seo-sitemap-route.model.ts b/projects/ngx-navigation/seo/seo-sitemap-route.model.ts new file mode 100644 index 0000000..c8709ce --- /dev/null +++ b/projects/ngx-navigation/seo/seo-sitemap-route.model.ts @@ -0,0 +1,14 @@ +import { NavSitemapEntry } from '@service-soft/ngx-navigation/navigation'; + +import { SeoPageRoute } from './seo-page-route.model'; + +/** + * A route of the router config that renders a page, as the app hands it to SeoServerUtilities.resolvePages, with the + * pages its data.sitemap lists. + */ +export type SeoSitemapRoute = SeoPageRoute & { + /** + * The pages data.sitemap lists, like the articles of a database. Undefined for a route without one. + */ + listed: NavSitemapEntry[] | undefined +}; \ No newline at end of file diff --git a/projects/ngx-navigation/seo/seo.provider.ts b/projects/ngx-navigation/seo/seo.provider.ts index e0011de..db63dc4 100644 --- a/projects/ngx-navigation/seo/seo.provider.ts +++ b/projects/ngx-navigation/seo/seo.provider.ts @@ -11,8 +11,9 @@ import { SeoService } from './seo.service'; * Writes what each page tells search engines and AI assistants about itself into the head of the document, on every * navigation and on the server too, so the prerendered html holds it: the description, the canonical url, the * structured data, the robots, the og tags of a shared link and, for a site in several languages, the url of the page - * in each of them, from the NavRouteData of its routes. On the server, it also runs the data.sitemap of the routes for - * SeoServerUtilities.resolvePages of `@service-soft/ngx-navigation/seo-server`. Provide it in the application config: + * in each of them, from the NavRouteData of its routes. On the server, it also hands SeoServerUtilities.resolvePages of + * `@service-soft/ngx-navigation/seo-server` the routes of the pages, with what their data.sitemap lists. Provide it in + * the application config: * `provideSeoConfig({ origin: 'https://example.com' })`, with `locales` for a site Angular i18n builds in several * languages. * @param config - The origin of the site, a default image and the languages if you like. @@ -34,7 +35,7 @@ export function provideSeoConfig(config: SeoConfigChanges): EnvironmentProviders const context: unknown = inject(REQUEST_CONTEXT); if (SeoRouteUtilities.isSitemapContext(context)) { // the page renders once they are done - context.ngxSeoSitemap = await SeoRouteUtilities.resolveListedPages(inject(Router).config, inject(EnvironmentInjector)); + context.ngxSeoSitemap = await SeoRouteUtilities.resolveSitemapRoutes(inject(Router).config, inject(EnvironmentInjector)); } }) ]); diff --git a/projects/ngx-navigation/tsconfig.lib.json b/projects/ngx-navigation/tsconfig.lib.json index 5ed1187..5315f63 100644 --- a/projects/ngx-navigation/tsconfig.lib.json +++ b/projects/ngx-navigation/tsconfig.lib.json @@ -8,7 +8,7 @@ // the paths of the workspace point to the sources of the other libraries, which the build would then compile // into this one. Without them, they resolve from node_modules like for a consumer, so ui has to be built first. "paths": {}, - "types": [] + "types": ["@angular/localize"] }, "exclude": ["**/*.spec.ts", "**/*.stories.ts"], "extends": "../../tsconfig.json", diff --git a/projects/ngx-navigation/tsconfig.spec.json b/projects/ngx-navigation/tsconfig.spec.json index cf926c8..d1df25e 100644 --- a/projects/ngx-navigation/tsconfig.spec.json +++ b/projects/ngx-navigation/tsconfig.spec.json @@ -3,7 +3,7 @@ { "compilerOptions": { "outDir": "../../out-tsc/spec", - "types": ["vitest/globals"] + "types": ["vitest/globals", "@angular/localize"] }, "extends": "../../tsconfig.json", "include": ["**/*.d.ts", "**/*.spec.ts"] diff --git a/projects/ngx-persistence-logger/README.md b/projects/ngx-persistence-logger/README.md index ca44a8e..a77ae19 100644 --- a/projects/ngx-persistence-logger/README.md +++ b/projects/ngx-persistence-logger/README.md @@ -14,11 +14,13 @@ Logs to the console of the browser and sends the logs to your backend, like the - [Log history](#log-history) - [The endpoint of the logs](#the-endpoint-of-the-logs) - [Configuration](#configuration) + - [Translating](#translating) - [Moving from the old ngx-persistence-logger](#moving-from-the-old-ngx-persistence-logger) - [License](#license) # Requirements -Angular 22. The log history also needs `@service-soft/ui` and Tailwind CSS 4. The models a log is sent and read as, +Angular 22. The log history also needs `@service-soft/ui`, `@angular/localize`, which [translates its texts](#translating), +and Tailwind CSS 4. The models a log is sent and read as, like `LogLevel`, `LogContext` and `PaginationResult`, come from [zibri-contract](https://www.npmjs.com/package/zibri-contract), the package zibri declares them in. @@ -26,6 +28,7 @@ the package zibri declares them in. npm install @service-soft/ngx-persistence-logger zibri-contract # only for the log history npm install @service-soft/ui +ng add @angular/localize ``` # Logger @@ -219,6 +222,9 @@ provideLogHistoryConfig({ pageSize: 25, labels: { levels: { [LogLevel.WARN]: 'Wa The buttons of the pages are the pagination of `@service-soft/ui`, whose names `providePaginationConfig` translates. +### Translating +The default texts are `$localize` with an id of their own, like `@@ngx-persistence-logger.log-history.search`, so `ng extract-i18n` puts them into the messages of your app, and you translate them like its own texts. The log history needs `@angular/localize` for that, `ng add @angular/localize`, also in an app of one language. A build with `localize` fills the texts in, so no part of `@angular/localize` reaches the browser. The defaults are made once a config is injected, so translations an app loads at runtime with `loadTranslations` apply as well. A text of `provideLogHistoryConfig` replaces the default in every language. So translate a default in your messages, and change it in the config only to say something else: a default the config replaces stays in your messages, though nothing shows it. + # Moving from the old ngx-persistence-logger - The package is `@service-soft/ngx-persistence-logger`. Import the logger from `/logger` and the log history from `/log-history`. - `BaseLoggerService` is `LoggerService`, which you inject without extending it. `LOG_URL` and `APPLICATION_NAME` are `logUrl` and `application` of `provideLoggerConfig`, and the `NGX_LOGGER_SERVICE` token is gone. diff --git a/projects/ngx-persistence-logger/log-history/applications-filter.component.ts b/projects/ngx-persistence-logger/log-history/applications-filter.component.ts index 7ee0b46..8b960c3 100644 --- a/projects/ngx-persistence-logger/log-history/applications-filter.component.ts +++ b/projects/ngx-persistence-logger/log-history/applications-filter.component.ts @@ -58,7 +58,8 @@ export class ApplicationsFilterComponent { * The text of the button, like 'Applications: Api, Website', which is its name for screen readers as well. */ protected readonly summary: Signal = computed(() => { - return `${this.label()}: ${this.selected().length ? this.selected().join(', ') : this.allLabel()}`; + const applications: string = this.selected().length ? this.selected().join(', ') : this.allLabel(); + return $localize`:@@ngx-persistence-logger.log-history.applicationsSummary:${this.label()}:label:: ${applications}:applications:`; }); /** diff --git a/projects/ngx-persistence-logger/log-history/log-history-config.provider.ts b/projects/ngx-persistence-logger/log-history/log-history-config.provider.ts index bf7fdfb..589a4e4 100644 --- a/projects/ngx-persistence-logger/log-history/log-history-config.provider.ts +++ b/projects/ngx-persistence-logger/log-history/log-history-config.provider.ts @@ -4,38 +4,45 @@ import { LogLevel } from 'zibri-contract'; import { LogHistoryConfigChanges } from './log-history-config-changes.model'; import { LogHistoryConfig } from './log-history-config.model'; -const DEFAULT_LOG_HISTORY_CONFIG: LogHistoryConfig = { - dateFormat: 'yyyy-MM-dd HH:mm:ss.SSS', - pageSize: 10, - levels: [LogLevel.CRITICAL, LogLevel.ERROR, LogLevel.WARN, LogLevel.INFO], - liveModeInterval: 1000, - labels: { - levels: { - [LogLevel.CRITICAL]: 'Critical', - [LogLevel.ERROR]: 'Error', - [LogLevel.WARN]: 'Warning', - [LogLevel.INFO]: 'Info', - [LogLevel.DEBUG]: 'Debug' - }, - levelFilter: 'Levels', - applications: 'Applications', - allApplications: 'All', - search: 'Search', - reload: 'Reload', - liveMode: 'Live mode', - stack: 'Stack trace', - pages: 'Pages of the logs', - noLogs: 'No log matches the filters.', - loadingFailed: 'The logs couldn\'t be loaded.' - } -}; +/** + * The values of the log history when nothing changes them. Its texts are $localize, which an app translates like its + * own, and resolved once the config is injected, so translations an app loads at runtime apply as well. + * @returns The default config. + */ +function getDefaultLogHistoryConfig(): LogHistoryConfig { + return { + dateFormat: 'yyyy-MM-dd HH:mm:ss.SSS', + pageSize: 10, + levels: [LogLevel.CRITICAL, LogLevel.ERROR, LogLevel.WARN, LogLevel.INFO], + liveModeInterval: 1000, + labels: { + levels: { + [LogLevel.CRITICAL]: $localize`:@@ngx-persistence-logger.log-history.levels.critical:Critical`, + [LogLevel.ERROR]: $localize`:@@ngx-persistence-logger.log-history.levels.error:Error`, + [LogLevel.WARN]: $localize`:@@ngx-persistence-logger.log-history.levels.warn:Warning`, + [LogLevel.INFO]: $localize`:@@ngx-persistence-logger.log-history.levels.info:Info`, + [LogLevel.DEBUG]: $localize`:@@ngx-persistence-logger.log-history.levels.debug:Debug` + }, + levelFilter: $localize`:@@ngx-persistence-logger.log-history.levelFilter:Levels`, + applications: $localize`:@@ngx-persistence-logger.log-history.applications:Applications`, + allApplications: $localize`:@@ngx-persistence-logger.log-history.allApplications:All`, + search: $localize`:@@ngx-persistence-logger.log-history.search:Search`, + reload: $localize`:@@ngx-persistence-logger.log-history.reload:Reload`, + liveMode: $localize`:@@ngx-persistence-logger.log-history.liveMode:Live mode`, + stack: $localize`:@@ngx-persistence-logger.log-history.stack:Stack trace`, + pages: $localize`:@@ngx-persistence-logger.log-history.pages:Pages of the logs`, + noLogs: $localize`:@@ngx-persistence-logger.log-history.noLogs:No log matches the filters.`, + loadingFailed: $localize`:@@ngx-persistence-logger.log-history.loadingFailed:The logs couldn't be loaded.` + } + }; +} /** * The values every log history below this injector uses. Change them with provideLogHistoryConfig. */ export const LOG_HISTORY_CONFIG: InjectionToken = new InjectionToken('LOG_HISTORY_CONFIG', { providedIn: 'root', - factory: () => DEFAULT_LOG_HISTORY_CONFIG + factory: () => getDefaultLogHistoryConfig() }); /** @@ -49,7 +56,7 @@ export function provideLogHistoryConfig(config: LogHistoryConfigChanges): Provid return { provide: LOG_HISTORY_CONFIG, useFactory: (): LogHistoryConfig => { - const parent: LogHistoryConfig = inject(LOG_HISTORY_CONFIG, { skipSelf: true, optional: true }) ?? DEFAULT_LOG_HISTORY_CONFIG; + const parent: LogHistoryConfig = inject(LOG_HISTORY_CONFIG, { skipSelf: true, optional: true }) ?? getDefaultLogHistoryConfig(); return { ...parent, ...config, diff --git a/projects/ngx-persistence-logger/package.json b/projects/ngx-persistence-logger/package.json index 0c20ac9..283292b 100644 --- a/projects/ngx-persistence-logger/package.json +++ b/projects/ngx-persistence-logger/package.json @@ -1,6 +1,6 @@ { "name": "@service-soft/ngx-persistence-logger", - "version": "22.3.0", + "version": "22.3.1", "license": "MIT", "repository": { "type": "git", @@ -21,12 +21,16 @@ "peerDependencies": { "@angular/common": "^22.2.0", "@angular/core": "^22.2.0", + "@angular/localize": "^22.2.0", "@fortawesome/free-solid-svg-icons": "^7.3.1", - "@service-soft/ui": "^22.3.0", + "@service-soft/ui": "^22.3.1", "tailwindcss": "^4.3.3", "zibri-contract": "^3.1.0" }, "peerDependenciesMeta": { + "@angular/localize": { + "optional": true + }, "@fortawesome/free-solid-svg-icons": { "optional": true }, diff --git a/projects/ngx-persistence-logger/tsconfig.lib.json b/projects/ngx-persistence-logger/tsconfig.lib.json index 5ed1187..5315f63 100644 --- a/projects/ngx-persistence-logger/tsconfig.lib.json +++ b/projects/ngx-persistence-logger/tsconfig.lib.json @@ -8,7 +8,7 @@ // the paths of the workspace point to the sources of the other libraries, which the build would then compile // into this one. Without them, they resolve from node_modules like for a consumer, so ui has to be built first. "paths": {}, - "types": [] + "types": ["@angular/localize"] }, "exclude": ["**/*.spec.ts", "**/*.stories.ts"], "extends": "../../tsconfig.json", diff --git a/projects/ngx-persistence-logger/tsconfig.spec.json b/projects/ngx-persistence-logger/tsconfig.spec.json index cf926c8..d1df25e 100644 --- a/projects/ngx-persistence-logger/tsconfig.spec.json +++ b/projects/ngx-persistence-logger/tsconfig.spec.json @@ -3,7 +3,7 @@ { "compilerOptions": { "outDir": "../../out-tsc/spec", - "types": ["vitest/globals"] + "types": ["vitest/globals", "@angular/localize"] }, "extends": "../../tsconfig.json", "include": ["**/*.d.ts", "**/*.spec.ts"] diff --git a/projects/ngx-pwa/README.md b/projects/ngx-pwa/README.md index 9cd6792..63bfa54 100644 --- a/projects/ngx-pwa/README.md +++ b/projects/ngx-pwa/README.md @@ -17,14 +17,16 @@ Everything works with server-side rendering: on the server nothing is kept, sent - [Sync dialog](#sync-dialog) - [Push notifications](#push-notifications) - [Updates](#updates) +- [Translating](#translating) - [Moving from ngx-pwa](#moving-from-ngx-pwa) - [License](#license) # Requirements -Angular 22 with `@angular/service-worker` set up by `ng add @angular/pwa`. The offline status bar, the sync dialog and the update dialog also need [@service-soft/ui](https://www.npmjs.com/package/@service-soft/ui) and Tailwind CSS 4. +Angular 22 with `@angular/service-worker` set up by `ng add @angular/pwa`. The offline status bar, the sync dialog and the update dialog also need [@service-soft/ui](https://www.npmjs.com/package/@service-soft/ui), `@angular/localize`, which [translates their texts](#translating), and Tailwind CSS 4. ```sh npm install @service-soft/ngx-pwa @service-soft/ui +ng add @angular/localize ``` ```css @@ -206,6 +208,9 @@ providers: [ To check for a new version yourself, call `checkForUpdate()` of `SwUpdate`. +# Translating +The default texts are `$localize` with an id of their own, like `@@ngx-pwa.sync-dialog.title`, so `ng extract-i18n` puts them into the messages of your app, and you translate them like its own texts. The offline status bar, the sync dialog and the update dialog need `@angular/localize` for that, `ng add @angular/localize`, also in an app of one language. A build with `localize` fills the texts in, so no part of `@angular/localize` reaches the browser. The defaults are made once a config is injected, so translations an app loads at runtime with `loadTranslations` apply as well. A text of `provideOfflineStatusBarConfig`, `provideSyncDialogConfig` or `provideUpdates` replaces the default in every language. So translate a default in your messages, and change it in the config only to say something else: a default the config replaces stays in your messages, though nothing shows it. + # Moving from ngx-pwa - The package is `@service-soft/ngx-pwa`, with an entry point each for `/offline`, `/offline-status-bar`, `/sync-dialog`, `/push-notifications` and `/updates`. It needs `@service-soft/ui` and Tailwind instead of Angular Material, and no longer lodash, uuid and dompurify. - `NgxPwaOfflineService` and `NGX_PWA_OFFLINE_SERVICE` are `OfflineService`, which you inject directly instead of extending it. `isOffline` is the signal `offline()` and `cachedRequests` a read-only signal. `removeSingleRequest` is `remove`, and setting `cachedRequests = []` is `removeAll()`. `sync` and `syncAll` reject when they fail instead of showing a snackbar; the sync dialog shows it. diff --git a/projects/ngx-pwa/offline-status-bar/offline-status-bar-config.provider.ts b/projects/ngx-pwa/offline-status-bar/offline-status-bar-config.provider.ts index 61a3fd2..4ee26a8 100644 --- a/projects/ngx-pwa/offline-status-bar/offline-status-bar-config.provider.ts +++ b/projects/ngx-pwa/offline-status-bar/offline-status-bar-config.provider.ts @@ -3,14 +3,21 @@ import { inject, InjectionToken, Provider } from '@angular/core'; import { OfflineStatusBarConfigChanges } from './offline-status-bar-config-changes.model'; import { OfflineStatusBarConfig } from './offline-status-bar-config.model'; -const DEFAULT_OFFLINE_STATUS_BAR_CONFIG: OfflineStatusBarConfig = { - labels: { - offline: 'Offline', - loadedAt: 'Data from', - unsavedChanges: 'Unsaved changes', - sync: 'Sync' - } -}; +/** + * What the offline status bar shows when nothing changes it. Its texts are $localize, which an app translates like its + * own, and resolved once the config is injected, so translations an app loads at runtime apply as well. + * @returns The default config. + */ +function getDefaultOfflineStatusBarConfig(): OfflineStatusBarConfig { + return { + labels: { + offline: $localize`:@@ngx-pwa.offline-status-bar.offline:Offline`, + loadedAt: $localize`:@@ngx-pwa.offline-status-bar.loadedAt:Data from`, + unsavedChanges: $localize`:@@ngx-pwa.offline-status-bar.unsavedChanges:Unsaved changes`, + sync: $localize`:@@ngx-pwa.offline-status-bar.sync:Sync` + } + }; +} /** * The values every offline status bar below this injector uses. Change them with provideOfflineStatusBarConfig. @@ -19,7 +26,7 @@ export const OFFLINE_STATUS_BAR_CONFIG: InjectionToken = 'OFFLINE_STATUS_BAR_CONFIG', { providedIn: 'root', - factory: () => DEFAULT_OFFLINE_STATUS_BAR_CONFIG + factory: () => getDefaultOfflineStatusBarConfig() } ); @@ -35,7 +42,7 @@ export function provideOfflineStatusBarConfig(config: OfflineStatusBarConfigChan provide: OFFLINE_STATUS_BAR_CONFIG, useFactory: (): OfflineStatusBarConfig => { const parent: OfflineStatusBarConfig = inject(OFFLINE_STATUS_BAR_CONFIG, { skipSelf: true, optional: true }) - ?? DEFAULT_OFFLINE_STATUS_BAR_CONFIG; + ?? getDefaultOfflineStatusBarConfig(); return { ...parent, ...config, labels: { ...parent.labels, ...config.labels } }; } }; diff --git a/projects/ngx-pwa/package.json b/projects/ngx-pwa/package.json index 812dc98..66b943f 100644 --- a/projects/ngx-pwa/package.json +++ b/projects/ngx-pwa/package.json @@ -1,6 +1,6 @@ { "name": "@service-soft/ngx-pwa", - "version": "22.3.0", + "version": "22.3.1", "license": "MIT", "repository": { "type": "git", @@ -21,12 +21,16 @@ "peerDependencies": { "@angular/common": "^22.2.0", "@angular/core": "^22.2.0", + "@angular/localize": "^22.2.0", "@angular/service-worker": "^22.2.0", "@fortawesome/free-solid-svg-icons": "^7.3.1", - "@service-soft/ui": "^22.3.0", + "@service-soft/ui": "^22.3.1", "tailwindcss": "^4.3.3" }, "peerDependenciesMeta": { + "@angular/localize": { + "optional": true + }, "@fortawesome/free-solid-svg-icons": { "optional": true }, diff --git a/projects/ngx-pwa/sync-dialog/sync-dialog-config.provider.ts b/projects/ngx-pwa/sync-dialog/sync-dialog-config.provider.ts index 24c61e3..67e5332 100644 --- a/projects/ngx-pwa/sync-dialog/sync-dialog-config.provider.ts +++ b/projects/ngx-pwa/sync-dialog/sync-dialog-config.provider.ts @@ -3,38 +3,45 @@ import { InjectionToken, Provider } from '@angular/core'; import { SyncDialogConfigChanges } from './sync-dialog-config-changes.model'; import { SyncDialogConfig } from './sync-dialog-config.model'; -const DEFAULT_SYNC_DIALOG_CONFIG: SyncDialogConfig = { - labels: { - title: 'Unsaved changes', - offline: 'You are offline. Your changes are kept on this device until you sync them.', - methods: { - POST: 'New', - PATCH: 'Changed', - DELETE: 'Deleted' - }, - sync: 'Sync', - discard: 'Discard', - syncAll: 'Sync all', - discardAll: 'Discard all', - discardAllTitle: 'Discard every change?', - discardAllMessage: 'The changes are deleted from this device without being synced. This can\'t be undone.', - cancel: 'Cancel', - close: 'Close', - beforeLogout: 'Sync or discard your changes before you log out.', - stayLoggedIn: 'Stay logged in', - synced: 'Synced.', - discarded: 'Discarded.', - syncFailed: 'Syncing failed. Please try again later.', - allSynced: 'Every change is synced.' - } -}; +/** + * What the sync dialog shows when nothing changes it. Its texts are $localize, which an app translates like its own, + * and resolved once the config is injected, so translations an app loads at runtime apply as well. + * @returns The default config. + */ +function getDefaultSyncDialogConfig(): SyncDialogConfig { + return { + labels: { + title: $localize`:@@ngx-pwa.sync-dialog.title:Unsaved changes`, + offline: $localize`:@@ngx-pwa.sync-dialog.offline:You are offline. Your changes are kept on this device until you sync them.`, + methods: { + POST: $localize`:@@ngx-pwa.sync-dialog.methods.POST:New`, + PATCH: $localize`:@@ngx-pwa.sync-dialog.methods.PATCH:Changed`, + DELETE: $localize`:@@ngx-pwa.sync-dialog.methods.DELETE:Deleted` + }, + sync: $localize`:@@ngx-pwa.sync-dialog.sync:Sync`, + discard: $localize`:@@ngx-pwa.sync-dialog.discard:Discard`, + syncAll: $localize`:@@ngx-pwa.sync-dialog.syncAll:Sync all`, + discardAll: $localize`:@@ngx-pwa.sync-dialog.discardAll:Discard all`, + discardAllTitle: $localize`:@@ngx-pwa.sync-dialog.discardAllTitle:Discard every change?`, + discardAllMessage: $localize`:@@ngx-pwa.sync-dialog.discardAllMessage:The changes are deleted from this device without being synced. This can't be undone.`, + cancel: $localize`:@@ngx-pwa.sync-dialog.cancel:Cancel`, + close: $localize`:@@ngx-pwa.sync-dialog.close:Close`, + beforeLogout: $localize`:@@ngx-pwa.sync-dialog.beforeLogout:Sync or discard your changes before you log out.`, + stayLoggedIn: $localize`:@@ngx-pwa.sync-dialog.stayLoggedIn:Stay logged in`, + synced: $localize`:@@ngx-pwa.sync-dialog.synced:Synced.`, + discarded: $localize`:@@ngx-pwa.sync-dialog.discarded:Discarded.`, + syncFailed: $localize`:@@ngx-pwa.sync-dialog.syncFailed:Syncing failed. Please try again later.`, + allSynced: $localize`:@@ngx-pwa.sync-dialog.allSynced:Every change is synced.` + } + }; +} /** * What the sync dialog shows. Change it with provideSyncDialogConfig. */ export const SYNC_DIALOG_CONFIG: InjectionToken = new InjectionToken('SYNC_DIALOG_CONFIG', { providedIn: 'root', - factory: () => DEFAULT_SYNC_DIALOG_CONFIG + factory: () => getDefaultSyncDialogConfig() }); /** @@ -45,9 +52,14 @@ export const SYNC_DIALOG_CONFIG: InjectionToken = new Injectio * @returns The provider for SYNC_DIALOG_CONFIG. */ export function provideSyncDialogConfig(config: SyncDialogConfigChanges): Provider { - const defaults: SyncDialogConfig = DEFAULT_SYNC_DIALOG_CONFIG; - const syncDialogConfig: SyncDialogConfig = { - labels: { ...defaults.labels, ...config.labels, methods: { ...defaults.labels.methods, ...config.labels?.methods } } + return { + provide: SYNC_DIALOG_CONFIG, + // a factory rather than a value, so the default texts are resolved once the config is injected, like without it. + useFactory: (): SyncDialogConfig => { + const defaults: SyncDialogConfig = getDefaultSyncDialogConfig(); + return { + labels: { ...defaults.labels, ...config.labels, methods: { ...defaults.labels.methods, ...config.labels?.methods } } + }; + } }; - return { provide: SYNC_DIALOG_CONFIG, useValue: syncDialogConfig }; } \ No newline at end of file diff --git a/projects/ngx-pwa/tsconfig.lib.json b/projects/ngx-pwa/tsconfig.lib.json index 5ed1187..5315f63 100644 --- a/projects/ngx-pwa/tsconfig.lib.json +++ b/projects/ngx-pwa/tsconfig.lib.json @@ -8,7 +8,7 @@ // the paths of the workspace point to the sources of the other libraries, which the build would then compile // into this one. Without them, they resolve from node_modules like for a consumer, so ui has to be built first. "paths": {}, - "types": [] + "types": ["@angular/localize"] }, "exclude": ["**/*.spec.ts", "**/*.stories.ts"], "extends": "../../tsconfig.json", diff --git a/projects/ngx-pwa/tsconfig.spec.json b/projects/ngx-pwa/tsconfig.spec.json index cf926c8..d1df25e 100644 --- a/projects/ngx-pwa/tsconfig.spec.json +++ b/projects/ngx-pwa/tsconfig.spec.json @@ -3,7 +3,7 @@ { "compilerOptions": { "outDir": "../../out-tsc/spec", - "types": ["vitest/globals"] + "types": ["vitest/globals", "@angular/localize"] }, "extends": "../../tsconfig.json", "include": ["**/*.d.ts", "**/*.spec.ts"] diff --git a/projects/ngx-pwa/updates/updates-config.provider.ts b/projects/ngx-pwa/updates/updates-config.provider.ts index 079f52e..6cde3ac 100644 --- a/projects/ngx-pwa/updates/updates-config.provider.ts +++ b/projects/ngx-pwa/updates/updates-config.provider.ts @@ -3,23 +3,31 @@ import { InjectionToken, Provider } from '@angular/core'; import { UpdatesConfigChanges } from './updates-config-changes.model'; import { UpdatesConfig } from './updates-config.model'; -const DEFAULT_UPDATES_CONFIG: UpdatesConfig = { - labels: { - newVersionTitle: 'New version available', - newVersionMessage: 'A new version of the app has been downloaded. Reload to use it.', - unrecoverableTitle: 'Reload needed', - unrecoverableMessage: 'Parts of this version of the app can\'t be loaded anymore. Reload to use the current version.', - reload: 'Reload', - notNow: 'Not now' - } -}; +/** + * How the user is told about a new version of the app when nothing changes it. Its texts are $localize, which an app + * translates like its own, and resolved once the config is injected, so translations an app loads at runtime apply as + * well. + * @returns The default config. + */ +function getDefaultUpdatesConfig(): UpdatesConfig { + return { + labels: { + newVersionTitle: $localize`:@@ngx-pwa.updates.newVersionTitle:New version available`, + newVersionMessage: $localize`:@@ngx-pwa.updates.newVersionMessage:A new version of the app has been downloaded. Reload to use it.`, + unrecoverableTitle: $localize`:@@ngx-pwa.updates.unrecoverableTitle:Reload needed`, + unrecoverableMessage: $localize`:@@ngx-pwa.updates.unrecoverableMessage:Parts of this version of the app can't be loaded anymore. Reload to use the current version.`, + reload: $localize`:@@ngx-pwa.updates.reload:Reload`, + notNow: $localize`:@@ngx-pwa.updates.notNow:Not now` + } + }; +} /** * How the user is told about a new version of the app. Set it with provideUpdates. */ export const UPDATES_CONFIG: InjectionToken = new InjectionToken('UPDATES_CONFIG', { providedIn: 'root', - factory: () => DEFAULT_UPDATES_CONFIG + factory: () => getDefaultUpdatesConfig() }); /** @@ -30,6 +38,9 @@ export const UPDATES_CONFIG: InjectionToken = new InjectionToken< */ export function provideUpdatesConfig(config: UpdatesConfigChanges): Provider { // no merging with a parent injector: the UpdateService lives in the root injector and never sees a config further down. - const updatesConfig: UpdatesConfig = { labels: { ...DEFAULT_UPDATES_CONFIG.labels, ...config.labels } }; - return { provide: UPDATES_CONFIG, useValue: updatesConfig }; + // A factory rather than a value, so the default texts are resolved once the config is injected, like without it. + return { + provide: UPDATES_CONFIG, + useFactory: (): UpdatesConfig => ({ labels: { ...getDefaultUpdatesConfig().labels, ...config.labels } }) + }; } \ No newline at end of file diff --git a/projects/ngx-tracking/README.md b/projects/ngx-tracking/README.md index ea7aaec..9c4eab8 100644 --- a/projects/ngx-tracking/README.md +++ b/projects/ngx-tracking/README.md @@ -13,14 +13,16 @@ Everything works with server-side rendering: on the server nothing is tracked, s - [Consent dialog](#consent-dialog) - [Embedded content](#embedded-content) - [Funnel](#funnel) +- [Translating](#translating) - [Moving from ngx-material-tracking](#moving-from-ngx-material-tracking) - [License](#license) # Requirements -Angular 22 with the router. The consent dialog, the button of the privacy settings and the funnel also need [@service-soft/ui](https://www.npmjs.com/package/@service-soft/ui) and Tailwind CSS 4. +Angular 22 with the router and `@angular/localize`, which [translates the texts](#translating). The consent dialog, the button of the privacy settings and the funnel also need [@service-soft/ui](https://www.npmjs.com/package/@service-soft/ui) and Tailwind CSS 4. ```sh npm install @service-soft/ngx-tracking @service-soft/ui +ng add @angular/localize ``` ```css @@ -142,7 +144,7 @@ Nothing that needs consent is allowed before the user pressed a button in the di # Consent dialog `ConsentDialogUi` from `@service-soft/ngx-tracking/consent-dialog` shows a modal dialog with a checkbox for every tracking, grouped by category. Escape doesn't close it: the user chooses with "Save choices", "Only required" or "Allow all", and refusing looks as prominent as allowing. Nothing changes before they press one of them. Links to your privacy policy and imprint open in a new tab, so the dialog stays. -Change its texts and links with `provideConsentDialogConfig`. Values you leave out keep their defaults, labels included: +Change its texts and links with `provideConsentDialogConfig` of `@service-soft/ngx-tracking/consent`, like to translate them. It is part of `/consent` rather than of `/consent-dialog`, so the app configures the dialog without loading it: an import of `/consent-dialog` in the application config puts the whole dialog into the first load. Values you leave out keep their defaults, labels included: ```ts provideConsentDialogConfig({ @@ -206,6 +208,9 @@ import { FunnelComponent } from '@service-soft/ngx-tracking/funnel'; The steps are a list screen readers read, and the shapes only repeat them. They are drawn in `--color-primary`. Without a heading before it, give it a `label`. +# Translating +The default texts are `$localize` with an id of their own, like `@@ngx-tracking.consent.title`, so `ng extract-i18n` puts them into the messages of your app, and you translate them like its own texts. The library needs `@angular/localize` for that, `ng add @angular/localize`, also in an app of one language. A build with `localize` fills the texts in, so no part of `@angular/localize` reaches the browser. The defaults are made once a config is injected, so translations an app loads at runtime with `loadTranslations` apply as well. A text of `provideConsentDialogConfig` or `providePrivacySettingsConfig` replaces the default in every language. So translate a default in your messages, and change it in the config only to say something else: a default the config replaces stays in your messages, though nothing shows it. + # Moving from ngx-material-tracking - The package is `@service-soft/ngx-tracking`, with an entry point each for `/consent`, `/consent-dialog`, `/custom-tracking`, `/google-analytics`, `/google-tag-manager`, `/meta-pixel` and `/funnel`. It needs `@service-soft/ui` and Tailwind instead of the Angular CDK and the Font Awesome packages. - `NGX_GDPR_TRACKINGS` and the `APP_INITIALIZER` are `provideTrackingConsent({ trackings, ui })`, which creates the services itself. `TrackingServiceClass` is `service`. `NGX_HAS_MADE_GDPR_CHOICES_DURATION_IN_MS` is `choicesDuration`, `NGX_GDPR_DNT_SETTINGS` is `respectDoNotTrack` and the `doNotTrackNotice` label. diff --git a/projects/ngx-tracking/consent-dialog/consent-dialog-config.provider.ts b/projects/ngx-tracking/consent-dialog/consent-dialog-config.provider.ts deleted file mode 100644 index 4dbc481..0000000 --- a/projects/ngx-tracking/consent-dialog/consent-dialog-config.provider.ts +++ /dev/null @@ -1,54 +0,0 @@ -import { InjectionToken, Provider } from '@angular/core'; -import { GdprCategory } from '@service-soft/ngx-tracking/consent'; - -import { ConsentDialogConfigChanges } from './consent-dialog-config-changes.model'; -import { ConsentDialogConfig } from './consent-dialog-config.model'; - -const DEFAULT_CONSENT_DIALOG_CONFIG: ConsentDialogConfig = { - paragraphs: [ - 'We use technologies like cookies to improve our website and to analyze how it is used.', - 'Choose below what you allow. You can change your choices at any time.' - ], - privacyUrl: '/privacy', - imprintUrl: '/imprint', - showOnlyCategories: false, - labels: { - title: 'Privacy settings', - allowAll: 'Allow all', - onlyRequired: 'Only required', - saveChoices: 'Save choices', - categories: { - [GdprCategory.TECHNICAL_NECESSARY]: 'Technically necessary', - [GdprCategory.ENABLED_BY_DEFAULT]: 'Analytics', - [GdprCategory.DISABLED_BY_DEFAULT]: 'Marketing' - }, - privacy: 'Privacy policy', - imprint: 'Imprint', - doNotTrackNotice: 'Your browser asked not to be tracked, so we turned off everything that isn\'t required.' - } -}; - -/** - * What the consent dialog shows. Change it with provideConsentDialogConfig. - */ -export const CONSENT_DIALOG_CONFIG: InjectionToken = new InjectionToken('CONSENT_DIALOG_CONFIG', { - providedIn: 'root', - factory: () => DEFAULT_CONSENT_DIALOG_CONFIG -}); - -/** - * Changes what the consent dialog shows, like its texts to translate them. Provide it in the application config: the - * dialog opens from the root of the app and never sees a config further down. Values you leave out keep their - * defaults, including single labels. - * @param config - The values to change. - * @returns The provider for CONSENT_DIALOG_CONFIG. - */ -export function provideConsentDialogConfig(config: ConsentDialogConfigChanges): Provider { - const defaults: ConsentDialogConfig = DEFAULT_CONSENT_DIALOG_CONFIG; - const consentDialogConfig: ConsentDialogConfig = { - ...defaults, - ...config, - labels: { ...defaults.labels, ...config.labels, categories: { ...defaults.labels.categories, ...config.labels?.categories } } - }; - return { provide: CONSENT_DIALOG_CONFIG, useValue: consentDialogConfig }; -} \ No newline at end of file diff --git a/projects/ngx-tracking/consent-dialog/consent-dialog-ui.service.ts b/projects/ngx-tracking/consent-dialog/consent-dialog-ui.service.ts index 5deaced..b4a43bd 100644 --- a/projects/ngx-tracking/consent-dialog/consent-dialog-ui.service.ts +++ b/projects/ngx-tracking/consent-dialog/consent-dialog-ui.service.ts @@ -1,10 +1,8 @@ import { inject, Service } from '@angular/core'; -import { ConsentUi } from '@service-soft/ngx-tracking/consent'; +import { CONSENT_DIALOG_CONFIG, ConsentDialogConfig, ConsentUi } from '@service-soft/ngx-tracking/consent'; import { DialogService } from '@service-soft/ui/dialog'; import { SnackbarService } from '@service-soft/ui/snackbar'; -import { ConsentDialogConfig } from './consent-dialog-config.model'; -import { CONSENT_DIALOG_CONFIG } from './consent-dialog-config.provider'; import { ConsentDialogComponent } from './consent-dialog.component'; /** diff --git a/projects/ngx-tracking/consent-dialog/consent-dialog.component.spec.ts b/projects/ngx-tracking/consent-dialog/consent-dialog.component.spec.ts index d5be71a..75763fb 100644 --- a/projects/ngx-tracking/consent-dialog/consent-dialog.component.spec.ts +++ b/projects/ngx-tracking/consent-dialog/consent-dialog.component.spec.ts @@ -2,7 +2,7 @@ import { ApplicationRef, Service } from '@angular/core'; import { TestBed } from '@angular/core/testing'; import { provideRouter } from '@angular/router'; -import { ConsentService, GdprCategory, provideTrackingConsent, Tracking, TrackingService } from '@service-soft/ngx-tracking/consent'; +import { ConsentService, GdprCategory, provideConsentDialogConfig, provideTrackingConsent, Tracking, TrackingService } from '@service-soft/ngx-tracking/consent'; import { DialogTestingUtilities } from 'testing/dialog'; import { afterEach, beforeEach, describe, expect, test } from 'vitest'; @@ -193,6 +193,20 @@ describe('ConsentDialogComponent', () => { .toEqual([false, false, true]); }); + test('shows the texts and links of the config, which the app gives it without loading the dialog', async () => { + // from /consent, which an app imports anyway, unlike the dialog, which loads once it shows + TestBed.configureTestingModule({ + providers: [provideConsentDialogConfig({ paragraphs: ['Wir nutzen Cookies.'], privacyUrl: 'datenschutz', labels: { title: 'Datenschutz' } })] + }); + await openDialog(); + + expect(document.querySelector('dialog h2')?.textContent.trim()).toBe('Datenschutz'); + expect([...document.querySelectorAll('dialog p')].map(p => p.textContent.trim())[0]).toBe('Wir nutzen Cookies.'); + expect(document.querySelector('dialog a')?.getAttribute('href')).toBe('datenschutz'); + // what it doesn't change keeps its default + expect(findButton('Allow all')).toBeDefined(); + }); + test('tells the user in a snackbar when their browser asked not to be tracked', async () => { TestBed.inject(ConsentDialogUi).showDoNotTrackNotice(); await expect.poll(() => document.querySelector('ui-snackbar')?.textContent?.trim()) diff --git a/projects/ngx-tracking/consent-dialog/consent-dialog.component.ts b/projects/ngx-tracking/consent-dialog/consent-dialog.component.ts index 41ae69d..f2960ca 100644 --- a/projects/ngx-tracking/consent-dialog/consent-dialog.component.ts +++ b/projects/ngx-tracking/consent-dialog/consent-dialog.component.ts @@ -1,13 +1,11 @@ import { Component, computed, inject, Signal, signal, WritableSignal } from '@angular/core'; -import { ConsentService, GdprCategory, Tracking } from '@service-soft/ngx-tracking/consent'; +import { CONSENT_DIALOG_CONFIG, ConsentDialogConfig, ConsentDialogLabels, ConsentService, GdprCategory, Tracking } from '@service-soft/ngx-tracking/consent'; import { ButtonComponent } from '@service-soft/ui/button'; import { DialogRef } from '@service-soft/ui/dialog'; import { FormComponent } from '@service-soft/ui/form'; import { ConsentCategoryView } from './consent-category-view.model'; import { ConsentCategoryComponent } from './consent-category.component'; -import { ConsentDialogConfig, ConsentDialogLabels } from './consent-dialog-config.model'; -import { CONSENT_DIALOG_CONFIG } from './consent-dialog-config.provider'; // the order the categories show in: what can't be changed first, then what is checked at first. const CATEGORIES: GdprCategory[] = [GdprCategory.TECHNICAL_NECESSARY, GdprCategory.ENABLED_BY_DEFAULT, GdprCategory.DISABLED_BY_DEFAULT]; diff --git a/projects/ngx-tracking/consent-dialog/consent-dialog.stories.ts b/projects/ngx-tracking/consent-dialog/consent-dialog.stories.ts index aca8a3e..c7e994a 100644 --- a/projects/ngx-tracking/consent-dialog/consent-dialog.stories.ts +++ b/projects/ngx-tracking/consent-dialog/consent-dialog.stories.ts @@ -1,10 +1,9 @@ import { afterNextRender, Component, inject, Service } from '@angular/core'; import { provideRouter } from '@angular/router'; -import { ConsentService, GdprCategory, provideTrackingConsent, Tracking, TrackingService } from '@service-soft/ngx-tracking/consent'; +import { ConsentService, GdprCategory, provideConsentDialogConfig, provideTrackingConsent, Tracking, TrackingService } from '@service-soft/ngx-tracking/consent'; import { PrivacySettingsComponent } from '@service-soft/ngx-tracking/privacy-settings'; import { applicationConfig, Meta, StoryObj } from '@storybook/angular'; -import { provideConsentDialogConfig } from './consent-dialog-config.provider'; import { ConsentDialogUi } from './consent-dialog-ui.service'; import { ConsentDialogComponent } from './consent-dialog.component'; diff --git a/projects/ngx-tracking/consent-dialog/public-api.ts b/projects/ngx-tracking/consent-dialog/public-api.ts index 3958989..770681c 100644 --- a/projects/ngx-tracking/consent-dialog/public-api.ts +++ b/projects/ngx-tracking/consent-dialog/public-api.ts @@ -1,5 +1,2 @@ -export * from './consent-dialog-config-changes.model'; -export * from './consent-dialog-config.model'; -export * from './consent-dialog-config.provider'; export * from './consent-dialog-ui.service'; export * from './consent-dialog.component'; \ No newline at end of file diff --git a/projects/ngx-tracking/consent-dialog/consent-dialog-config-changes.model.ts b/projects/ngx-tracking/consent/consent-dialog-config-changes.model.ts similarity index 100% rename from projects/ngx-tracking/consent-dialog/consent-dialog-config-changes.model.ts rename to projects/ngx-tracking/consent/consent-dialog-config-changes.model.ts diff --git a/projects/ngx-tracking/consent-dialog/consent-dialog-config.model.ts b/projects/ngx-tracking/consent/consent-dialog-config.model.ts similarity index 95% rename from projects/ngx-tracking/consent-dialog/consent-dialog-config.model.ts rename to projects/ngx-tracking/consent/consent-dialog-config.model.ts index 2f83004..d9f88bb 100644 --- a/projects/ngx-tracking/consent-dialog/consent-dialog-config.model.ts +++ b/projects/ngx-tracking/consent/consent-dialog-config.model.ts @@ -1,4 +1,4 @@ -import { GdprCategory } from '@service-soft/ngx-tracking/consent'; +import { GdprCategory } from './gdpr-category.enum'; /** * The texts of the consent dialog, to translate them. diff --git a/projects/ngx-tracking/consent/consent-dialog-config.provider.ts b/projects/ngx-tracking/consent/consent-dialog-config.provider.ts new file mode 100644 index 0000000..9a691a3 --- /dev/null +++ b/projects/ngx-tracking/consent/consent-dialog-config.provider.ts @@ -0,0 +1,73 @@ +import { InjectionToken, Provider } from '@angular/core'; + +import { ConsentDialogConfigChanges } from './consent-dialog-config-changes.model'; +import { ConsentDialogConfig } from './consent-dialog-config.model'; +import { GdprCategory } from './gdpr-category.enum'; + +/** + * What the consent dialog shows when nothing changes it. Its texts are $localize, which an app translates like its + * own, and resolved once the config is injected, so translations an app loads at runtime apply as well. + * @returns The default config. + */ +function getDefaultConsentDialogConfig(): ConsentDialogConfig { + return { + paragraphs: [ + $localize`:@@ngx-tracking.consent.paragraphs.purpose:We use technologies like cookies to improve our website and to analyze how it is used.`, + $localize`:@@ngx-tracking.consent.paragraphs.choices:Choose below what you allow. You can change your choices at any time.` + ], + privacyUrl: '/privacy', + imprintUrl: '/imprint', + showOnlyCategories: false, + labels: { + title: $localize`:@@ngx-tracking.consent.title:Privacy settings`, + allowAll: $localize`:@@ngx-tracking.consent.allowAll:Allow all`, + onlyRequired: $localize`:@@ngx-tracking.consent.onlyRequired:Only required`, + saveChoices: $localize`:@@ngx-tracking.consent.saveChoices:Save choices`, + categories: { + [GdprCategory.TECHNICAL_NECESSARY]: $localize`:@@ngx-tracking.consent.categories.technicallyNecessary:Technically necessary`, + [GdprCategory.ENABLED_BY_DEFAULT]: $localize`:@@ngx-tracking.consent.categories.analytics:Analytics`, + [GdprCategory.DISABLED_BY_DEFAULT]: $localize`:@@ngx-tracking.consent.categories.marketing:Marketing` + }, + privacy: $localize`:@@ngx-tracking.consent.privacy:Privacy policy`, + imprint: $localize`:@@ngx-tracking.consent.imprint:Imprint`, + doNotTrackNotice: $localize`:@@ngx-tracking.consent.doNotTrackNotice:Your browser asked not to be tracked, so we turned off everything that isn't required.` + } + }; +} + +/** + * What the consent dialog of `@service-soft/ngx-tracking/consent-dialog` shows. Change it with + * provideConsentDialogConfig. + */ +export const CONSENT_DIALOG_CONFIG: InjectionToken = new InjectionToken('CONSENT_DIALOG_CONFIG', { + providedIn: 'root', + factory: () => getDefaultConsentDialogConfig() +}); + +/** + * Changes what the consent dialog shows, like its texts to translate them. Provide it in the application config: the + * dialog opens from the root of the app and never sees a config further down. Values you leave out keep their + * defaults, including single labels. It is part of this entry point rather than of the dialog's, so that the app + * configures the dialog without loading it before it shows. + * @param config - The values to change. + * @returns The provider for CONSENT_DIALOG_CONFIG. + */ +export function provideConsentDialogConfig(config: ConsentDialogConfigChanges): Provider { + return { + provide: CONSENT_DIALOG_CONFIG, + // a factory rather than a value: the apps call this while their config is built, which can be before they load + // the translations of the defaults at runtime. + useFactory: (): ConsentDialogConfig => { + const defaults: ConsentDialogConfig = getDefaultConsentDialogConfig(); + return { + ...defaults, + ...config, + labels: { + ...defaults.labels, + ...config.labels, + categories: { ...defaults.labels.categories, ...config.labels?.categories } + } + }; + } + }; +} \ No newline at end of file diff --git a/projects/ngx-tracking/consent/public-api.ts b/projects/ngx-tracking/consent/public-api.ts index 362f61e..d09d3e8 100644 --- a/projects/ngx-tracking/consent/public-api.ts +++ b/projects/ngx-tracking/consent/public-api.ts @@ -2,6 +2,9 @@ export * from './consent-ask-on.type'; export * from './consent-config-changes.model'; export * from './consent-config.model'; export * from './consent-config.provider'; +export * from './consent-dialog-config-changes.model'; +export * from './consent-dialog-config.model'; +export * from './consent-dialog-config.provider'; export * from './consent-ui.service'; export * from './consent.guard'; export * from './consent.service'; diff --git a/projects/ngx-tracking/package.json b/projects/ngx-tracking/package.json index 03c70ae..cb59ffc 100644 --- a/projects/ngx-tracking/package.json +++ b/projects/ngx-tracking/package.json @@ -1,6 +1,6 @@ { "name": "@service-soft/ngx-tracking", - "version": "22.3.0", + "version": "22.3.1", "license": "MIT", "repository": { "type": "git", @@ -21,9 +21,10 @@ "peerDependencies": { "@angular/common": "^22.2.0", "@angular/core": "^22.2.0", + "@angular/localize": "^22.2.0", "@angular/router": "^22.2.0", "@fortawesome/free-solid-svg-icons": "^7.3.1", - "@service-soft/ui": "^22.3.0", + "@service-soft/ui": "^22.3.1", "tailwindcss": "^4.3.3" }, "peerDependenciesMeta": { diff --git a/projects/ngx-tracking/privacy-settings/privacy-settings-config.provider.ts b/projects/ngx-tracking/privacy-settings/privacy-settings-config.provider.ts index 6f0381a..436998e 100644 --- a/projects/ngx-tracking/privacy-settings/privacy-settings-config.provider.ts +++ b/projects/ngx-tracking/privacy-settings/privacy-settings-config.provider.ts @@ -2,10 +2,18 @@ import { inject, InjectionToken, Provider } from '@angular/core'; import { PrivacySettingsConfig } from './privacy-settings-config.model'; -const DEFAULT_PRIVACY_SETTINGS_CONFIG: PrivacySettingsConfig = { - color: 'secondary', - label: 'Privacy settings' -}; +/** + * The values of the button that opens the privacy settings when nothing changes them. Its label is $localize, which an + * app translates like its own texts, and resolved once the config is injected, so translations an app loads at runtime + * apply as well. + * @returns The default config. + */ +function getDefaultPrivacySettingsConfig(): PrivacySettingsConfig { + return { + color: 'secondary', + label: $localize`:@@ngx-tracking.privacy-settings.label:Privacy settings` + }; +} /** * The values every button below this injector that opens the privacy settings uses when its inputs are not set, and @@ -15,7 +23,7 @@ export const PRIVACY_SETTINGS_CONFIG: InjectionToken = ne 'PRIVACY_SETTINGS_CONFIG', { providedIn: 'root', - factory: () => DEFAULT_PRIVACY_SETTINGS_CONFIG + factory: () => getDefaultPrivacySettingsConfig() } ); @@ -30,7 +38,7 @@ export function providePrivacySettingsConfig(config: Partial ({ - ...inject(PRIVACY_SETTINGS_CONFIG, { skipSelf: true, optional: true }) ?? DEFAULT_PRIVACY_SETTINGS_CONFIG, + ...inject(PRIVACY_SETTINGS_CONFIG, { skipSelf: true, optional: true }) ?? getDefaultPrivacySettingsConfig(), ...config }) }; diff --git a/projects/ngx-tracking/tsconfig.lib.json b/projects/ngx-tracking/tsconfig.lib.json index 5ed1187..5315f63 100644 --- a/projects/ngx-tracking/tsconfig.lib.json +++ b/projects/ngx-tracking/tsconfig.lib.json @@ -8,7 +8,7 @@ // the paths of the workspace point to the sources of the other libraries, which the build would then compile // into this one. Without them, they resolve from node_modules like for a consumer, so ui has to be built first. "paths": {}, - "types": [] + "types": ["@angular/localize"] }, "exclude": ["**/*.spec.ts", "**/*.stories.ts"], "extends": "../../tsconfig.json", diff --git a/projects/ngx-tracking/tsconfig.spec.json b/projects/ngx-tracking/tsconfig.spec.json index cf926c8..d1df25e 100644 --- a/projects/ngx-tracking/tsconfig.spec.json +++ b/projects/ngx-tracking/tsconfig.spec.json @@ -3,7 +3,7 @@ { "compilerOptions": { "outDir": "../../out-tsc/spec", - "types": ["vitest/globals"] + "types": ["vitest/globals", "@angular/localize"] }, "extends": "../../tsconfig.json", "include": ["**/*.d.ts", "**/*.spec.ts"] diff --git a/projects/showcase/tsconfig.app.json b/projects/showcase/tsconfig.app.json index bb928b1..366f4bf 100644 --- a/projects/showcase/tsconfig.app.json +++ b/projects/showcase/tsconfig.app.json @@ -4,7 +4,7 @@ "compilerOptions": { // the showcase consumes the built libraries from node_modules, exactly like an external project. "paths": {}, - "types": [] + "types": ["@angular/localize"] }, "exclude": ["src/**/*.spec.ts"], "extends": "../../tsconfig.json", diff --git a/projects/ui/.storybook/preview.ts b/projects/ui/.storybook/preview.ts index 1db3adc..cdb0f28 100644 --- a/projects/ui/.storybook/preview.ts +++ b/projects/ui/.storybook/preview.ts @@ -1,3 +1,5 @@ +// the default texts of the libraries are $localize, which an app defines with this polyfill +import '@angular/localize/init'; import { Preview } from '@storybook/angular'; import { PAGE_LEVEL_RULES } from './page-level-rules'; diff --git a/projects/ui/.storybook/tsconfig.json b/projects/ui/.storybook/tsconfig.json index 1a0d2cd..a45fa08 100644 --- a/projects/ui/.storybook/tsconfig.json +++ b/projects/ui/.storybook/tsconfig.json @@ -1,6 +1,6 @@ { "compilerOptions": { - "types": ["node"] + "types": ["node", "@angular/localize"] }, "exclude": ["../**/*.spec.ts", "../../ngx-change-sets/**/*.spec.ts", "../../ngx-persistence-logger/**/*.spec.ts", "../../ngx-tracking/**/*.spec.ts", "../../ngx-pwa/**/*.spec.ts", "../../ngx-auth/**/*.spec.ts", "../../ngx-error-handling/**/*.spec.ts", "../../ngx-navigation/**/*.spec.ts", "../../ngx-entity/**/*.spec.ts", "../../ngx-ecommerce/**/*.spec.ts", "../../testing/**/*.spec.ts"], "extends": "../tsconfig.lib.json", diff --git a/projects/ui/README.md b/projects/ui/README.md index 1198940..5f0d8aa 100644 --- a/projects/ui/README.md +++ b/projects/ui/README.md @@ -11,6 +11,7 @@ Every component lives in its own entry point, so a project only ships the code o - [Theming](#theming) - [Colored surfaces](#colored-surfaces) - [Dark mode](#dark-mode) + - [Translating](#translating) - [Components](#components) - [Button](#button) - [Input string](#input-string) @@ -93,10 +94,11 @@ Every component lives in its own entry point, so a project only ships the code o - [License](#license) # Usage -It requires Angular 22 and Tailwind CSS 4: +It requires Angular 22 with `@angular/localize`, which [translates the texts](#translating), and Tailwind CSS 4: ```sh npm install @service-soft/ui +ng add @angular/localize ``` The icons it draws itself, like the one that shows a password, come from `@fortawesome/free-solid-svg-icons`, a peer dependency npm installs with it. Your app and every library share that one copy, and only the icons that are imported end up in the bundle. @@ -193,6 +195,9 @@ Use the surface on your `body`, so the page background switches with the compone Tailwind's `dark:` variant follows the same rules. You rarely need it, since the tokens switch by themselves. +## Translating +The default texts are `$localize` with an id of their own, like `@@ui.table.selectAllLabel`, so `ng extract-i18n` puts them into the messages of your app, and you translate them like its own texts. The library needs `@angular/localize` for that, `ng add @angular/localize`, also in an app of one language. A build with `localize` fills the texts in, so no part of `@angular/localize` reaches the browser. The defaults are made once a config is injected, so translations an app loads at runtime with `loadTranslations` apply as well. A text of `provideXConfig` replaces the default in every language. So translate a default in your messages, and change it in the config only to say something else: a default the config replaces stays in your messages, though nothing shows it. + # Components Every input of a component has a default you can change for the whole app, or for only a part of it, with its `provideXConfig` function. Values you leave out keep the defaults of the parent. diff --git a/projects/ui/address/address-config.provider.ts b/projects/ui/address/address-config.provider.ts index 05f4e5e..a455c31 100644 --- a/projects/ui/address/address-config.provider.ts +++ b/projects/ui/address/address-config.provider.ts @@ -2,14 +2,21 @@ import { inject, InjectionToken, Provider } from '@angular/core'; import { AddressConfig } from './address-config.model'; -const DEFAULT_ADDRESS_CONFIG: AddressConfig = { - icons: true, - microdata: true, - businessType: 'LocalBusiness', - phoneLabel: 'Phone', - faxLabel: 'Fax', - emailLabel: 'Email' -}; +/** + * The values of an address block when nothing changes them. Its texts are $localize, which an app translates like its + * own, and resolved once the config is injected, so translations an app loads at runtime apply as well. + * @returns The default config. + */ +function getDefaultAddressConfig(): AddressConfig { + return { + icons: true, + microdata: true, + businessType: 'LocalBusiness', + phoneLabel: $localize`:@@ui.address.phoneLabel:Phone`, + faxLabel: $localize`:@@ui.address.faxLabel:Fax`, + emailLabel: $localize`:@@ui.address.emailLabel:Email` + }; +} /** * The values every address block below this injector uses when its inputs are not set, and its texts. @@ -17,7 +24,7 @@ const DEFAULT_ADDRESS_CONFIG: AddressConfig = { */ export const ADDRESS_CONFIG: InjectionToken = new InjectionToken('ADDRESS_CONFIG', { providedIn: 'root', - factory: () => DEFAULT_ADDRESS_CONFIG + factory: () => getDefaultAddressConfig() }); /** @@ -31,7 +38,7 @@ export function provideAddressConfig(config: Partial): Provider { return { provide: ADDRESS_CONFIG, useFactory: (): AddressConfig => ({ - ...inject(ADDRESS_CONFIG, { skipSelf: true, optional: true }) ?? DEFAULT_ADDRESS_CONFIG, + ...inject(ADDRESS_CONFIG, { skipSelf: true, optional: true }) ?? getDefaultAddressConfig(), ...config }) }; diff --git a/projects/ui/back-to-top/back-to-top-config.provider.ts b/projects/ui/back-to-top/back-to-top-config.provider.ts index 5d4fb8c..f0fa3c0 100644 --- a/projects/ui/back-to-top/back-to-top-config.provider.ts +++ b/projects/ui/back-to-top/back-to-top-config.provider.ts @@ -2,10 +2,18 @@ import { inject, InjectionToken, Provider } from '@angular/core'; import { BackToTopConfig } from './back-to-top-config.model'; -const DEFAULT_BACK_TO_TOP_CONFIG: BackToTopConfig = { - color: 'secondary', - label: 'Back to top' -}; +/** + * The values of the button that goes back to the top of the page when nothing changes them. Its label is $localize, + * which an app translates like its own texts, and resolved once the config is injected, so translations an app loads at + * runtime apply as well. + * @returns The default config. + */ +function getDefaultBackToTopConfig(): BackToTopConfig { + return { + color: 'secondary', + label: $localize`:@@ui.back-to-top.label:Back to top` + }; +} /** * The values every button below this injector that goes back to the top of the page uses when its inputs are not set, @@ -13,7 +21,7 @@ const DEFAULT_BACK_TO_TOP_CONFIG: BackToTopConfig = { */ export const BACK_TO_TOP_CONFIG: InjectionToken = new InjectionToken('BACK_TO_TOP_CONFIG', { providedIn: 'root', - factory: () => DEFAULT_BACK_TO_TOP_CONFIG + factory: () => getDefaultBackToTopConfig() }); /** @@ -28,7 +36,7 @@ export function provideBackToTopConfig(config: Partial): Provid return { provide: BACK_TO_TOP_CONFIG, useFactory: (): BackToTopConfig => ({ - ...inject(BACK_TO_TOP_CONFIG, { skipSelf: true, optional: true }) ?? DEFAULT_BACK_TO_TOP_CONFIG, + ...inject(BACK_TO_TOP_CONFIG, { skipSelf: true, optional: true }) ?? getDefaultBackToTopConfig(), ...config }) }; diff --git a/projects/ui/breadcrumbs/breadcrumbs-config.provider.ts b/projects/ui/breadcrumbs/breadcrumbs-config.provider.ts index 30b92ab..1128dc8 100644 --- a/projects/ui/breadcrumbs/breadcrumbs-config.provider.ts +++ b/projects/ui/breadcrumbs/breadcrumbs-config.provider.ts @@ -2,9 +2,16 @@ import { inject, InjectionToken, Provider } from '@angular/core'; import { BreadcrumbsConfig } from './breadcrumbs-config.model'; -const DEFAULT_BREADCRUMBS_CONFIG: BreadcrumbsConfig = { - label: 'Breadcrumbs' -}; +/** + * The values of breadcrumbs when nothing changes them. Its label is $localize, which an app translates like its own + * texts, and resolved once the config is injected, so translations an app loads at runtime apply as well. + * @returns The default config. + */ +function getDefaultBreadcrumbsConfig(): BreadcrumbsConfig { + return { + label: $localize`:@@ui.breadcrumbs.label:Breadcrumbs` + }; +} /** * The values all breadcrumbs below this injector use when their inputs are not set. @@ -12,7 +19,7 @@ const DEFAULT_BREADCRUMBS_CONFIG: BreadcrumbsConfig = { */ export const BREADCRUMBS_CONFIG: InjectionToken = new InjectionToken('BREADCRUMBS_CONFIG', { providedIn: 'root', - factory: () => DEFAULT_BREADCRUMBS_CONFIG + factory: () => getDefaultBreadcrumbsConfig() }); /** @@ -26,7 +33,7 @@ export function provideBreadcrumbsConfig(config: Partial): Pr return { provide: BREADCRUMBS_CONFIG, useFactory: (): BreadcrumbsConfig => ({ - ...inject(BREADCRUMBS_CONFIG, { skipSelf: true, optional: true }) ?? DEFAULT_BREADCRUMBS_CONFIG, + ...inject(BREADCRUMBS_CONFIG, { skipSelf: true, optional: true }) ?? getDefaultBreadcrumbsConfig(), ...config }) }; diff --git a/projects/ui/byline/byline-config.provider.ts b/projects/ui/byline/byline-config.provider.ts index 8a0a470..ae2fad2 100644 --- a/projects/ui/byline/byline-config.provider.ts +++ b/projects/ui/byline/byline-config.provider.ts @@ -2,11 +2,18 @@ import { inject, InjectionToken, Provider } from '@angular/core'; import { BylineConfig } from './byline-config.model'; -const DEFAULT_BYLINE_CONFIG: BylineConfig = { - showAvatar: false, - dateFormat: { dateStyle: 'medium' }, - readingTimeLabel: minutes => `${minutes} min read` -}; +/** + * The values of a byline when nothing changes them. Its text of the reading time is $localize, which an app translates + * like its own texts, and resolved once the config is injected, so translations an app loads at runtime apply as well. + * @returns The default config. + */ +function getDefaultBylineConfig(): BylineConfig { + return { + showAvatar: false, + dateFormat: { dateStyle: 'medium' }, + readingTimeLabel: minutes => $localize`:@@ui.byline.readingTimeLabel:${minutes}:minutes: min read` + }; +} /** * The values every byline below this injector uses when its inputs are not set. @@ -14,7 +21,7 @@ const DEFAULT_BYLINE_CONFIG: BylineConfig = { */ export const BYLINE_CONFIG: InjectionToken = new InjectionToken('BYLINE_CONFIG', { providedIn: 'root', - factory: () => DEFAULT_BYLINE_CONFIG + factory: () => getDefaultBylineConfig() }); /** @@ -28,7 +35,7 @@ export function provideBylineConfig(config: Partial): Provider { return { provide: BYLINE_CONFIG, useFactory: (): BylineConfig => ({ - ...inject(BYLINE_CONFIG, { skipSelf: true, optional: true }) ?? DEFAULT_BYLINE_CONFIG, + ...inject(BYLINE_CONFIG, { skipSelf: true, optional: true }) ?? getDefaultBylineConfig(), ...config }) }; diff --git a/projects/ui/callout/callout-config.provider.ts b/projects/ui/callout/callout-config.provider.ts index 2dc6167..c335ebf 100644 --- a/projects/ui/callout/callout-config.provider.ts +++ b/projects/ui/callout/callout-config.provider.ts @@ -3,25 +3,32 @@ import { faCircleCheck, faCircleExclamation, faCircleInfo, faLightbulb, faStar, import { CalloutConfig } from './callout-config.model'; -const DEFAULT_CALLOUT_CONFIG: CalloutConfig = { - tone: 'info', - icons: { - neutral: faLightbulb, - info: faCircleInfo, - success: faCircleCheck, - warning: faTriangleExclamation, - error: faCircleExclamation, - promo: faStar - }, - toneLabels: { - neutral: undefined, - info: 'Information', - success: 'Success', - warning: 'Warning', - error: 'Error', - promo: undefined - } -}; +/** + * The values of a callout when nothing changes them. Its texts are $localize, which an app translates like its own, and + * resolved once the config is injected, so translations an app loads at runtime apply as well. + * @returns The default config. + */ +function getDefaultCalloutConfig(): CalloutConfig { + return { + tone: 'info', + icons: { + neutral: faLightbulb, + info: faCircleInfo, + success: faCircleCheck, + warning: faTriangleExclamation, + error: faCircleExclamation, + promo: faStar + }, + toneLabels: { + neutral: undefined, + info: $localize`:@@ui.callout.toneLabels.info:Information`, + success: $localize`:@@ui.callout.toneLabels.success:Success`, + warning: $localize`:@@ui.callout.toneLabels.warning:Warning`, + error: $localize`:@@ui.callout.toneLabels.error:Error`, + promo: undefined + } + }; +} /** * The values every callout below this injector uses when its inputs are not set. @@ -29,7 +36,7 @@ const DEFAULT_CALLOUT_CONFIG: CalloutConfig = { */ export const CALLOUT_CONFIG: InjectionToken = new InjectionToken('CALLOUT_CONFIG', { providedIn: 'root', - factory: () => DEFAULT_CALLOUT_CONFIG + factory: () => getDefaultCalloutConfig() }); /** @@ -44,7 +51,7 @@ export function provideCalloutConfig(config: Partial): Provider { return { provide: CALLOUT_CONFIG, useFactory: (): CalloutConfig => ({ - ...inject(CALLOUT_CONFIG, { skipSelf: true, optional: true }) ?? DEFAULT_CALLOUT_CONFIG, + ...inject(CALLOUT_CONFIG, { skipSelf: true, optional: true }) ?? getDefaultCalloutConfig(), ...config }) }; diff --git a/projects/ui/check-list/check-list-config.provider.ts b/projects/ui/check-list/check-list-config.provider.ts index d318650..a905584 100644 --- a/projects/ui/check-list/check-list-config.provider.ts +++ b/projects/ui/check-list/check-list-config.provider.ts @@ -3,12 +3,20 @@ import { faCheck, faXmark } from '@fortawesome/free-solid-svg-icons'; import { CheckListConfig } from './check-list-config.model'; -const DEFAULT_CHECK_LIST_CONFIG: CheckListConfig = { - color: 'primary', - icon: faCheck, - excludedIcon: faXmark, - excludedLabel: 'not included' -}; +/** + * The values of a check list when nothing changes them. Its text for an item that is not included is $localize, which + * an app translates like its own texts, and resolved once the config is injected, so translations an app loads at + * runtime apply as well. + * @returns The default config. + */ +function getDefaultCheckListConfig(): CheckListConfig { + return { + color: 'primary', + icon: faCheck, + excludedIcon: faXmark, + excludedLabel: $localize`:@@ui.check-list.excludedLabel:not included` + }; +} /** * The values every check list below this injector uses when its inputs are not set. @@ -16,7 +24,7 @@ const DEFAULT_CHECK_LIST_CONFIG: CheckListConfig = { */ export const CHECK_LIST_CONFIG: InjectionToken = new InjectionToken('CHECK_LIST_CONFIG', { providedIn: 'root', - factory: () => DEFAULT_CHECK_LIST_CONFIG + factory: () => getDefaultCheckListConfig() }); /** @@ -31,7 +39,7 @@ export function provideCheckListConfig(config: Partial): Provid return { provide: CHECK_LIST_CONFIG, useFactory: (): CheckListConfig => ({ - ...inject(CHECK_LIST_CONFIG, { skipSelf: true, optional: true }) ?? DEFAULT_CHECK_LIST_CONFIG, + ...inject(CHECK_LIST_CONFIG, { skipSelf: true, optional: true }) ?? getDefaultCheckListConfig(), ...config }) }; diff --git a/projects/ui/consent-gate/consent-gate-config.provider.ts b/projects/ui/consent-gate/consent-gate-config.provider.ts index 33f9b90..b6d103c 100644 --- a/projects/ui/consent-gate/consent-gate-config.provider.ts +++ b/projects/ui/consent-gate/consent-gate-config.provider.ts @@ -2,18 +2,24 @@ import { inject, InjectionToken, Provider } from '@angular/core'; import { ConsentGateConfig } from './consent-gate-config.model'; -const DEFAULT_CONSENT_GATE_CONFIG: ConsentGateConfig = { - privacyPolicyUrl: undefined, - alwaysAllow: false, - aspectRatio: undefined, - title: provider => `Content from ${provider}`, - description: provider => `To show it, your browser loads it from ${provider}, which receives data like your IP address ` - + 'and may set cookies.', - privacyPolicyLabel: 'Privacy policy', - providerPrivacyPolicyLabel: provider => `Privacy policy of ${provider}`, - loadLabel: provider => `Load ${provider}`, - alwaysAllowLabel: provider => `Always allow ${provider}` -}; +/** + * The values of a consent gate when nothing changes them. Its texts are $localize, which an app translates like its + * own, and resolved once the config is injected, so translations an app loads at runtime apply as well. + * @returns The default config. + */ +function getDefaultConsentGateConfig(): ConsentGateConfig { + return { + privacyPolicyUrl: undefined, + alwaysAllow: false, + aspectRatio: undefined, + title: provider => $localize`:@@ui.consent-gate.title:Content from ${provider}:provider:`, + description: provider => $localize`:@@ui.consent-gate.description:To show it, your browser loads it from ${provider}:provider:, which receives data like your IP address and may set cookies.`, + privacyPolicyLabel: $localize`:@@ui.consent-gate.privacyPolicyLabel:Privacy policy`, + providerPrivacyPolicyLabel: provider => $localize`:@@ui.consent-gate.providerPrivacyPolicyLabel:Privacy policy of ${provider}:provider:`, + loadLabel: provider => $localize`:@@ui.consent-gate.loadLabel:Load ${provider}:provider:`, + alwaysAllowLabel: provider => $localize`:@@ui.consent-gate.alwaysAllowLabel:Always allow ${provider}:provider:` + }; +} /** * The values every consent gate below this injector uses when its inputs are not set, and its texts. @@ -21,7 +27,7 @@ const DEFAULT_CONSENT_GATE_CONFIG: ConsentGateConfig = { */ export const CONSENT_GATE_CONFIG: InjectionToken = new InjectionToken('CONSENT_GATE_CONFIG', { providedIn: 'root', - factory: () => DEFAULT_CONSENT_GATE_CONFIG + factory: () => getDefaultConsentGateConfig() }); /** @@ -35,7 +41,7 @@ export function provideConsentGateConfig(config: Partial): Pr return { provide: CONSENT_GATE_CONFIG, useFactory: (): ConsentGateConfig => ({ - ...inject(CONSENT_GATE_CONFIG, { skipSelf: true, optional: true }) ?? DEFAULT_CONSENT_GATE_CONFIG, + ...inject(CONSENT_GATE_CONFIG, { skipSelf: true, optional: true }) ?? getDefaultConsentGateConfig(), ...config }) }; diff --git a/projects/ui/date-period/date-period-config.provider.ts b/projects/ui/date-period/date-period-config.provider.ts index 0d51d0a..cfe5b2b 100644 --- a/projects/ui/date-period/date-period-config.provider.ts +++ b/projects/ui/date-period/date-period-config.provider.ts @@ -2,12 +2,20 @@ import { inject, InjectionToken, Provider } from '@angular/core'; import { DatePeriodConfig } from './date-period-config.model'; -const DEFAULT_DATE_PERIOD_CONFIG: DatePeriodConfig = { - format: { month: '2-digit', year: 'numeric' }, - openEndLabel: 'today', - // an en dash, which stands for "to" in a range of dates - separator: ' – ' -}; +/** + * The values of a date period when nothing changes them. Its text for a period without an end is $localize, which an + * app translates like its own texts, and resolved once the config is injected, so translations an app loads at runtime + * apply as well. + * @returns The default config. + */ +function getDefaultDatePeriodConfig(): DatePeriodConfig { + return { + format: { month: '2-digit', year: 'numeric' }, + openEndLabel: $localize`:@@ui.date-period.openEndLabel:today`, + // an en dash, which stands for "to" in a range of dates + separator: ' – ' + }; +} /** * The values every date period below this injector uses when its inputs or the arguments of its pipe are not set. @@ -15,7 +23,7 @@ const DEFAULT_DATE_PERIOD_CONFIG: DatePeriodConfig = { */ export const DATE_PERIOD_CONFIG: InjectionToken = new InjectionToken('DATE_PERIOD_CONFIG', { providedIn: 'root', - factory: () => DEFAULT_DATE_PERIOD_CONFIG + factory: () => getDefaultDatePeriodConfig() }); /** @@ -30,7 +38,7 @@ export function provideDatePeriodConfig(config: Partial): Prov return { provide: DATE_PERIOD_CONFIG, useFactory: (): DatePeriodConfig => ({ - ...inject(DATE_PERIOD_CONFIG, { skipSelf: true, optional: true }) ?? DEFAULT_DATE_PERIOD_CONFIG, + ...inject(DATE_PERIOD_CONFIG, { skipSelf: true, optional: true }) ?? getDefaultDatePeriodConfig(), ...config }) }; diff --git a/projects/ui/drawer/drawer-config.provider.ts b/projects/ui/drawer/drawer-config.provider.ts index 6786ab8..33741d0 100644 --- a/projects/ui/drawer/drawer-config.provider.ts +++ b/projects/ui/drawer/drawer-config.provider.ts @@ -2,12 +2,19 @@ import { inject, InjectionToken, Provider } from '@angular/core'; import { DrawerConfig } from './drawer-config.model'; -const DEFAULT_DRAWER_CONFIG: DrawerConfig = { - side: 'start', - color: 'surface', - header: false, - closeLabel: 'Close' -}; +/** + * The values of a drawer when nothing changes them. Its label of the close button is $localize, which an app translates + * like its own texts, and resolved once the config is injected, so translations an app loads at runtime apply as well. + * @returns The default config. + */ +function getDefaultDrawerConfig(): DrawerConfig { + return { + side: 'start', + color: 'surface', + header: false, + closeLabel: $localize`:@@ui.drawer.closeLabel:Close` + }; +} /** * The values every drawer below this injector uses when its inputs are not set. @@ -15,7 +22,7 @@ const DEFAULT_DRAWER_CONFIG: DrawerConfig = { */ export const DRAWER_CONFIG: InjectionToken = new InjectionToken('DRAWER_CONFIG', { providedIn: 'root', - factory: () => DEFAULT_DRAWER_CONFIG + factory: () => getDefaultDrawerConfig() }); /** @@ -29,7 +36,7 @@ export function provideDrawerConfig(config: Partial): Provider { return { provide: DRAWER_CONFIG, useFactory: (): DrawerConfig => ({ - ...inject(DRAWER_CONFIG, { skipSelf: true, optional: true }) ?? DEFAULT_DRAWER_CONFIG, + ...inject(DRAWER_CONFIG, { skipSelf: true, optional: true }) ?? getDefaultDrawerConfig(), ...config }) }; diff --git a/projects/ui/event-calendar/event-calendar-config.provider.ts b/projects/ui/event-calendar/event-calendar-config.provider.ts index c7b4692..28fc5e9 100644 --- a/projects/ui/event-calendar/event-calendar-config.provider.ts +++ b/projects/ui/event-calendar/event-calendar-config.provider.ts @@ -2,28 +2,43 @@ import { inject, InjectionToken, Provider } from '@angular/core'; import { EventCalendarConfig } from './event-calendar-config.model'; -const DEFAULT_EVENT_CALENDAR_CONFIG: EventCalendarConfig = { - view: 'month', - color: 'primary', - headerColor: 'primary', - // Monday, as in ISO 8601 and like the calendar of a date input. - firstDayOfWeek: 1, - maxEventsPerDay: 2, - todayLabel: 'Today', - previousMonthLabel: 'Previous month', - nextMonthLabel: 'Next month', - viewLabel: 'View', - monthViewLabel: 'Month', - agendaViewLabel: 'List', - allDayLabel: 'All day', - locationLabel: 'Location', - linkLabel: 'Details', - addToCalendarLabel: 'Add to calendar', - noEventsLabel: 'No events this month.', - noEventsOnDayLabel: 'No events on this day.', - moreEventsLabel: count => `+${count} more`, - eventCountLabel: count => count === 1 ? '1 event' : `${count === 0 ? 'no' : count} events` -}; +/** + * The values of an event calendar when nothing changes them. Its texts are $localize, which an app translates like its + * own, and resolved once the config is injected, so translations an app loads at runtime apply as well. + * @returns The default config. + */ +function getDefaultEventCalendarConfig(): EventCalendarConfig { + return { + view: 'month', + color: 'primary', + headerColor: 'primary', + // Monday, as in ISO 8601 and like the calendar of a date input. + firstDayOfWeek: 1, + maxEventsPerDay: 2, + todayLabel: $localize`:@@ui.event-calendar.todayLabel:Today`, + previousMonthLabel: $localize`:@@ui.event-calendar.previousMonthLabel:Previous month`, + nextMonthLabel: $localize`:@@ui.event-calendar.nextMonthLabel:Next month`, + viewLabel: $localize`:@@ui.event-calendar.viewLabel:View`, + monthViewLabel: $localize`:@@ui.event-calendar.monthViewLabel:Month`, + agendaViewLabel: $localize`:@@ui.event-calendar.agendaViewLabel:List`, + allDayLabel: $localize`:@@ui.event-calendar.allDayLabel:All day`, + locationLabel: $localize`:@@ui.event-calendar.locationLabel:Location`, + linkLabel: $localize`:@@ui.event-calendar.linkLabel:Details`, + addToCalendarLabel: $localize`:@@ui.event-calendar.addToCalendarLabel:Add to calendar`, + noEventsLabel: $localize`:@@ui.event-calendar.noEventsLabel:No events this month.`, + noEventsOnDayLabel: $localize`:@@ui.event-calendar.noEventsOnDayLabel:No events on this day.`, + moreEventsLabel: count => $localize`:@@ui.event-calendar.moreEventsLabel:+${count}:count: more`, + eventCountLabel: count => { + // a text of its own for each form, as $localize has no plurals. + if (count === 0) { + return $localize`:@@ui.event-calendar.eventCountLabel.none:no events`; + } + return count === 1 + ? $localize`:@@ui.event-calendar.eventCountLabel.one:1 event` + : $localize`:@@ui.event-calendar.eventCountLabel.other:${count}:count: events`; + } + }; +} /** * The values every event calendar below this injector uses when its inputs are not set, and its texts. @@ -31,7 +46,7 @@ const DEFAULT_EVENT_CALENDAR_CONFIG: EventCalendarConfig = { */ export const EVENT_CALENDAR_CONFIG: InjectionToken = new InjectionToken('EVENT_CALENDAR_CONFIG', { providedIn: 'root', - factory: () => DEFAULT_EVENT_CALENDAR_CONFIG + factory: () => getDefaultEventCalendarConfig() }); /** @@ -45,7 +60,7 @@ export function provideEventCalendarConfig(config: Partial) return { provide: EVENT_CALENDAR_CONFIG, useFactory: (): EventCalendarConfig => ({ - ...inject(EVENT_CALENDAR_CONFIG, { skipSelf: true, optional: true }) ?? DEFAULT_EVENT_CALENDAR_CONFIG, + ...inject(EVENT_CALENDAR_CONFIG, { skipSelf: true, optional: true }) ?? getDefaultEventCalendarConfig(), ...config }) }; diff --git a/projects/ui/expandable-text/expandable-text-config.provider.ts b/projects/ui/expandable-text/expandable-text-config.provider.ts index 48d0159..132b62b 100644 --- a/projects/ui/expandable-text/expandable-text-config.provider.ts +++ b/projects/ui/expandable-text/expandable-text-config.provider.ts @@ -2,11 +2,18 @@ import { inject, InjectionToken, Provider } from '@angular/core'; import { ExpandableTextConfig } from './expandable-text-config.model'; -const DEFAULT_EXPANDABLE_TEXT_CONFIG: ExpandableTextConfig = { - lines: 3, - moreLabel: 'Read more', - lessLabel: 'Show less' -}; +/** + * The values of an expandable text when nothing changes them. Its texts are $localize, which an app translates like its + * own, and resolved once the config is injected, so translations an app loads at runtime apply as well. + * @returns The default config. + */ +function getDefaultExpandableTextConfig(): ExpandableTextConfig { + return { + lines: 3, + moreLabel: $localize`:@@ui.expandable-text.moreLabel:Read more`, + lessLabel: $localize`:@@ui.expandable-text.lessLabel:Show less` + }; +} /** * The values every expandable text below this injector uses when its inputs are not set. @@ -16,7 +23,7 @@ export const EXPANDABLE_TEXT_CONFIG: InjectionToken = new 'EXPANDABLE_TEXT_CONFIG', { providedIn: 'root', - factory: () => DEFAULT_EXPANDABLE_TEXT_CONFIG + factory: () => getDefaultExpandableTextConfig() } ); @@ -32,7 +39,7 @@ export function provideExpandableTextConfig(config: Partial ({ - ...inject(EXPANDABLE_TEXT_CONFIG, { skipSelf: true, optional: true }) ?? DEFAULT_EXPANDABLE_TEXT_CONFIG, + ...inject(EXPANDABLE_TEXT_CONFIG, { skipSelf: true, optional: true }) ?? getDefaultExpandableTextConfig(), ...config }) }; diff --git a/projects/ui/filter-tiles/filter-tiles-config.provider.ts b/projects/ui/filter-tiles/filter-tiles-config.provider.ts index 9919b04..2bc52ee 100644 --- a/projects/ui/filter-tiles/filter-tiles-config.provider.ts +++ b/projects/ui/filter-tiles/filter-tiles-config.provider.ts @@ -3,12 +3,22 @@ import { faBorderAll } from '@fortawesome/free-solid-svg-icons'; import { FilterTilesConfig } from './filter-tiles-config.model'; -const DEFAULT_FILTER_TILES_CONFIG: FilterTilesConfig = { - color: 'primary', - allLabel: 'All', - allIcon: faBorderAll, - countLabel: count => count === 1 ? '1 item' : `${count} items` -}; +/** + * The values of filter tiles when nothing changes them. Their texts are $localize, which an app translates like its + * own, and resolved once the config is injected, so translations an app loads at runtime apply as well. + * @returns The default config. + */ +function getDefaultFilterTilesConfig(): FilterTilesConfig { + return { + color: 'primary', + allLabel: $localize`:@@ui.filter-tiles.allLabel:All`, + allIcon: faBorderAll, + // a text of its own for each form, as $localize has no plurals. + countLabel: count => count === 1 + ? $localize`:@@ui.filter-tiles.countLabel.one:1 item` + : $localize`:@@ui.filter-tiles.countLabel.other:${count}:count: items` + }; +} /** * The values every filter tiles below this injector use when their inputs are not set. @@ -16,7 +26,7 @@ const DEFAULT_FILTER_TILES_CONFIG: FilterTilesConfig = { */ export const FILTER_TILES_CONFIG: InjectionToken = new InjectionToken('FILTER_TILES_CONFIG', { providedIn: 'root', - factory: () => DEFAULT_FILTER_TILES_CONFIG + factory: () => getDefaultFilterTilesConfig() }); /** @@ -30,7 +40,7 @@ export function provideFilterTilesConfig(config: Partial): Pr return { provide: FILTER_TILES_CONFIG, useFactory: (): FilterTilesConfig => ({ - ...inject(FILTER_TILES_CONFIG, { skipSelf: true, optional: true }) ?? DEFAULT_FILTER_TILES_CONFIG, + ...inject(FILTER_TILES_CONFIG, { skipSelf: true, optional: true }) ?? getDefaultFilterTilesConfig(), ...config }) }; diff --git a/projects/ui/footnotes/footnotes-config.provider.ts b/projects/ui/footnotes/footnotes-config.provider.ts index 517ea5e..35e8c44 100644 --- a/projects/ui/footnotes/footnotes-config.provider.ts +++ b/projects/ui/footnotes/footnotes-config.provider.ts @@ -2,11 +2,18 @@ import { inject, InjectionToken, Provider } from '@angular/core'; import { FootnotesConfig } from './footnotes-config.model'; -const DEFAULT_FOOTNOTES_CONFIG: FootnotesConfig = { - label: 'Footnotes', - referenceLabel: number => `Footnote ${number}`, - backLabel: number => `Back to reference ${number}` -}; +/** + * The texts of footnotes when nothing changes them. They are $localize, which an app translates like its own texts, and + * resolved once the config is injected, so translations an app loads at runtime apply as well. + * @returns The default config. + */ +function getDefaultFootnotesConfig(): FootnotesConfig { + return { + label: $localize`:@@ui.footnotes.label:Footnotes`, + referenceLabel: number => $localize`:@@ui.footnotes.referenceLabel:Footnote ${number}:number:`, + backLabel: number => $localize`:@@ui.footnotes.backLabel:Back to reference ${number}:number:` + }; +} /** * The texts every list of footnotes and every footnote below this injector uses. @@ -14,7 +21,7 @@ const DEFAULT_FOOTNOTES_CONFIG: FootnotesConfig = { */ export const FOOTNOTES_CONFIG: InjectionToken = new InjectionToken('FOOTNOTES_CONFIG', { providedIn: 'root', - factory: () => DEFAULT_FOOTNOTES_CONFIG + factory: () => getDefaultFootnotesConfig() }); /** @@ -28,7 +35,7 @@ export function provideFootnotesConfig(config: Partial): Provid return { provide: FOOTNOTES_CONFIG, useFactory: (): FootnotesConfig => ({ - ...inject(FOOTNOTES_CONFIG, { skipSelf: true, optional: true }) ?? DEFAULT_FOOTNOTES_CONFIG, + ...inject(FOOTNOTES_CONFIG, { skipSelf: true, optional: true }) ?? getDefaultFootnotesConfig(), ...config }) }; diff --git a/projects/ui/gallery/gallery-config.provider.ts b/projects/ui/gallery/gallery-config.provider.ts index 7f13c88..63f86c0 100644 --- a/projects/ui/gallery/gallery-config.provider.ts +++ b/projects/ui/gallery/gallery-config.provider.ts @@ -2,13 +2,20 @@ import { inject, InjectionToken, Provider } from '@angular/core'; import { GalleryConfig } from './gallery-config.model'; -const DEFAULT_GALLERY_CONFIG: GalleryConfig = { - label: 'Pictures', - previousLabel: 'Previous picture', - nextLabel: 'Next picture', - closeLabel: 'Close', - positionLabel: (position, count) => `Picture ${position} of ${count}` -}; +/** + * The texts of a gallery when nothing changes them. They are $localize, which an app translates like its own texts, and + * resolved once the config is injected, so translations an app loads at runtime apply as well. + * @returns The default config. + */ +function getDefaultGalleryConfig(): GalleryConfig { + return { + label: $localize`:@@ui.gallery.label:Pictures`, + previousLabel: $localize`:@@ui.gallery.previousLabel:Previous picture`, + nextLabel: $localize`:@@ui.gallery.nextLabel:Next picture`, + closeLabel: $localize`:@@ui.gallery.closeLabel:Close`, + positionLabel: (position, count) => $localize`:@@ui.gallery.positionLabel:Picture ${position}:position: of ${count}:count:` + }; +} /** * The texts every gallery below this injector uses. @@ -16,7 +23,7 @@ const DEFAULT_GALLERY_CONFIG: GalleryConfig = { */ export const GALLERY_CONFIG: InjectionToken = new InjectionToken('GALLERY_CONFIG', { providedIn: 'root', - factory: () => DEFAULT_GALLERY_CONFIG + factory: () => getDefaultGalleryConfig() }); /** @@ -30,7 +37,7 @@ export function provideGalleryConfig(config: Partial): Provider { return { provide: GALLERY_CONFIG, useFactory: (): GalleryConfig => ({ - ...inject(GALLERY_CONFIG, { skipSelf: true, optional: true }) ?? DEFAULT_GALLERY_CONFIG, + ...inject(GALLERY_CONFIG, { skipSelf: true, optional: true }) ?? getDefaultGalleryConfig(), ...config }) }; diff --git a/projects/ui/input-autocomplete/input-autocomplete.component.ts b/projects/ui/input-autocomplete/input-autocomplete.component.ts index 6c351ca..01dfa1e 100644 --- a/projects/ui/input-autocomplete/input-autocomplete.component.ts +++ b/projects/ui/input-autocomplete/input-autocomplete.component.ts @@ -95,10 +95,12 @@ export class InputAutocompleteComponent extends BaseInputDirective { const options: InputOption[] = this.options(); untracked(() => { - const input: HTMLInputElement = this.nativeInput().nativeElement; + const inputElement: HTMLInputElement = this.nativeInput().nativeElement; const query: string = this.query().trim() .toLowerCase(); - const searching: boolean = input.ownerDocument.activeElement === input && query !== '' && !this.isChosenLabel(query); + const searching: boolean = inputElement.ownerDocument.activeElement === inputElement + && query !== '' + && !this.isChosenLabel(query); if (options.length && searching && this.shownOptions().length) { this.combobox().expanded.set(true); } @@ -116,9 +118,9 @@ export class InputAutocompleteComponent extends BaseInputDirective { const query: string = this.query(); - const input: HTMLInputElement = this.nativeInput().nativeElement; - if (input.value !== query) { - input.value = query; + const inputElement: HTMLInputElement = this.nativeInput().nativeElement; + if (inputElement.value !== query) { + inputElement.value = query; } } }); diff --git a/projects/ui/input-chips/input-chips.component.ts b/projects/ui/input-chips/input-chips.component.ts index 7e5dd76..3137842 100644 --- a/projects/ui/input-chips/input-chips.component.ts +++ b/projects/ui/input-chips/input-chips.component.ts @@ -195,9 +195,9 @@ export class InputChipsComponent extends BaseInputDirective { afterRenderEffect({ write: () => { const query: string = this.query(); - const input: HTMLInputElement = this.nativeInput().nativeElement; - if (input.value !== query) { - input.value = query; + const inputElement: HTMLInputElement = this.nativeInput().nativeElement; + if (inputElement.value !== query) { + inputElement.value = query; } } }); diff --git a/projects/ui/input-date/input-date.utilities.ts b/projects/ui/input-date/input-date.utilities.ts index 0baa6cf..3b873ab 100644 --- a/projects/ui/input-date/input-date.utilities.ts +++ b/projects/ui/input-date/input-date.utilities.ts @@ -126,6 +126,7 @@ export abstract class InputDateUtilities { static resolveCalendarWeeks(month: Date, firstDayOfWeek: InputWeekday): Date[][] { const start: Date = this.resolveMonthStart(month); const daysBefore: number = (start.getDay() - firstDayOfWeek + DAYS_PER_WEEK) % DAYS_PER_WEEK; + // eslint-disable-next-line typescript/no-shadow return Array.from({ length: CALENDAR_WEEKS }, (_, week) => Array.from({ length: DAYS_PER_WEEK }, (_, weekday) => { return new Date(start.getFullYear(), start.getMonth(), 1 - daysBefore + (week * DAYS_PER_WEEK) + weekday); })); diff --git a/projects/ui/input-time/input-time-config.provider.ts b/projects/ui/input-time/input-time-config.provider.ts index aaaf7c3..2e6537c 100644 --- a/projects/ui/input-time/input-time-config.provider.ts +++ b/projects/ui/input-time/input-time-config.provider.ts @@ -2,12 +2,19 @@ import { inject, InjectionToken, Provider } from '@angular/core'; import { InputTimeConfig } from './input-time-config.model'; -const DEFAULT_INPUT_TIME_CONFIG: InputTimeConfig = { - step: 30, - // like the calendar of a date input - color: 'primary', - timePickerLabel: 'Choose a time' -}; +/** + * The values of a time input when nothing changes them. Its label of the picker is $localize, which an app translates + * like its own texts, and resolved once the config is injected, so translations an app loads at runtime apply as well. + * @returns The default config. + */ +function getDefaultInputTimeConfig(): InputTimeConfig { + return { + step: 30, + // like the calendar of a date input + color: 'primary', + timePickerLabel: $localize`:@@ui.input-time.timePickerLabel:Choose a time` + }; +} /** * The values every time input below this injector uses when its inputs are not set, and its texts. @@ -15,7 +22,7 @@ const DEFAULT_INPUT_TIME_CONFIG: InputTimeConfig = { */ export const INPUT_TIME_CONFIG: InjectionToken = new InjectionToken('INPUT_TIME_CONFIG', { providedIn: 'root', - factory: () => DEFAULT_INPUT_TIME_CONFIG + factory: () => getDefaultInputTimeConfig() }); /** @@ -29,7 +36,7 @@ export function provideInputTimeConfig(config: Partial): Provid return { provide: INPUT_TIME_CONFIG, useFactory: (): InputTimeConfig => ({ - ...inject(INPUT_TIME_CONFIG, { skipSelf: true, optional: true }) ?? DEFAULT_INPUT_TIME_CONFIG, + ...inject(INPUT_TIME_CONFIG, { skipSelf: true, optional: true }) ?? getDefaultInputTimeConfig(), ...config }) }; diff --git a/projects/ui/input/input-config.provider.ts b/projects/ui/input/input-config.provider.ts index 430081e..492b576 100644 --- a/projects/ui/input/input-config.provider.ts +++ b/projects/ui/input/input-config.provider.ts @@ -3,56 +3,63 @@ import { inject, InjectionToken, Provider } from '@angular/core'; import { InputConfigChanges } from './input-config-changes.model'; import { InputConfig } from './input-config.model'; -const DEFAULT_INPUT_CONFIG: InputConfig = { - size: 'md', - required: true, - showPasswordLabel: 'Show password', - clearSearchLabel: 'Clear search', - passwordStrength: false, - passwordStrengthLabels: { - weak: 'Password strength: weak', - medium: 'Password strength: medium', - strong: 'Password strength: strong' - }, - textareaRows: 3, - booleanAppearance: 'checkbox', - cardsAppearance: 'cards', - chooseFileLabel: 'Choose a file', - chooseFilesLabel: 'Choose files', - removeLabel: 'Remove', - datePickerLabel: 'Choose a date', - previousMonthLabel: 'Previous month', - nextMonthLabel: 'Next month', - chooseYearLabel: 'Choose a year', - dateRangePickerLabel: 'Choose the dates', - rangeStartLabel: 'Start', - rangeEndLabel: 'End', - timeLabel: 'Time', - calendarColor: 'primary', - color: 'primary', - // Monday, as in ISO 8601. Browsers don't agree on Intl.Locale's week info yet, so it isn't read from the locale. - firstDayOfWeek: 1, - errorMessages: { - valueMissing: 'This field is required.', - typeMismatch: 'The value has the wrong format.', - patternMismatch: 'The value has the wrong format.', - tooShort: 'The value is too short.', - tooLong: 'The value is too long.', - rangeUnderflow: 'The value is too small.', - rangeOverflow: 'The value is too large.', - stepMismatch: 'The value is not one of the allowed steps.', - badInput: 'The value can\'t be read.', - fileTooLarge: 'This file is too large.', - fileTypeMismatch: 'This file is of a type that isn\'t accepted.', - invalidFiles: 'Remove the marked files, they can\'t be uploaded.', - optionNotChosen: 'Choose one of the options.', - rangeIncomplete: 'Choose the start and the end.', - rangeReversed: 'The end is before the start.', - rangeTooShort: 'The period is too short.', - rangeTooLong: 'The period is too long.', - timeNotAllowed: 'This time isn\'t available.' - } -}; +/** + * The values of inputs when nothing changes them. Their texts are $localize, which an app translates like its own, and + * resolved once the config is injected, so translations an app loads at runtime apply as well. + * @returns The default config. + */ +function getDefaultInputConfig(): InputConfig { + return { + size: 'md', + required: true, + showPasswordLabel: $localize`:@@ui.input.showPasswordLabel:Show password`, + clearSearchLabel: $localize`:@@ui.input.clearSearchLabel:Clear search`, + passwordStrength: false, + passwordStrengthLabels: { + weak: $localize`:@@ui.input.passwordStrengthLabels.weak:Password strength: weak`, + medium: $localize`:@@ui.input.passwordStrengthLabels.medium:Password strength: medium`, + strong: $localize`:@@ui.input.passwordStrengthLabels.strong:Password strength: strong` + }, + textareaRows: 3, + booleanAppearance: 'checkbox', + cardsAppearance: 'cards', + chooseFileLabel: $localize`:@@ui.input.chooseFileLabel:Choose a file`, + chooseFilesLabel: $localize`:@@ui.input.chooseFilesLabel:Choose files`, + removeLabel: $localize`:@@ui.input.removeLabel:Remove`, + datePickerLabel: $localize`:@@ui.input.datePickerLabel:Choose a date`, + previousMonthLabel: $localize`:@@ui.input.previousMonthLabel:Previous month`, + nextMonthLabel: $localize`:@@ui.input.nextMonthLabel:Next month`, + chooseYearLabel: $localize`:@@ui.input.chooseYearLabel:Choose a year`, + dateRangePickerLabel: $localize`:@@ui.input.dateRangePickerLabel:Choose the dates`, + rangeStartLabel: $localize`:@@ui.input.rangeStartLabel:Start`, + rangeEndLabel: $localize`:@@ui.input.rangeEndLabel:End`, + timeLabel: $localize`:@@ui.input.timeLabel:Time`, + calendarColor: 'primary', + color: 'primary', + // Monday, as in ISO 8601. Browsers don't agree on Intl.Locale's week info yet, so it isn't read from the locale. + firstDayOfWeek: 1, + errorMessages: { + valueMissing: $localize`:@@ui.input.errorMessages.valueMissing:This field is required.`, + typeMismatch: $localize`:@@ui.input.errorMessages.typeMismatch:The value has the wrong format.`, + patternMismatch: $localize`:@@ui.input.errorMessages.patternMismatch:The value has the wrong format.`, + tooShort: $localize`:@@ui.input.errorMessages.tooShort:The value is too short.`, + tooLong: $localize`:@@ui.input.errorMessages.tooLong:The value is too long.`, + rangeUnderflow: $localize`:@@ui.input.errorMessages.rangeUnderflow:The value is too small.`, + rangeOverflow: $localize`:@@ui.input.errorMessages.rangeOverflow:The value is too large.`, + stepMismatch: $localize`:@@ui.input.errorMessages.stepMismatch:The value is not one of the allowed steps.`, + badInput: $localize`:@@ui.input.errorMessages.badInput:The value can't be read.`, + fileTooLarge: $localize`:@@ui.input.errorMessages.fileTooLarge:This file is too large.`, + fileTypeMismatch: $localize`:@@ui.input.errorMessages.fileTypeMismatch:This file is of a type that isn't accepted.`, + invalidFiles: $localize`:@@ui.input.errorMessages.invalidFiles:Remove the marked files, they can't be uploaded.`, + optionNotChosen: $localize`:@@ui.input.errorMessages.optionNotChosen:Choose one of the options.`, + rangeIncomplete: $localize`:@@ui.input.errorMessages.rangeIncomplete:Choose the start and the end.`, + rangeReversed: $localize`:@@ui.input.errorMessages.rangeReversed:The end is before the start.`, + rangeTooShort: $localize`:@@ui.input.errorMessages.rangeTooShort:The period is too short.`, + rangeTooLong: $localize`:@@ui.input.errorMessages.rangeTooLong:The period is too long.`, + timeNotAllowed: $localize`:@@ui.input.errorMessages.timeNotAllowed:This time isn't available.` + } + }; +} /** * The values every input below this injector uses when its inputs are not set. @@ -60,7 +67,7 @@ const DEFAULT_INPUT_CONFIG: InputConfig = { */ export const INPUT_CONFIG: InjectionToken = new InjectionToken('INPUT_CONFIG', { providedIn: 'root', - factory: () => DEFAULT_INPUT_CONFIG + factory: () => getDefaultInputConfig() }); /** @@ -74,7 +81,7 @@ export function provideInputConfig(config: InputConfigChanges): Provider { return { provide: INPUT_CONFIG, useFactory: (): InputConfig => { - const parent: InputConfig = inject(INPUT_CONFIG, { skipSelf: true, optional: true }) ?? DEFAULT_INPUT_CONFIG; + const parent: InputConfig = inject(INPUT_CONFIG, { skipSelf: true, optional: true }) ?? getDefaultInputConfig(); return { ...parent, ...config, errorMessages: { ...parent.errorMessages, ...config.errorMessages } }; } }; diff --git a/projects/ui/link/link-config.provider.ts b/projects/ui/link/link-config.provider.ts index e85f7da..779e29a 100644 --- a/projects/ui/link/link-config.provider.ts +++ b/projects/ui/link/link-config.provider.ts @@ -2,10 +2,18 @@ import { inject, InjectionToken, Provider } from '@angular/core'; import { LinkConfig } from './link-config.model'; -const DEFAULT_LINK_CONFIG: LinkConfig = { - appearance: 'inline', - newTabLabel: 'opens in a new tab' -}; +/** + * The values of a link when nothing changes them. Its text for a link that opens in a new tab is $localize, which an + * app translates like its own texts, and resolved once the config is injected, so translations an app loads at runtime + * apply as well. + * @returns The default config. + */ +function getDefaultLinkConfig(): LinkConfig { + return { + appearance: 'inline', + newTabLabel: $localize`:@@ui.link.newTabLabel:opens in a new tab` + }; +} /** * The values every link below this injector uses when its inputs are not set. @@ -13,7 +21,7 @@ const DEFAULT_LINK_CONFIG: LinkConfig = { */ export const LINK_CONFIG: InjectionToken = new InjectionToken('LINK_CONFIG', { providedIn: 'root', - factory: () => DEFAULT_LINK_CONFIG + factory: () => getDefaultLinkConfig() }); /** @@ -27,7 +35,7 @@ export function provideLinkConfig(config: Partial): Provider { return { provide: LINK_CONFIG, useFactory: (): LinkConfig => ({ - ...inject(LINK_CONFIG, { skipSelf: true, optional: true }) ?? DEFAULT_LINK_CONFIG, + ...inject(LINK_CONFIG, { skipSelf: true, optional: true }) ?? getDefaultLinkConfig(), ...config }) }; diff --git a/projects/ui/loading/loading-config.provider.ts b/projects/ui/loading/loading-config.provider.ts index 104c561..d9925b3 100644 --- a/projects/ui/loading/loading-config.provider.ts +++ b/projects/ui/loading/loading-config.provider.ts @@ -2,10 +2,17 @@ import { inject, InjectionToken, Provider } from '@angular/core'; import { LoadingConfig } from './loading-config.model'; -const DEFAULT_LOADING_CONFIG: LoadingConfig = { - label: 'Loading', - size: 'lg' -}; +/** + * The values of an area that loads when nothing changes them. Its label is $localize, which an app translates like its + * own texts, and resolved once the config is injected, so translations an app loads at runtime apply as well. + * @returns The default config. + */ +function getDefaultLoadingConfig(): LoadingConfig { + return { + label: $localize`:@@ui.loading.label:Loading`, + size: 'lg' + }; +} /** * The values every area that loads below this injector uses when its inputs are not set, and its text. @@ -13,7 +20,7 @@ const DEFAULT_LOADING_CONFIG: LoadingConfig = { */ export const LOADING_CONFIG: InjectionToken = new InjectionToken('LOADING_CONFIG', { providedIn: 'root', - factory: () => DEFAULT_LOADING_CONFIG + factory: () => getDefaultLoadingConfig() }); /** @@ -27,7 +34,7 @@ export function provideLoadingConfig(config: Partial): Provider { return { provide: LOADING_CONFIG, useFactory: (): LoadingConfig => ({ - ...inject(LOADING_CONFIG, { skipSelf: true, optional: true }) ?? DEFAULT_LOADING_CONFIG, + ...inject(LOADING_CONFIG, { skipSelf: true, optional: true }) ?? getDefaultLoadingConfig(), ...config }) }; diff --git a/projects/ui/map/map-config.provider.ts b/projects/ui/map/map-config.provider.ts index 4760f71..a675774 100644 --- a/projects/ui/map/map-config.provider.ts +++ b/projects/ui/map/map-config.provider.ts @@ -3,13 +3,20 @@ import { inject, InjectionToken, Provider } from '@angular/core'; import { GOOGLE_MAPS_PROVIDER } from './google-maps-provider'; import { MapConfig } from './map-config.model'; -const DEFAULT_MAP_CONFIG: MapConfig = { - provider: GOOGLE_MAPS_PROVIDER, - zoom: 15, - aspectRatio: '16 / 9', - label: 'Map', - routeLabel: 'Plan route' -}; +/** + * The values of a map when nothing changes them. Its texts are $localize, which an app translates like its own, and + * resolved once the config is injected, so translations an app loads at runtime apply as well. + * @returns The default config. + */ +function getDefaultMapConfig(): MapConfig { + return { + provider: GOOGLE_MAPS_PROVIDER, + zoom: 15, + aspectRatio: '16 / 9', + label: $localize`:@@ui.map.label:Map`, + routeLabel: $localize`:@@ui.map.routeLabel:Plan route` + }; +} /** * The values every map below this injector uses when its inputs are not set, and its texts. @@ -17,7 +24,7 @@ const DEFAULT_MAP_CONFIG: MapConfig = { */ export const MAP_CONFIG: InjectionToken = new InjectionToken('MAP_CONFIG', { providedIn: 'root', - factory: () => DEFAULT_MAP_CONFIG + factory: () => getDefaultMapConfig() }); /** @@ -32,7 +39,7 @@ export function provideMapConfig(config: Partial): Provider { return { provide: MAP_CONFIG, useFactory: (): MapConfig => ({ - ...inject(MAP_CONFIG, { skipSelf: true, optional: true }) ?? DEFAULT_MAP_CONFIG, + ...inject(MAP_CONFIG, { skipSelf: true, optional: true }) ?? getDefaultMapConfig(), ...config }) }; diff --git a/projects/ui/news-ticker/news-ticker-config.provider.ts b/projects/ui/news-ticker/news-ticker-config.provider.ts index 62521af..356b061 100644 --- a/projects/ui/news-ticker/news-ticker-config.provider.ts +++ b/projects/ui/news-ticker/news-ticker-config.provider.ts @@ -3,14 +3,21 @@ import { faBullhorn } from '@fortawesome/free-solid-svg-icons'; import { NewsTickerConfig } from './news-ticker-config.model'; -const DEFAULT_NEWS_TICKER_CONFIG: NewsTickerConfig = { - color: 'neutral', - icon: faBullhorn, - speed: 50, - label: 'News', - pauseLabel: 'Pause news', - playLabel: 'Play news' -}; +/** + * The values of a news ticker when nothing changes them. Its texts are $localize, which an app translates like its own, + * and resolved once the config is injected, so translations an app loads at runtime apply as well. + * @returns The default config. + */ +function getDefaultNewsTickerConfig(): NewsTickerConfig { + return { + color: 'neutral', + icon: faBullhorn, + speed: 50, + label: $localize`:@@ui.news-ticker.label:News`, + pauseLabel: $localize`:@@ui.news-ticker.pauseLabel:Pause news`, + playLabel: $localize`:@@ui.news-ticker.playLabel:Play news` + }; +} /** * The values every news ticker below this injector uses when its inputs are not set, and its texts. @@ -18,7 +25,7 @@ const DEFAULT_NEWS_TICKER_CONFIG: NewsTickerConfig = { */ export const NEWS_TICKER_CONFIG: InjectionToken = new InjectionToken('NEWS_TICKER_CONFIG', { providedIn: 'root', - factory: () => DEFAULT_NEWS_TICKER_CONFIG + factory: () => getDefaultNewsTickerConfig() }); /** @@ -32,7 +39,7 @@ export function provideNewsTickerConfig(config: Partial): Prov return { provide: NEWS_TICKER_CONFIG, useFactory: (): NewsTickerConfig => ({ - ...inject(NEWS_TICKER_CONFIG, { skipSelf: true, optional: true }) ?? DEFAULT_NEWS_TICKER_CONFIG, + ...inject(NEWS_TICKER_CONFIG, { skipSelf: true, optional: true }) ?? getDefaultNewsTickerConfig(), ...config }) }; diff --git a/projects/ui/opening-hours/opening-hours-config.provider.ts b/projects/ui/opening-hours/opening-hours-config.provider.ts index aad3391..a2fe41c 100644 --- a/projects/ui/opening-hours/opening-hours-config.provider.ts +++ b/projects/ui/opening-hours/opening-hours-config.provider.ts @@ -2,20 +2,27 @@ import { inject, InjectionToken, Provider } from '@angular/core'; import { OpeningHoursConfig } from './opening-hours-config.model'; -const DEFAULT_OPENING_HOURS_CONFIG: OpeningHoursConfig = { - firstDayOfWeek: 1, - group: false, - status: true, - microdata: true, - timeZone: undefined, - dayFormat: 'long', - label: 'Opening hours', - closedLabel: 'Closed', - todayLabel: 'Today', - openNowLabel: 'Open now', - closedNowLabel: 'Closed now', - toLabel: 'to' -}; +/** + * The values of opening hours when nothing changes them. Their texts are $localize, which an app translates like its + * own, and resolved once the config is injected, so translations an app loads at runtime apply as well. + * @returns The default config. + */ +function getDefaultOpeningHoursConfig(): OpeningHoursConfig { + return { + firstDayOfWeek: 1, + group: false, + status: true, + microdata: true, + timeZone: undefined, + dayFormat: 'long', + label: $localize`:@@ui.opening-hours.label:Opening hours`, + closedLabel: $localize`:@@ui.opening-hours.closedLabel:Closed`, + todayLabel: $localize`:@@ui.opening-hours.todayLabel:Today`, + openNowLabel: $localize`:@@ui.opening-hours.openNowLabel:Open now`, + closedNowLabel: $localize`:@@ui.opening-hours.closedNowLabel:Closed now`, + toLabel: $localize`:@@ui.opening-hours.toLabel:to` + }; +} /** * The values all opening hours below this injector use when their inputs are not set, and their texts. @@ -23,7 +30,7 @@ const DEFAULT_OPENING_HOURS_CONFIG: OpeningHoursConfig = { */ export const OPENING_HOURS_CONFIG: InjectionToken = new InjectionToken('OPENING_HOURS_CONFIG', { providedIn: 'root', - factory: () => DEFAULT_OPENING_HOURS_CONFIG + factory: () => getDefaultOpeningHoursConfig() }); /** @@ -37,7 +44,7 @@ export function provideOpeningHoursConfig(config: Partial): return { provide: OPENING_HOURS_CONFIG, useFactory: (): OpeningHoursConfig => ({ - ...inject(OPENING_HOURS_CONFIG, { skipSelf: true, optional: true }) ?? DEFAULT_OPENING_HOURS_CONFIG, + ...inject(OPENING_HOURS_CONFIG, { skipSelf: true, optional: true }) ?? getDefaultOpeningHoursConfig(), ...config }) }; diff --git a/projects/ui/package.json b/projects/ui/package.json index ceda394..2514a88 100644 --- a/projects/ui/package.json +++ b/projects/ui/package.json @@ -1,6 +1,6 @@ { "name": "@service-soft/ui", - "version": "22.3.0", + "version": "22.3.1", "license": "MIT", "repository": { "type": "git", @@ -23,6 +23,7 @@ "@angular/aria": "^22.2.0", "@angular/common": "^22.2.0", "@angular/core": "^22.2.0", + "@angular/localize": "^22.2.0", "@angular/platform-browser": "^22.2.0", "@fortawesome/free-solid-svg-icons": "^7.3.1", "tailwindcss": "^4.3.3" diff --git a/projects/ui/pagination/pagination-config.provider.ts b/projects/ui/pagination/pagination-config.provider.ts index 1c54fb1..a00e0d6 100644 --- a/projects/ui/pagination/pagination-config.provider.ts +++ b/projects/ui/pagination/pagination-config.provider.ts @@ -2,15 +2,22 @@ import { inject, InjectionToken, Provider } from '@angular/core'; import { PaginationConfig } from './pagination-config.model'; -const DEFAULT_PAGINATION_CONFIG: PaginationConfig = { - color: 'primary', - label: 'Pages', - firstLabel: 'First page', - previousLabel: 'Previous page', - nextLabel: 'Next page', - lastLabel: 'Last page', - pageLabel: page => `Page ${page}` -}; +/** + * The values of a pagination when nothing changes them. Its texts are $localize, which an app translates like its own, + * and resolved once the config is injected, so translations an app loads at runtime apply as well. + * @returns The default config. + */ +function getDefaultPaginationConfig(): PaginationConfig { + return { + color: 'primary', + label: $localize`:@@ui.pagination.label:Pages`, + firstLabel: $localize`:@@ui.pagination.firstLabel:First page`, + previousLabel: $localize`:@@ui.pagination.previousLabel:Previous page`, + nextLabel: $localize`:@@ui.pagination.nextLabel:Next page`, + lastLabel: $localize`:@@ui.pagination.lastLabel:Last page`, + pageLabel: page => $localize`:@@ui.pagination.pageLabel:Page ${page}:page:` + }; +} /** * The values every pagination below this injector uses when its inputs are not set, and its texts. @@ -18,7 +25,7 @@ const DEFAULT_PAGINATION_CONFIG: PaginationConfig = { */ export const PAGINATION_CONFIG: InjectionToken = new InjectionToken('PAGINATION_CONFIG', { providedIn: 'root', - factory: () => DEFAULT_PAGINATION_CONFIG + factory: () => getDefaultPaginationConfig() }); /** @@ -32,7 +39,7 @@ export function providePaginationConfig(config: Partial): Prov return { provide: PAGINATION_CONFIG, useFactory: (): PaginationConfig => ({ - ...inject(PAGINATION_CONFIG, { skipSelf: true, optional: true }) ?? DEFAULT_PAGINATION_CONFIG, + ...inject(PAGINATION_CONFIG, { skipSelf: true, optional: true }) ?? getDefaultPaginationConfig(), ...config }) }; diff --git a/projects/ui/price/price-config.provider.ts b/projects/ui/price/price-config.provider.ts index b1e4dc3..57ddbd7 100644 --- a/projects/ui/price/price-config.provider.ts +++ b/projects/ui/price/price-config.provider.ts @@ -2,13 +2,20 @@ import { inject, InjectionToken, Provider } from '@angular/core'; import { PriceConfig } from './price-config.model'; -const DEFAULT_PRICE_CONFIG: PriceConfig = { - currency: 'EUR', - format: {}, - size: 'md', - perLabel: 'per', - oldPriceLabel: 'previously' -}; +/** + * The values of a price when nothing changes them. Its texts are $localize, which an app translates like its own, and + * resolved once the config is injected, so translations an app loads at runtime apply as well. + * @returns The default config. + */ +function getDefaultPriceConfig(): PriceConfig { + return { + currency: 'EUR', + format: {}, + size: 'md', + perLabel: $localize`:@@ui.price.perLabel:per`, + oldPriceLabel: $localize`:@@ui.price.oldPriceLabel:previously` + }; +} /** * The values every price below this injector uses when its inputs are not set. @@ -16,7 +23,7 @@ const DEFAULT_PRICE_CONFIG: PriceConfig = { */ export const PRICE_CONFIG: InjectionToken = new InjectionToken('PRICE_CONFIG', { providedIn: 'root', - factory: () => DEFAULT_PRICE_CONFIG + factory: () => getDefaultPriceConfig() }); /** @@ -30,7 +37,7 @@ export function providePriceConfig(config: Partial): Provider { return { provide: PRICE_CONFIG, useFactory: (): PriceConfig => ({ - ...inject(PRICE_CONFIG, { skipSelf: true, optional: true }) ?? DEFAULT_PRICE_CONFIG, + ...inject(PRICE_CONFIG, { skipSelf: true, optional: true }) ?? getDefaultPriceConfig(), ...config }) }; diff --git a/projects/ui/pricing-card/pricing-card-config.provider.ts b/projects/ui/pricing-card/pricing-card-config.provider.ts index baa7f84..92bcfa4 100644 --- a/projects/ui/pricing-card/pricing-card-config.provider.ts +++ b/projects/ui/pricing-card/pricing-card-config.provider.ts @@ -2,12 +2,19 @@ import { inject, InjectionToken, Provider } from '@angular/core'; import { PricingCardConfig } from './pricing-card-config.model'; -// below the h2 of the section the plans are in. -const DEFAULT_PRICING_CARD_CONFIG: PricingCardConfig = { - headingLevel: 3, - badge: 'Recommended', - highlightColor: 'primary' -}; +/** + * The values of a pricing card when nothing changes them. Its text of the badge is $localize, which an app translates + * like its own texts, and resolved once the config is injected, so translations an app loads at runtime apply as well. + * @returns The default config. + */ +function getDefaultPricingCardConfig(): PricingCardConfig { + return { + // below the h2 of the section the plans are in. + headingLevel: 3, + badge: $localize`:@@ui.pricing-card.badge:Recommended`, + highlightColor: 'primary' + }; +} /** * The values every pricing card below this injector uses when its inputs are not set. @@ -15,7 +22,7 @@ const DEFAULT_PRICING_CARD_CONFIG: PricingCardConfig = { */ export const PRICING_CARD_CONFIG: InjectionToken = new InjectionToken('PRICING_CARD_CONFIG', { providedIn: 'root', - factory: () => DEFAULT_PRICING_CARD_CONFIG + factory: () => getDefaultPricingCardConfig() }); /** @@ -29,7 +36,7 @@ export function providePricingCardConfig(config: Partial): Pr return { provide: PRICING_CARD_CONFIG, useFactory: (): PricingCardConfig => ({ - ...inject(PRICING_CARD_CONFIG, { skipSelf: true, optional: true }) ?? DEFAULT_PRICING_CARD_CONFIG, + ...inject(PRICING_CARD_CONFIG, { skipSelf: true, optional: true }) ?? getDefaultPricingCardConfig(), ...config }) }; diff --git a/projects/ui/rating/rating-config.provider.ts b/projects/ui/rating/rating-config.provider.ts index 0f5d22a..ed09d5a 100644 --- a/projects/ui/rating/rating-config.provider.ts +++ b/projects/ui/rating/rating-config.provider.ts @@ -2,10 +2,17 @@ import { inject, InjectionToken, Provider } from '@angular/core'; import { RatingConfig } from './rating-config.model'; -const DEFAULT_RATING_CONFIG: RatingConfig = { - max: 5, - label: (value, max) => `${value} out of ${max} stars` -}; +/** + * The values of a rating when nothing changes them. Its label is $localize, which an app translates like its own texts, + * and resolved once the config is injected, so translations an app loads at runtime apply as well. + * @returns The default config. + */ +function getDefaultRatingConfig(): RatingConfig { + return { + max: 5, + label: (value, max) => $localize`:@@ui.rating.label:${value}:value: out of ${max}:max: stars` + }; +} /** * The values every rating below this injector uses when its inputs are not set, and its texts. @@ -13,7 +20,7 @@ const DEFAULT_RATING_CONFIG: RatingConfig = { */ export const RATING_CONFIG: InjectionToken = new InjectionToken('RATING_CONFIG', { providedIn: 'root', - factory: () => DEFAULT_RATING_CONFIG + factory: () => getDefaultRatingConfig() }); /** @@ -27,7 +34,7 @@ export function provideRatingConfig(config: Partial): Provider { return { provide: RATING_CONFIG, useFactory: (): RatingConfig => ({ - ...inject(RATING_CONFIG, { skipSelf: true, optional: true }) ?? DEFAULT_RATING_CONFIG, + ...inject(RATING_CONFIG, { skipSelf: true, optional: true }) ?? getDefaultRatingConfig(), ...config }) }; diff --git a/projects/ui/search-toolbar/search-toolbar-config.provider.ts b/projects/ui/search-toolbar/search-toolbar-config.provider.ts index e244312..5de2421 100644 --- a/projects/ui/search-toolbar/search-toolbar-config.provider.ts +++ b/projects/ui/search-toolbar/search-toolbar-config.provider.ts @@ -2,11 +2,22 @@ import { inject, InjectionToken, Provider } from '@angular/core'; import { SearchToolbarConfig } from './search-toolbar-config.model'; -const DEFAULT_SEARCH_TOOLBAR_CONFIG: SearchToolbarConfig = { - searchLabel: 'Search', - resultCountLabel: count => count === 1 ? '1 result' : `${count} results`, - activeFiltersLabel: count => `${count} active` -}; +/** + * The values of a search toolbar and a filter button when nothing changes them. Their texts are $localize, which an app + * translates like its own, and resolved once the config is injected, so translations an app loads at runtime apply as + * well. + * @returns The default config. + */ +function getDefaultSearchToolbarConfig(): SearchToolbarConfig { + return { + searchLabel: $localize`:@@ui.search-toolbar.searchLabel:Search`, + // a text of its own for each form, as $localize has no plurals. + resultCountLabel: count => count === 1 + ? $localize`:@@ui.search-toolbar.resultCountLabel.one:1 result` + : $localize`:@@ui.search-toolbar.resultCountLabel.other:${count}:count: results`, + activeFiltersLabel: count => $localize`:@@ui.search-toolbar.activeFiltersLabel:${count}:count: active` + }; +} /** * The values every search toolbar and filter button below this injector uses when their inputs are not set. @@ -14,7 +25,7 @@ const DEFAULT_SEARCH_TOOLBAR_CONFIG: SearchToolbarConfig = { */ export const SEARCH_TOOLBAR_CONFIG: InjectionToken = new InjectionToken('SEARCH_TOOLBAR_CONFIG', { providedIn: 'root', - factory: () => DEFAULT_SEARCH_TOOLBAR_CONFIG + factory: () => getDefaultSearchToolbarConfig() }); /** @@ -29,7 +40,7 @@ export function provideSearchToolbarConfig(config: Partial) return { provide: SEARCH_TOOLBAR_CONFIG, useFactory: (): SearchToolbarConfig => ({ - ...inject(SEARCH_TOOLBAR_CONFIG, { skipSelf: true, optional: true }) ?? DEFAULT_SEARCH_TOOLBAR_CONFIG, + ...inject(SEARCH_TOOLBAR_CONFIG, { skipSelf: true, optional: true }) ?? getDefaultSearchToolbarConfig(), ...config }) }; diff --git a/projects/ui/showcase-card/showcase-card-config.provider.ts b/projects/ui/showcase-card/showcase-card-config.provider.ts index ba8f09d..b586f2b 100644 --- a/projects/ui/showcase-card/showcase-card-config.provider.ts +++ b/projects/ui/showcase-card/showcase-card-config.provider.ts @@ -2,10 +2,17 @@ import { inject, InjectionToken, Provider } from '@angular/core'; import { ShowcaseCardConfig } from './showcase-card-config.model'; -const DEFAULT_SHOWCASE_CARD_CONFIG: ShowcaseCardConfig = { - headingLevel: 2, - tagsLabel: 'Tags' -}; +/** + * The values of a showcase card when nothing changes them. Its label of the tags is $localize, which an app translates + * like its own texts, and resolved once the config is injected, so translations an app loads at runtime apply as well. + * @returns The default config. + */ +function getDefaultShowcaseCardConfig(): ShowcaseCardConfig { + return { + headingLevel: 2, + tagsLabel: $localize`:@@ui.showcase-card.tagsLabel:Tags` + }; +} /** * The values every showcase card below this injector uses when its inputs are not set. @@ -13,7 +20,7 @@ const DEFAULT_SHOWCASE_CARD_CONFIG: ShowcaseCardConfig = { */ export const SHOWCASE_CARD_CONFIG: InjectionToken = new InjectionToken('SHOWCASE_CARD_CONFIG', { providedIn: 'root', - factory: () => DEFAULT_SHOWCASE_CARD_CONFIG + factory: () => getDefaultShowcaseCardConfig() }); /** @@ -27,7 +34,7 @@ export function provideShowcaseCardConfig(config: Partial): return { provide: SHOWCASE_CARD_CONFIG, useFactory: (): ShowcaseCardConfig => ({ - ...inject(SHOWCASE_CARD_CONFIG, { skipSelf: true, optional: true }) ?? DEFAULT_SHOWCASE_CARD_CONFIG, + ...inject(SHOWCASE_CARD_CONFIG, { skipSelf: true, optional: true }) ?? getDefaultShowcaseCardConfig(), ...config }) }; diff --git a/projects/ui/spam-protection/spam-protection-config.provider.ts b/projects/ui/spam-protection/spam-protection-config.provider.ts index a286c01..6c2486b 100644 --- a/projects/ui/spam-protection/spam-protection-config.provider.ts +++ b/projects/ui/spam-protection/spam-protection-config.provider.ts @@ -2,12 +2,19 @@ import { inject, InjectionToken, Provider } from '@angular/core'; import { SpamProtectionConfig } from './spam-protection-config.model'; -// no minimum by default: a person who comes back to a form whose draft was kept may send it within a second. -const DEFAULT_SPAM_PROTECTION_CONFIG: SpamProtectionConfig = { - name: 'website', - label: 'Leave this field empty', - minimumFillTime: 0 -}; +/** + * The values of a spam protection when nothing changes them. Its label is $localize, which an app translates like its + * own texts, and resolved once the config is injected, so translations an app loads at runtime apply as well. + * @returns The default config. + */ +function getDefaultSpamProtectionConfig(): SpamProtectionConfig { + return { + name: 'website', + label: $localize`:@@ui.spam-protection.label:Leave this field empty`, + // no minimum by default: a person who comes back to a form whose draft was kept may send it within a second. + minimumFillTime: 0 + }; +} /** * The values every spam protection below this injector uses when its inputs are not set, and its texts. @@ -17,7 +24,7 @@ export const SPAM_PROTECTION_CONFIG: InjectionToken = new 'SPAM_PROTECTION_CONFIG', { providedIn: 'root', - factory: () => DEFAULT_SPAM_PROTECTION_CONFIG + factory: () => getDefaultSpamProtectionConfig() } ); @@ -32,7 +39,7 @@ export function provideSpamProtectionConfig(config: Partial ({ - ...inject(SPAM_PROTECTION_CONFIG, { skipSelf: true, optional: true }) ?? DEFAULT_SPAM_PROTECTION_CONFIG, + ...inject(SPAM_PROTECTION_CONFIG, { skipSelf: true, optional: true }) ?? getDefaultSpamProtectionConfig(), ...config }) }; diff --git a/projects/ui/spinner/spinner-config.provider.ts b/projects/ui/spinner/spinner-config.provider.ts index 8d3598e..1e0fa76 100644 --- a/projects/ui/spinner/spinner-config.provider.ts +++ b/projects/ui/spinner/spinner-config.provider.ts @@ -2,10 +2,17 @@ import { inject, InjectionToken, Provider } from '@angular/core'; import { SpinnerConfig } from './spinner-config.model'; -const DEFAULT_SPINNER_CONFIG: SpinnerConfig = { - label: 'Loading', - size: 'md' -}; +/** + * The values of a spinner when nothing changes them. Its label is $localize, which an app translates like its own + * texts, and resolved once the config is injected, so translations an app loads at runtime apply as well. + * @returns The default config. + */ +function getDefaultSpinnerConfig(): SpinnerConfig { + return { + label: $localize`:@@ui.spinner.label:Loading`, + size: 'md' + }; +} /** * The values every spinner below this injector uses when its inputs are not set. @@ -13,7 +20,7 @@ const DEFAULT_SPINNER_CONFIG: SpinnerConfig = { */ export const SPINNER_CONFIG: InjectionToken = new InjectionToken('SPINNER_CONFIG', { providedIn: 'root', - factory: () => DEFAULT_SPINNER_CONFIG + factory: () => getDefaultSpinnerConfig() }); /** @@ -27,7 +34,7 @@ export function provideSpinnerConfig(config: Partial): Provider { return { provide: SPINNER_CONFIG, useFactory: (): SpinnerConfig => ({ - ...inject(SPINNER_CONFIG, { skipSelf: true, optional: true }) ?? DEFAULT_SPINNER_CONFIG, + ...inject(SPINNER_CONFIG, { skipSelf: true, optional: true }) ?? getDefaultSpinnerConfig(), ...config }) }; diff --git a/projects/ui/stepper/stepper-config.provider.ts b/projects/ui/stepper/stepper-config.provider.ts index 35aa4db..5893805 100644 --- a/projects/ui/stepper/stepper-config.provider.ts +++ b/projects/ui/stepper/stepper-config.provider.ts @@ -2,19 +2,26 @@ import { inject, InjectionToken, Provider } from '@angular/core'; import { StepperConfig } from './stepper-config.model'; -const DEFAULT_STEPPER_CONFIG: StepperConfig = { - orientation: 'horizontal', - linear: true, - color: 'primary', - headingLevel: 2, - label: 'Steps', - backLabel: 'Back', - nextLabel: 'Next', - finishLabel: 'Finish', - doneLabel: 'completed', - busyLabel: 'Checking', - progressLabel: (current, total) => `Step ${current} of ${total}` -}; +/** + * The values of a stepper when nothing changes them. Its texts are $localize, which an app translates like its own, and + * resolved once the config is injected, so translations an app loads at runtime apply as well. + * @returns The default config. + */ +function getDefaultStepperConfig(): StepperConfig { + return { + orientation: 'horizontal', + linear: true, + color: 'primary', + headingLevel: 2, + label: $localize`:@@ui.stepper.label:Steps`, + backLabel: $localize`:@@ui.stepper.backLabel:Back`, + nextLabel: $localize`:@@ui.stepper.nextLabel:Next`, + finishLabel: $localize`:@@ui.stepper.finishLabel:Finish`, + doneLabel: $localize`:@@ui.stepper.doneLabel:completed`, + busyLabel: $localize`:@@ui.stepper.busyLabel:Checking`, + progressLabel: (current, total) => $localize`:@@ui.stepper.progressLabel:Step ${current}:current: of ${total}:total:` + }; +} /** * The values every stepper below this injector uses when its inputs are not set. @@ -22,7 +29,7 @@ const DEFAULT_STEPPER_CONFIG: StepperConfig = { */ export const STEPPER_CONFIG: InjectionToken = new InjectionToken('STEPPER_CONFIG', { providedIn: 'root', - factory: () => DEFAULT_STEPPER_CONFIG + factory: () => getDefaultStepperConfig() }); /** @@ -36,7 +43,7 @@ export function provideStepperConfig(config: Partial): Provider { return { provide: STEPPER_CONFIG, useFactory: (): StepperConfig => ({ - ...inject(STEPPER_CONFIG, { skipSelf: true, optional: true }) ?? DEFAULT_STEPPER_CONFIG, + ...inject(STEPPER_CONFIG, { skipSelf: true, optional: true }) ?? getDefaultStepperConfig(), ...config }) }; diff --git a/projects/ui/table-of-contents/table-of-contents-config.provider.ts b/projects/ui/table-of-contents/table-of-contents-config.provider.ts index 65e651e..d342972 100644 --- a/projects/ui/table-of-contents/table-of-contents-config.provider.ts +++ b/projects/ui/table-of-contents/table-of-contents-config.provider.ts @@ -2,12 +2,19 @@ import { inject, InjectionToken, Provider } from '@angular/core'; import { TableOfContentsConfig } from './table-of-contents-config.model'; -// the label of the anchors of @service-soft/ngx-navigation, which link to the sections of a page as well. -const DEFAULT_TABLE_OF_CONTENTS_CONFIG: TableOfContentsConfig = { - label: 'On this page', - levels: [2, 3], - spy: true -}; +/** + * The values of a table of contents when nothing changes them. Its label is $localize, which an app translates like its + * own texts, and resolved once the config is injected, so translations an app loads at runtime apply as well. + * @returns The default config. + */ +function getDefaultTableOfContentsConfig(): TableOfContentsConfig { + return { + // the label of the anchors of @service-soft/ngx-navigation, which link to the sections of a page as well. + label: $localize`:@@ui.table-of-contents.label:On this page`, + levels: [2, 3], + spy: true + }; +} /** * The values every table of contents below this injector uses when its inputs are not set. @@ -17,7 +24,7 @@ export const TABLE_OF_CONTENTS_CONFIG: InjectionToken = n 'TABLE_OF_CONTENTS_CONFIG', { providedIn: 'root', - factory: () => DEFAULT_TABLE_OF_CONTENTS_CONFIG + factory: () => getDefaultTableOfContentsConfig() } ); @@ -32,7 +39,7 @@ export function provideTableOfContentsConfig(config: Partial ({ - ...inject(TABLE_OF_CONTENTS_CONFIG, { skipSelf: true, optional: true }) ?? DEFAULT_TABLE_OF_CONTENTS_CONFIG, + ...inject(TABLE_OF_CONTENTS_CONFIG, { skipSelf: true, optional: true }) ?? getDefaultTableOfContentsConfig(), ...config }) }; diff --git a/projects/ui/table/table-config.provider.ts b/projects/ui/table/table-config.provider.ts index 2d43d7c..79ef1c9 100644 --- a/projects/ui/table/table-config.provider.ts +++ b/projects/ui/table/table-config.provider.ts @@ -2,24 +2,31 @@ import { inject, InjectionToken, Provider } from '@angular/core'; import { TableConfig } from './table-config.model'; -const DEFAULT_TABLE_CONFIG: TableConfig = { - pageSize: 10, - pageSizes: [10, 25, 50, 100], - variant: 'outlined', - striped: false, - selectAllLabel: 'Select all rows of this page', - selectRowLabel: 'Select', - filterLabel: column => `Filter ${column}`, - allLabel: 'All', - filtersLabel: 'Filters', - removeFilterLabel: filter => `Remove filter ${filter}`, - paginationLabel: table => `Pages of ${table}`, - rangeLabel: (first, last, total) => `Showing ${first}–${last} of ${total}`, - pageSizeLabel: 'Rows per page', - actionsLabel: 'Actions', - noRowsLabel: 'Nothing found.', - loadingLabel: 'Loading' -}; +/** + * The values of a table when nothing changes them. Its texts are $localize, which an app translates like its own, and + * resolved once the config is injected, so translations an app loads at runtime apply as well. + * @returns The default config. + */ +function getDefaultTableConfig(): TableConfig { + return { + pageSize: 10, + pageSizes: [10, 25, 50, 100], + variant: 'outlined', + striped: false, + selectAllLabel: $localize`:@@ui.table.selectAllLabel:Select all rows of this page`, + selectRowLabel: $localize`:@@ui.table.selectRowLabel:Select`, + filterLabel: column => $localize`:@@ui.table.filterLabel:Filter ${column}:column:`, + allLabel: $localize`:@@ui.table.allLabel:All`, + filtersLabel: $localize`:@@ui.table.filtersLabel:Filters`, + removeFilterLabel: filter => $localize`:@@ui.table.removeFilterLabel:Remove filter ${filter}:filter:`, + paginationLabel: table => $localize`:@@ui.table.paginationLabel:Pages of ${table}:table:`, + rangeLabel: (first, last, total) => $localize`:@@ui.table.rangeLabel:Showing ${first}:first:–${last}:last: of ${total}:total:`, + pageSizeLabel: $localize`:@@ui.table.pageSizeLabel:Rows per page`, + actionsLabel: $localize`:@@ui.table.actionsLabel:Actions`, + noRowsLabel: $localize`:@@ui.table.noRowsLabel:Nothing found.`, + loadingLabel: $localize`:@@ui.table.loadingLabel:Loading` + }; +} /** * The values every table below this injector uses when its inputs are not set, and its texts. @@ -27,7 +34,7 @@ const DEFAULT_TABLE_CONFIG: TableConfig = { */ export const TABLE_CONFIG: InjectionToken = new InjectionToken('TABLE_CONFIG', { providedIn: 'root', - factory: () => DEFAULT_TABLE_CONFIG + factory: () => getDefaultTableConfig() }); /** @@ -41,7 +48,7 @@ export function provideTableConfig(config: Partial): Provider { return { provide: TABLE_CONFIG, useFactory: (): TableConfig => ({ - ...inject(TABLE_CONFIG, { skipSelf: true, optional: true }) ?? DEFAULT_TABLE_CONFIG, + ...inject(TABLE_CONFIG, { skipSelf: true, optional: true }) ?? getDefaultTableConfig(), ...config }) }; diff --git a/projects/ui/tsconfig.lib.json b/projects/ui/tsconfig.lib.json index 2ae54a6..c2dd61e 100644 --- a/projects/ui/tsconfig.lib.json +++ b/projects/ui/tsconfig.lib.json @@ -5,7 +5,7 @@ "declaration": true, "declarationMap": true, "outDir": "../../out-tsc/lib", - "types": [] + "types": ["@angular/localize"] }, "exclude": ["**/*.spec.ts", "**/*.stories.ts", ".storybook", "test-setup.ts"], "extends": "../../tsconfig.json", diff --git a/projects/ui/tsconfig.spec.json b/projects/ui/tsconfig.spec.json index 88ee701..6be3646 100644 --- a/projects/ui/tsconfig.spec.json +++ b/projects/ui/tsconfig.spec.json @@ -3,7 +3,7 @@ { "compilerOptions": { "outDir": "../../out-tsc/spec", - "types": ["vitest/globals"] + "types": ["vitest/globals", "@angular/localize"] }, "extends": "../../tsconfig.json", "include": ["**/*.d.ts", "**/*.spec.ts", "test-setup.ts"] diff --git a/tests/accessibility.spec.ts b/tests/accessibility.spec.ts index 360ea8d..4b90987 100644 --- a/tests/accessibility.spec.ts +++ b/tests/accessibility.spec.ts @@ -3,9 +3,9 @@ import { AxeResults } from 'axe-core'; import { Browser, BrowserContext, chromium, Page } from 'playwright'; import { afterAll, beforeAll, describe, expect, test } from 'vitest'; +import { PAGE_LEVEL_RULES } from '../projects/ui/.storybook/page-level-rules'; import { StoryIndexEntry } from './story-index-entry.model'; import { StorybookUtilities } from './storybook.utilities'; -import { PAGE_LEVEL_RULES } from '../projects/ui/.storybook/page-level-rules'; /** * A story and the color scheme of the operating system it gets checked in. diff --git a/tests/entity-arrays.spec.ts b/tests/entity-arrays.spec.ts index 53af778..5af47e4 100644 --- a/tests/entity-arrays.spec.ts +++ b/tests/entity-arrays.spec.ts @@ -3,8 +3,8 @@ import { AxeResults } from 'axe-core'; import { Browser, BrowserContext, chromium, Locator, Page } from 'playwright'; import { afterAll, beforeAll, describe, expect, test } from 'vitest'; -import { StorybookUtilities } from './storybook.utilities'; import { PAGE_LEVEL_RULES } from '../projects/ui/.storybook/page-level-rules'; +import { StorybookUtilities } from './storybook.utilities'; // a real browser, because the dialog of an item is a modal one, and where the focus goes is the point. describe('entity arrays in the browser', () => {