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.

Recursive Translation & Interpolation

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
[x] support request => check the FAQ and search github for a similar issue before submitting
[ ] feature request

Current behavior Support for parameters to be added/interpolated to another translated string is fine.

Expected/desired behavior The parameters which need to be added to the translated string might need to be translated themselves.

Reproduction of the problem I have various output on a form for errors. The field names are added into the output error string as a parameter:

en.json

{
    "GENERAL": {
        "ERROR": "The {field} field has an error"
    },
    "FIELDS":{
        "FIRSTNAME": "First Name"
    }
}

component.html

<p *ngIf="errors" translate [translateParams]="{field: labels[key]}">
    GENERAL.ERROR
</p>

What is the expected behavior? The ‘field’ parameter should be catered for translation too, as for now, the field names would only be in English.

What is the motivation / use case for changing the behavior? By allowing the key for another field to be translated too, a more dynamic translation implementation could be achieved.

Is it possible to achieve something like this without referencing the TranslateService in a components class to translate the labels prior to adding them as parameters for another string to be translated in the components template?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:3
  • Comments:5

github_iconTop GitHub Comments

1reaction
CodeAndWebcommented, Apr 12, 2018

Currently not - sorry. It would require creating a quite complex way of handling the strings. Especially if user input contains {} and triggers other unwanted replacements…

0reactions
jarodsmkcommented, Apr 12, 2018

@CodeAndWeb ok cool thanks man, was just wanting to know why 😛 does make sense though

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 >
A general approach to multivariable recursive interpolation
We consider here the problem of constructing a general recursive algorithm to interpolate a given set of data with a rational function.
Read more >
How do I implement recursive interpolation ($) for string macros?
The problem is, this only works one level. While normal string interpolation works any number of levels, it doesn't work with string macros....
Read more >
Recursive Graphics, Bi/Tri-linear Interpolation, Anti-aliasing ...
Our task is to implement a recursive function sierpinski(). We need to think recursively: our function should draw one black triangle (pointed ...
Read more >
A Recursive Method For Solving Unconstrained Tangential ...
translate the interpolation data into a so-called left null pair that describes the zero structure of a rational matrix function denoted by.
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