Using ngx-extractor to update the extracted translation files

Currently, our team is developing a website using Angular 6 and Visual Studio Code. The site will eventually support multiple languages, but for now, we are focusing on Swedish and English, with English set as the default language. To extract strings from HTML files, we utilize the xi18n command, while the ngx-extractor command from i18n-polyfill helps us extract strings from TypeScript files.

My dilemma lies in wanting to integrate translation seamlessly into the coding process, rather than treating it as an afterthought at the project's end. I aim to update both HTML and TypeScript strings simultaneously within the translation files. However, the current command I use removes TypeScript strings when running it after extracting HTML strings using xliff.

The commands specified in package.json are:

"scripts": {
    "i18n-extract": "ng xi18n --output-path=locale --out-file messages.xlf --i18n-locale en && xliffmerge",
    "ngx-extract": "ngx-extractor -i ./src/**/*.ts -f xlf -o ./src/locale/messages.xlf --i18n-locale en && xliffmerge"
},
"xliffmergeOptions": {
    "srcDir": "src/locale",
    "genDir": "src/locale",
    "i18nFile": "messages.xlf",
    
    (Additional configuration options were present here.)
(For the complete text with unchanged content, please refer to the original passage provided above.)

Answer №1

If you need to manage localization files, consider using the tool called xliffmerge which is included in this particular package.

The process involves utilizing the following commands:

# Generate xliff files from HTML
ng xi18n --i18nFormat xlf --output-path i18n --i18n-locale en 

# Update generated xliff files with translations from TypeScript
&& ngx-extractor --input src/**/*.ts --format xlf --outFile src/i18n/messages.xlf 

# OPTIONAL: Removing context for a cleaner file - see linked script for details
&& node src/i18n/remove-context.js src/i18n/messages.xlf 

# Merging newly generated file with existing translation files
&& xliffmerge --profile xliffmerge.json`

Our configuration for xliffmerge is set up as follows:

{
  "xliffmergeOptions": {
    "srcDir": "src/i18n",
    "genDir": "src/i18n",
    "defaultLanguage": "en",
    "languages": [
      "en",
      "de"
    ]
  }
}

To witness this in action, visit this link

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How can I ensure I am receiving real-time updates from a Resolver Service by subscribing and staying in sync with the

How can I effectively implement this code without encountering an error? "Property 'resolve' in type 'DocumentaryResolverService' is not assignable to the same property in base type 'Resolve'." import { Documentary } from ...

Tips on avoiding tab selection in ngx-bootstrap

My current setup includes two tabs using ngx-bootstrap as shown below. I am looking to disable the tab functionality programmatically: <tabset> <tab heading="First">Tab 1 content</tab> <tab heading="Second">Tab 2 content< ...

Cannot execute example of type alias in Typescript

While delving into the Typescript documentation, I came across the concept of type alias and found an interesting example here. type DescribableFunction = { description: string; (someArg: number): boolean; }; function doSomething(fn: DescribableFunctio ...

Which server does ng serve rely on with Angular CLI version 1.6.0?

When using Angular CLI 1.6.0, what server is utilized by the command ng serve? ng serve Now that webpack is integrated into the Angular CLI for bundling websites, does this mean ng serve utilizes the webpack-dev-server (a Node.js Express server)? There a ...

The FullCalendar plugin on the list was experiencing functionality issues

I came across this code snippet that is causing me some trouble: .... import { FullCalendarComponent } from '@fullcalendar/angular'; import { EventInput } from '@fullcalendar/core'; import dayGridPlugin from '@fullcalendar/daygrid& ...

Issue with `rxjs/Subject.d.ts`: The class `Subject<T>` is incorrectly extending the base class `Observable<T>`

I found a sample template code in this helpful tutorial and followed these two steps to get started - npm install // everything went smoothly, created node_modules folder with all dependencies npm start // encountered an error as shown below- node_mo ...

The Ionic 4 Angular App functions perfectly on Ionic devices, however, when attempting to build for the browser, it displays a frustrating

I've been working on developing an Angular/Ionic 4 app for the browser. While everything seems to be running smoothly when I use "ionic serve," the real trouble starts when I try building the app with: ionic cordova build browser --prod --release --d ...

Can the dimensions of a dialog be customized in Angular Material Design for Angular 5?

I am currently developing a login feature for an Angular 5 application. As part of this, I have implemented an Angular Material Design popup. Within the dialog screen, I have a specific process in place: The system checks the user's email to determi ...

What is the process for generating an object type that encompasses all the keys from an array type?

In my coding journey, I am exploring the creation of a versatile class that can define and handle CRUD operations for various resources. The ultimate goal is to have a single generic class instance that can be utilized to generate services, reducer slices, ...

Building a Next.js application that supports both Javascript and Typescript

I currently have a Next.js app that is written in Javascript, but I am looking to transition to writing new code in Typescript. To add Typescript to my project, I tried creating a tsconfig.json file at the project root and then ran npm install --save-dev ...

Unexpected Error: Serverless detecting undefined IdToken in AWS Cognito

I am currently in the process of constructing a login system that utilizes ApiGateway, Lambda function, and Cognito. I have developed a login API that issues a token id upon successful authentication export async function login( event: APIGatewayEvent, ...

Troubleshooting: Why is my Datatables data not showing up with Angular 2/4 server side processing

Angular version 4.2.4 Angular-Datatables version 4.2.0 HTML Code Snippet <table datatable [dtOptions]="dtOptions"></table> Component Function ngOnInit() { this.dtOptions = { ajax: { url: "http://localhost:8880/nmets ...

Troubleshooting: Issue with implementing BehaviorSubject and async pipe in Angular component extension

While working on my code, I encountered an issue where I couldn't get the parent component's async pipe to trigger from a child component in order to update the view. To better explain this problem, let me show you a simplified version of my code ...

Reasons behind the lack of proper styling in my p-calendar from PrimeNG

Currently deep diving into Angular for a project and I decided to incorporate the <p-calendar> component from primeng. After installing the necessary packages, the versions were: "primeicons": "^2.0.0", "primeng": "^5.2.7", Initially everything was ...

When trying to open the phonegap-plugin-barcodescanner on Android Studio with Ionic 6 and Capacitor, I encounter an error

Encountered an issue while trying to build the app in Android Studio. The error message "Could not find method compile() for arguments [{name=barcodescanner-release-2.1.5, ext=aar}] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.Defau ...

Angular 2 Twitter integration plugin

I attempted to integrate a Twitter timeline into my Angular 2 application. I followed the instructions provided on , and this is what I ended up with: <a class="twitter-timeline" href="https://twitter.com/TwitterDev">Tweets by TwitterDev</a> & ...

Connecting a pre-existing Angular 2 application to a Node.js server: A step-by-step guide

I am currently working on an Angular 2 application with the following structure : View Structure of my Angular app Furthermore, on the server side : View Structure of server app I have noticed that there are two module dependencies folders, but I am un ...

Finding the total of values within an array in Angular 2 and Ionic 2 by utilizing *ngfor

As I work on developing a mobile application using Ionic 2, my current task involves calculating the total allocation sum (Course.allocation) for each year per horse in the database. For instance: Table: Course (Race): [Id_course: 1, allocation: 200, dat ...

Angular Firebase Count of Items in List

My current dilemma revolves around obtaining a count of items within a firebase list. Firebase details: foods randompushid title: apple, comboQuery: apple23523526(userid) Angular Code snippet: this.foods= this.firebaseDB.list(& ...

Combining various POST requests by matching the common value in each array. (Angular)

Here are the two different sets of data: "statusCode": 200, "data": [ { "color": { "id": "1111", "name": null, "hex&quo ...