Nested dynamic values within messages #33
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Added the parameters property, which makes possible to insert text (which requires no translations, such as numbers, names, dates) within messages. This feature exists in other frameworks such as Spring MVC and its MessageSource class.
Let's say we want to have a message like this: Hello, my name is John Doe and I am from Seattle.
In this example we have "John Doe" and "Seattle" as values which requires no translation. Actually, these values could come as dynamic values using {{}} or [[]]. So, in order to translate this kind of sentence it was required at least two messages, one for "Hello, my name is " and one for " and I am from ".
With the parameters property it's possible to insert both values within a unique message. To achieve this, the message in the locale should be writen as follows:
Hello, my name is $0 and I am from $1
Where $n is a pattern where the values will be inserted, being n a numeric value starting at zero. In the HTML the tag must be declared like this:
<i18n-msg id="hello" parameters="John Doe;;Seattle"></i18n-msg>
The values in parameters replace the patterns in the same numeric order they were declared in the message. In this case, $0 is replaced by "John Doe" and $1 is replaced by "Seattle". Also, it's possible to use dynamic values:
<i18n-msg id="hello" parameters="{{user.name}};;{{user.city}}"></i18n-msg>
TODO: create test for this feature and include in demo.
P.D.: sorry if my english is a bit confusing... I'm from Spain, actually it's a miracle I can write like this :P
Any suggestions for the code (and my writting skills) are welcome. ;)