
Product
A Fresh Look for the Socket Dashboard
We’ve redesigned the Socket dashboard with simpler navigation, less visual clutter, and a cleaner UI that highlights what really matters.
ng-merge-i18n
Advanced tools
Default Angular extract-i18n
is just extracting the messages of the source locale.
You need to manually create files for the other locales.
This library will help you to create files of the other locales and merge the translations from the source.
json
format of the translation source.Install as a devDependencies
by following command.
npm install ng-merge-i18n --save-dev
By default, angular.json
has a builder target named extract-i18n
. This library relies on it to get the options.
Make sure to specify the options format
to json
since we're currently support this format.
{
// ...
"projects": {
"project-name": {
// ...
"architect": {
// ...
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "project-name:build",
"format": "json" // <-- Specify format to json
}
}
// ...
}
}
}
}
You can also define the other options such as outputPath
and outFile
. The library will detect those options to get the source file. If not provided, the default value of the extract-i18n
will be used.
outputPath
, default to root directory of your project.outFile
, default to messages.[format]
, example: messages.json
.Define locales on i18n
option in the project (see Angular Internationalization docs).
The translation targets will be placed based on the path you provide for each locale.
{
// ...
"projects": {
"project-name": {
// ...
"i18n": {
"sourceLocale": "en-US", // <-- This is optional
"locales": {
"id": "assets/locales/id.json",
"it": "assets/locales/it.json"
}
},
"architect": {
// ...
}
}
}
}
Notes:
For json
format of the source file, the locale
value will follows the locale key of the locales
.
For example, the locale keys from code example above are id
and it
.
Then the locale value for each locale will use those keys on the translation target files.
// id.json file
{
"locale": "id",
"translations": {}
}
// it.json file
{
"locale": "it",
"translations": {}
}
Add builder target for merging the translations. The builder name is "ng-merge-i18n:merge
".
And the builder target name can be "merge-i18n"
(recommended), but you can name it whatever you want.
{
// ...
"projects": {
"project-name": {
// ...
"architect": {
// ...
"merge-i18n": {
"builder": "ng-merge-i18n:merge"
}
}
}
}
}
Additionally, you can provide the builder options to the target.
{
"merge-i18n": {
"builder": "ng-merge-i18n:merge",
"options": {
// Provide options here. See available options below.
}
}
}
Available builder options:
option | default value | description |
---|---|---|
builderTarget | "extract-i18n" | Provide this option if you're changing the default extract-i18n builder target name. |
sort | "push" | Sort translation messages in target translation files. Supported: - "push" (append new translation messages at the end).- "asc" (sort by id in ascending order). |
removeUnusedTranslation | false | Whether to remove unused translation messages on the target translation files. |
removeSource | false | Whether to remove the translation source file after translation messages have been merged. |
The translation source file need to be exist before merging the translations. So, you need to extract i18n first then merge the translations.
Extract I18n:
npm run ng extract-i18n
Merge Translation:
Should provide the project name that run the target. The format is "ng run [projectName]:merge-i18n"
.
npm run ng run project-name:merge-i18n
Rather than run merge command manually, it can be used as post script in package.json
.
{
"scripts": {
"extract-i18n": "ng extract-i18n",
"postextract-i18n": "ng run project-name:merge-i18n"
}
}
After extracting, it will merge the translations.
v1.0.1 (December 24, 2022)
FAQs
Merge Angular translations from source
The npm package ng-merge-i18n receives a total of 0 weekly downloads. As such, ng-merge-i18n popularity was classified as not popular.
We found that ng-merge-i18n demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
We’ve redesigned the Socket dashboard with simpler navigation, less visual clutter, and a cleaner UI that highlights what really matters.
Industry Insights
Terry O’Daniel, Head of Security at Amplitude, shares insights on building high-impact security teams, aligning with engineering, and why AI gives defenders a fighting chance.
Security News
MCP spec updated with structured tool output, stronger OAuth 2.1 security, resource indicators, and protocol cleanups for safer, more reliable AI workflows.