question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Translation stops after first language change

See original GitHub issue

I’m submitting a bug report.

Angular Version: 7.2.12

Library Version: 2.9.0 Browser: all

Language: TypeScript 3.2.4

Context: I am currently trying to translate data in my table.

What I have done:

  1. I have enabled translate in my Grid Options.
  2. I have added “headerKey” in my Column Definitions to translate my header titles.
  3. I have created my own custom formatters to custom dates and currency.
  4. I have added “labelKey” to translate my dropdown filter menu.

Current behavior: On the first page load, everything is translated fine. When switching the language for the FIRST time, after the load, everything is still translated fine. But now, after switching the language for a SECOND, THIRD, +, nothing gets translated. (i.e, if I was in English on the first load, the data will show in English, then if I switch to French, the data will show in French, but afterwards, when I switch the language X number of times, the data will stick to French even if the language is English.

Expected behavior: The data should switch language even after the first language switch.

My solution: To fix this issue, I have added my column definitions to my language change listener, on top of having it in my ngOnInit().

ngOnInit() {

        this.columnDefinitions = [
            { id: 'Date', name: 'Date', field: 'transactionDate', sortable: true, exportWithFormatter: true, formatter: this.translateDate },
            {
                id: 'Type', name: 'Type', field: 'activity', formatter: Formatters.translate, sortable: true, exportWithFormatter: true, filterable: true, filter: {
                    collection: [{ value: '', labelKey: 'ALL' }, { value: 'BUY', labelKey: 'BUY' }, { value: 'SELL', labelKey: 'SELL' }],
                    model: Filters.singleSelect, enableTranslateLabel: true
            } },
            { id: 'Quantity', name: 'Quantity', field: 'quantity', headerKey: 'QUANTITY', sortable: true },
            { id: 'Description', name: 'Description', field: 'description', sortable: true },
            {
                id: 'Symbol', name: 'Symbol', field: 'symbol', headerKey: 'SYMBOL', cssClass: 'symbol-input', sortable: true, filterable: true, filter: {
                    model: Filters.inputText,
                }
                },
            { id: 'Price', name: 'Price', field: 'price', headerKey: 'PRICE', exportWithFormatter: true, formatter: this.translateCurrency, sortable: true },
            { id: 'Comm', name: 'Comm', field: 'commission', exportWithFormatter: true, formatter: this.translateCurrency, sortable: true },
            { id: 'Amount', name: 'Amount', field: 'netAmount', headerKey: 'AMOUNT', exportWithFormatter: true, formatter: this.translateCurrency, sortable: true }
        ];
    }

@HostListener('document:langChanged', ['$event'])
    updateAccountNames(event) {
        this.columnDefinitions = [
            { id: 'Date', name: 'Date', field: 'transactionDate', sortable: true, exportWithFormatter: true, formatter: this.translateDate },
            {
                id: 'Type', name: 'Type', field: 'activity', formatter: Formatters.translate, sortable: true, exportWithFormatter: true, filterable: true, filter: {
                    collection: [{ value: '', labelKey: 'ALL' }, { value: 'BUY', labelKey: 'BUY' }, { value: 'SELL', labelKey: 'SELL' }],
                    model: Filters.singleSelect, enableTranslateLabel: true
                }
            },
            { id: 'Quantity', name: 'Quantity', field: 'quantity', headerKey: 'QUANTITY', sortable: true },
            { id: 'Description', name: 'Description', field: 'description', sortable: true },
            {
                id: 'Symbol', name: 'Symbol', field: 'symbol', headerKey: 'SYMBOL', cssClass: 'symbol-input', sortable: true, filterable: true, filter: {
                    model: Filters.inputText,
                }
            },
            { id: 'Price', name: 'Price', field: 'price', headerKey: 'PRICE', exportWithFormatter: true, formatter: this.translateCurrency, sortable: true },
            { id: 'Comm', name: 'Comm', field: 'commission', exportWithFormatter: true, formatter: this.translateCurrency, sortable: true },
            { id: 'Amount', name: 'Amount', field: 'netAmount', headerKey: 'AMOUNT', exportWithFormatter: true, formatter: this.translateCurrency, sortable: true }
        ];
    }

Thank you!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
marcofortincommented, Jun 19, 2019

Thank you.

Issue solved by adding: this.angularGrid.pluginService.translateColumnHeaders(); in my language switch event.

Best,

0reactions
ghiscodingcommented, Jun 19, 2019

Glad you found a way around.

You can also up vote the lib if you like it ⭐ I’d be nice to make it shine more

Cheers from Montreal 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is English Changing? | Linguistic Society of America
Language is always changing, evolving, and adapting to the needs of its users. ... First, it changes because the needs of its speakers...
Read more >
Forgetting My First Language | The New Yorker
Though Cantonese no longer feels natural for me to speak, it will always be my first language—even if it takes a few translation...
Read more >
Language shift - Wikipedia
Language shift, also known as language transfer or language replacement or language assimilation, is the process whereby a speech community shifts to a ......
Read more >
3 Ways to Put a Stop to Translating in Your Head - FluentU
The best way to stop translating is to surround yourself completely with the language if you can. You'll stop translating over time as...
Read more >
Stop Translating in Your Head: Train Your Brain to Think in a ...
When speaking in a foreign language, translating in your head can slow down your ability to ... (This even works well if your...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found