Skip to content

Commit 0fb98b0

Browse files
authored
Merge pull request #124 from lephyrus/ngx-translate-v17
Support ngx-translate v17
2 parents eecf75f + b7f5912 commit 0fb98b0

12 files changed

+7605
-10492
lines changed

.github/workflows/build.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ jobs:
2323
run: npm ci
2424
- name: Lint
2525
run: npm run lint
26+
- name: Check formatting
27+
run: npm run format
2628
- name: Test
2729
run: npm run test
2830
- name: Build for production

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,17 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
66
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
77

8+
## [7.2.0] - 2025-08-03
9+
10+
### Added
11+
12+
- Support ngx-translate v17 (#122)
13+
14+
### Changed
15+
16+
- Migrate docs and example app to standalone bootstrapping and provider
17+
functions
18+
819
## [7.1.0] - 2024-12-29
920

1021
### Added

README.md

Lines changed: 31 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
[![npm version](https://badge.fury.io/js/ngx-translate-messageformat-compiler.svg)](https://www.npmjs.com/package/ngx-translate-messageformat-compiler) ![build](https://github.com/lephyrus/ngx-translate-messageformat-compiler/workflows/build/badge.svg) [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
66

7-
**[Example App](https://stackblitz.com/edit/ngx-translate-messageformat-compiler-example)** (StackBlitz)
7+
**[Example App](https://stackblitz.com/edit/stackblitz-starters-bunksjia?file=src%2Fapp%2Fapp.component.ts)** (StackBlitz)
88

99
## Table of Contents
1010

@@ -31,34 +31,41 @@ In the current version, this library supports Angular versions 13+, ngx-translat
3131

3232
### Integration with ngx-translate
3333

34-
You need to configure `TranslateModule` so it uses `TranslateMessageFormatCompiler` as the compiler:
34+
You need to provide `TranslateMessageFormatCompiler` as the compiler:
3535

3636
```ts
37-
import { NgModule } from "@angular/core";
38-
import { BrowserModule } from "@angular/platform-browser";
39-
import { TranslateCompiler, TranslateModule } from "@ngx-translate/core";
40-
import { TranslateMessageFormatCompiler } from "ngx-translate-messageformat-compiler";
41-
42-
import { AppComponent } from "./app";
43-
44-
@NgModule({
45-
imports: [
46-
BrowserModule,
47-
TranslateModule.forRoot({
48-
compiler: {
49-
provide: TranslateCompiler,
50-
useClass: TranslateMessageFormatCompiler,
51-
},
37+
import { bootstrapApplication } from "@angular/platform-browser";
38+
39+
import {
40+
provideTranslateCompiler,
41+
provideTranslateService,
42+
} from "@ngx-translate/core";
43+
import {
44+
TranslateMessageFormatCompiler,
45+
MESSAGE_FORMAT_CONFIG,
46+
} from "ngx-translate-messageformat-compiler";
47+
48+
import { MyAppComponent } from "./my-app.component";
49+
50+
bootstrapApplication(MyAppComponent, {
51+
providers: [
52+
provideTranslateService({
53+
compiler: provideTranslateCompiler(TranslateMessageFormatCompiler),
5254
}),
55+
// injecting a config is optional, and any values provided here will
56+
// override the defaults (see below)
57+
{
58+
provide: MESSAGE_FORMAT_CONFIG,
59+
useValue: {
60+
throwOnError: true,
61+
formatters: { upcase: (v) => v.toUpperCase() },
62+
},
63+
},
5364
],
54-
bootstrap: [AppComponent],
55-
})
56-
export class AppModule {}
65+
});
5766
```
5867

59-
Check the [ngx-translate documentation](https://ngx-translate.org/reference/configuration/#standalone-components) for an example when using a "standalone" setup.
60-
61-
You can override the values used when configuring MessageFormat by providing a configuration object for the `MESSAGE_FORMAT_CONFIG` injection token. Here's the default:
68+
You can override the values used by the plugin to configure MessageFormat by providing a configuration object for the `MESSAGE_FORMAT_CONFIG` injection token. Here's the default:
6269

6370
```ts
6471
{
@@ -76,22 +83,6 @@ You can override the values used when configuring MessageFormat by providing a c
7683

7784
MessageFormat instances provide some options to influence its behaviour, among them `customFormatters`, `biDiSupport` and `strict`. Learn about their meaning here: <https://messageformat.github.io/messageformat/api/core.messageformatoptions/> (The names used in the MESSAGE_FORMAT_CONFIG object are slightly different for backward-compatibility reasons.)
7885

79-
This is how you would enable bi-directional support and add a custom formatter, for example:
80-
81-
```ts
82-
import { MESSAGE_FORMAT_CONFIG } from 'ngx-translate-messageformat-compiler';
83-
84-
@NgModule({
85-
// ...
86-
providers: [{
87-
provide: MESSAGE_FORMAT_CONFIG,
88-
useValue: {
89-
biDiSupport: true,
90-
formatters: { upcase: v => v.toUpperCase() }
91-
}
92-
}]
93-
```
94-
9586
## Usage
9687

9788
This library implements neither the syntax used for pluralization (et al) nor the "mechanics" for making translations work in your Angular app. The former is _MessageFormat_, the latter _ngx-translate_. Before you assume your problem is with _ngx-translate-messageformat-compiler_, please consult these ressources:
@@ -106,20 +97,7 @@ Here's two important differences to _ngx-translate_'s default syntax when using
10697

10798
### Transitioning from _ngx-translate_ default syntax to _MessageFormat_ syntax
10899

109-
If you have to transition on a message-by-message basis, you can do so by configuring a prefix that, if found on the message, will cause the compiler to "ignore" the message. This has the effect of falling back on _ngx-translate_'s default message interpolation.
110-
111-
```ts
112-
import { MESSAGE_FORMAT_CONFIG } from 'ngx-translate-messageformat-compiler';
113-
114-
@NgModule({
115-
// ...
116-
providers: [{
117-
provide: MESSAGE_FORMAT_CONFIG,
118-
useValue: {
119-
fallbackPrefix: 'your_choice::'
120-
}
121-
}]
122-
```
100+
If you have to transition on a message-by-message basis, you can do so by configuring a prefix that, if found on the message, will cause the compiler to "ignore" the message. This has the effect of falling back on _ngx-translate_'s default message interpolation. Set the prefix using `fallbackPrefix` in the configuration object, e.g. `fallbackPrefix: 'your_choice::'`.
123101

124102
```json
125103
{

angular.json

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"prefix": "lib",
1111
"architect": {
1212
"build": {
13-
"builder": "@angular-devkit/build-angular:ng-packagr",
13+
"builder": "@angular/build:ng-packagr",
1414
"options": {
1515
"tsConfig": "tsconfig.lib.json",
1616
"project": "ng-package.json"
@@ -22,7 +22,7 @@
2222
}
2323
},
2424
"test": {
25-
"builder": "@angular-devkit/build-angular:karma",
25+
"builder": "@angular/build:karma",
2626
"options": {
2727
"main": "src/test.ts",
2828
"tsConfig": "tsconfig.spec.json",
@@ -32,19 +32,40 @@
3232
"lint": {
3333
"builder": "@angular-eslint/builder:lint",
3434
"options": {
35-
"lintFilePatterns": [
36-
"./**/*.ts",
37-
"./**/*.html"
38-
]
35+
"lintFilePatterns": ["./**/*.ts", "./**/*.html"]
3936
}
4037
}
4138
}
4239
}
4340
},
4441
"cli": {
45-
"schematicCollections": [
46-
"@angular-eslint/schematics"
47-
],
42+
"schematicCollections": ["@angular-eslint/schematics"],
4843
"analytics": false
44+
},
45+
"schematics": {
46+
"@schematics/angular:component": {
47+
"type": "component"
48+
},
49+
"@schematics/angular:directive": {
50+
"type": "directive"
51+
},
52+
"@schematics/angular:service": {
53+
"type": "service"
54+
},
55+
"@schematics/angular:guard": {
56+
"typeSeparator": "."
57+
},
58+
"@schematics/angular:interceptor": {
59+
"typeSeparator": "."
60+
},
61+
"@schematics/angular:module": {
62+
"typeSeparator": "."
63+
},
64+
"@schematics/angular:pipe": {
65+
"typeSeparator": "."
66+
},
67+
"@schematics/angular:resolver": {
68+
"typeSeparator": "."
69+
}
4970
}
5071
}

eslint.config.mjs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { globalIgnores } from "eslint/config";
2+
import js from "@eslint/js";
3+
import angularPlugin from "angular-eslint";
4+
import tseslint from "typescript-eslint";
5+
6+
export default tseslint.config(
7+
globalIgnores(["**/dist"]),
8+
js.configs.recommended,
9+
tseslint.configs.recommendedTypeChecked,
10+
tseslint.configs.strictTypeChecked,
11+
angularPlugin.configs.tsRecommended,
12+
{
13+
files: ["**/*.ts"],
14+
languageOptions: {
15+
parserOptions: {
16+
projectService: true,
17+
tsconfigRootDir: import.meta.dirname,
18+
},
19+
},
20+
},
21+
{
22+
files: ["**/*.{js,mjs,cjs}"],
23+
extends: [tseslint.configs.disableTypeChecked],
24+
},
25+
{
26+
rules: {
27+
"@angular-eslint/prefer-inject": "warn",
28+
"@typescript-eslint/no-explicit-any": "off",
29+
"@typescript-eslint/no-unsafe-argument": "off",
30+
"@typescript-eslint/no-unsafe-assignment": "off",
31+
"@typescript-eslint/no-unsafe-member-access": "off",
32+
"@typescript-eslint/no-unsafe-return": "off",
33+
"no-console": "error",
34+
},
35+
},
36+
{
37+
files: ["**/*.spec.ts"],
38+
rules: {
39+
"@typescript-eslint/no-floating-promises": "off",
40+
"@typescript-eslint/no-unsafe-call": "off",
41+
},
42+
},
43+
);

karma.conf.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,14 @@ module.exports = function (config) {
1010
require("karma-chrome-launcher"),
1111
require("karma-jasmine-html-reporter"),
1212
require("karma-coverage-istanbul-reporter"),
13-
require("@angular-devkit/build-angular/plugins/karma"),
1413
],
1514
client: {
1615
clearContext: false, // leave Jasmine Spec Runner output visible in browser
1716
},
1817
coverageIstanbulReporter: {
1918
dir: require("path").join(
2019
__dirname,
21-
"../../coverage/ngx-translate-messageformat-compiler"
20+
"../../coverage/ngx-translate-messageformat-compiler",
2221
),
2322
reports: ["html", "lcovonly", "text-summary"],
2423
fixWebpackSourcePaths: true,

0 commit comments

Comments
 (0)