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.

Interpolate strings without a translated value

See original GitHub issue

I’m submitting a … (check one with “x”)

[ ] bug report => check the FAQ and search github for a similar issue or PR before submitting
[ ] support request => check the FAQ and search github for a similar issue before submitting
[x] feature request

Current behavior I’m trying to mimic Gettext behavior:

  • Base language in source is plain english
  • If a translation exists, use it, if not, don’t do anything (in my case, leave the english strings)

This is the default behavior in ng2-translate, so far so good.

Where I’m running into trouble is when I have a string without a translation, that needs interpolation. The string isn’t interpolated which makes sense if you use made-up keys like LOGGED_IN_USER etc, since you wouldn’t need that to be interpolated, but in my case I do.

Do you think that is something this lib could support?

EDIT: Example

<h1>{{ 'This is a string with value "{value}" interpolated' | translate: { value: 'TEST' } }}</h1>

If no translation is available for this message, it will output:

This is a string with value "{value}" interpolated

Instead of what I want:

This is a string with value "TEST" interpolated

(I’m using the new custom TranslateParser to allow me to interpolate {value} in my strings)

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
SamanthaAdrichemcommented, Feb 22, 2022

@Halfist we’re on version 11.0.1 and still somewhat literally use the code above (only a different file name for the handler) However we do not translate using the “GREETING” syntax we translate like so

HTML

<element translate>Hello {{name}}</element>

HTML plurals

<ng-container [ngPlural]="count">
    <ng-template ngPluralCase="=0"><span translate>There are no things</span></ng-template>
    <ng-template ngPluralCase="=1"><span translate>There is 1 thing</span></ng-template>
    <ng-template ngPluralCase="other"><span translate>There are {{count}} things</span></ng-template>
</ng-container>

Typescript

import {TranslateService} from '@ngx-translate/core';

class x {
...
    constructor(
        ...,
        protected translateService: TranslateService,
        ...,
    ) {}
...
    x(): void {
        this.translatedValue = this.translateService.instant('Hello {{name}}', {name: 'name'});
    }
....
}

If you use the greetings syntax you probably need to fix some code in the InterpolatedMissingTranslationHandler

0reactions
SamanthaAdrichemcommented, Feb 21, 2022

@Halfist it was on v9. I will check it for you tomorrow between 9 and 11 CEST and let you know

Read more comments on GitHub >

github_iconTop Results From Across the Web

Interpolation - i18next documentation
Interpolation is one of the most used functionalities in I18N. It allows integrating dynamic values into your translations.
Read more >
How to translate angular interpolation string from container ...
I'm searching the best way to translate my futur angular project so no, my project dosen't use i18n already. But I never see...
Read more >
How to use i18n string interpolation - zargony.com
Here, the translation uses string interpolation to put variable values into a meaningful sentence. The translation string itself is a ...
Read more >
Displaying values with interpolation - Angular
Interpolation refers to embedding expressions into marked up text. By default, interpolation uses the double curly braces {{ and }} as delimiters. To...
Read more >
ngx-translate Documentation - CodeAndWeb
Using a compiler opens the door for powerful pre-processing of translation values. As long as the compiler outputs a compatible interpolation string or...
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