Registry / web-framework / ngx-translate-messageformat-compiler

ngx-translate-messageformat-compiler

JSON →
library7.2.0jsnpmunverified

Compiler for ngx-translate that uses messageformat.js to compile translations using ICU syntax for handling pluralization and gender. Current stable version is 7.2.0, released under an MIT license with monthly releases. Key differentiators: supports Angular 13+, ngx-translate 14-17, and messageformat 3; provides MESSAGE_FORMAT_CONFIG token for custom formatters and options; enables ICU pluralization and gender selection in ngx-translate projects. Requires unsafe-eval CSP for runtime compilation.

npm install ngx-translate-messageformat-compiler
INSTALL
IMPORT
SIG · NGX-TRANSLATE-MESS
N
ngx-translate-messageformat-compiler
web-frameworkjavascriptv7.2.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

TranslateMessageFormatCompiler
import { TranslateMessageFormatCompiler } from 'ngx-translate-messageformat-compiler'
const { TranslateMessageFormatCompiler } = require('ngx-translate-messageformat-compiler')
ESM-only module; use named import
MESSAGE_FORMAT_CONFIG
import { MESSAGE_FORMAT_CONFIG } from 'ngx-translate-messageformat-compiler'
import { MESSAGE_FORMAT_CONFIG } from '@ngx-translate/core'
Injection token from this library, not from ngx-translate
TranslateMessageFormatCompiler
import { TranslateMessageFormatCompiler } from 'ngx-translate-messageformat-compiler'
import TranslateMessageFormatCompiler from 'ngx-translate-messageformat-compiler'
Default export not available; must use named import

Setup ngx-translate-messageformat-compiler in Angular standalone bootstrap with custom config

import { bootstrapApplication } from '@angular/platform-browser'; import { provideTranslateCompiler, provideTranslateService } from '@ngx-translate/core'; import { TranslateMessageFormatCompiler, MESSAGE_FORMAT_CONFIG } from 'ngx-translate-messageformat-compiler'; import { MyAppComponent } from './my-app.component'; bootstrapApplication(MyAppComponent, { providers: [ provideTranslateService({ compiler: provideTranslateCompiler(TranslateMessageFormatCompiler), }), { provide: MESSAGE_FORMAT_CONFIG, useValue: { throwOnError: true, formatters: { upcase: (v) => v.toUpperCase() }, }, }, ], });
Debug
Known issues
gotchaICU runtime compilation requires unsafe-eval CSP directive
fix
Add 'unsafe-eval' to script-src Content-Security-Policy header
affects: >=1.0.0
breakingVersion 7 requires @ngx-translate/core ^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0 and @messageformat/core ^3.2.0
fix
Update peer dependencies to match required versions
affects: 7.0.0 - 7.2.0
deprecatedOlder versions (pre-7) used different config object structure
fix
Upgrade to v7 and use MESSAGE_FORMAT_CONFIG token
affects: <7.0.0
gotchaMESSAGE_FORMAT_CONFIG keys differ from MessageFormat options (e.g., biDiSupport not biDiSupport)
fix
Use MESSAGE_FORMAT_CONFIG keys as documented, not raw MessageFormat option names
affects: >=1.0.0
gotchaPlaceholder syntax differs from ngx-translate default (ICU vs {{ }}); ngx-translate translate pipe/directive works but requires ICU syntax in translation values
fix
Use ICU syntax like {{ count, plural, =1 {one} other {# other} }} instead of ngx-translate native interpolation
affects: >=1.0.0
Errors
Common errors & fixes
ERROR Error: Uncaught (in promise): TypeError: messageformat_compiler_1.TranslateMessageFormatCompiler is not a constructor
Node require() used with ESM-only package
fix
Switch to ESM import syntax: import { TranslateMessageFormatCompiler } from 'ngx-translate-messageformat-compiler'
NullInjectorError: No provider for MESSAGE_FORMAT_CONFIG
Missing provider for MESSAGE_FORMAT_CONFIG injection token
fix
Add { provide: MESSAGE_FORMAT_CONFIG, useValue: {...} } to providers array
Upgrade
Version history
7.2.0latest on npm
Audit
Dependencies
@angular/corerequiredPeer dependency for Angular framework features
@messageformat/corerequiredPeer dependency for messageformat compilation
@ngx-translate/corerequiredPeer dependency for ngx-translate integration
Agent activity
12 hits · last 30 days
node
10
OpenAI (training)
2
Resources
ngx-translate-messageformat-compiler — npm install ngx-translate-messageformat-compiler · libregistry