Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A suggestion for simple, yet efficient variable interpolation in js translations #24

Merged
merged 1 commit into from
Oct 10, 2012

Conversation

tanghus
Copy link
Contributor

@tanghus tanghus commented Oct 5, 2012

Which requires no extra libraries. This is of course for post-4.5, just wanted to get it out of the door while I remembered.

Usage is imo very intuitive:

t('app', 'Bake, uncovered, until the {greasystuff} is melted and the {pasta} is heated through, about {min} minutes.',
    {greasystuff: 'cheese', pasta: 'macaroni', min: 10});

Not that I want to stir up a discussion of whether macaroni is pasta or not, but my mind was totally blank when I should find an example :-P

btw, I can't take credit for it http://stackoverflow.com/questions/1408289/best-way-to-do-variable-interpolation-in-javascript#answer-1408373

@DeepDiver1975
Copy link
Member

I like this approach as translators get a better impression what the variables stand for.

This is much easier to translate
Bake, uncovered, until the {greasystuff} is melted and the {pasta} is heated through, about {min} minutes.

than
Bake, uncovered, until the %1 is melted and the %2 is heated through, about %3 minutes.

@DeepDiver1975
Copy link
Member

Comparing this approach with #16:
Would we get any benefit from using sprintf.js?
http://www.diveintojavascript.com/projects/javascript-sprintf

@tanghus
Copy link
Contributor Author

tanghus commented Oct 8, 2012

From my POV we have the exact same functionality without adding extra libraries and with the added benefit that it easier for translators as you also stated earlier.

DeepDiver1975 added a commit that referenced this pull request Oct 10, 2012
A suggestion for simple, yet efficient variable interpolation in js translations
@DeepDiver1975 DeepDiver1975 merged commit a0c5361 into master Oct 10, 2012
@lock lock bot locked as resolved and limited conversation to collaborators Aug 19, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants