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

Nested dynamic values within messages #33

Closed
wants to merge 1 commit into from

Conversation

benjaminpg
Copy link

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. ;)

…ires no translations, such as numbers, names, dates) within message. TODO: create test for this feature and include in demo.
@ebidel
Copy link
Owner

ebidel commented Feb 26, 2016

Can you rebase?

@ebidel
Copy link
Owner

ebidel commented Feb 26, 2016

There's a PR for placeholders already: #25

What I like about it is that it follows the the chrome.18n API. Much of this component is already based off that API, so I'd like to stick to it for consistency.

@ebidel ebidel closed this Feb 26, 2016
@benjaminpg
Copy link
Author

I based my placeholders approach to the one used in Spring MVC. Nonetheless I see that the Chrome API may use a more efficient method to detect the placeholders, not like mine which requires a .match to detect if the message contains placeholders or not.

@benjaminpg
Copy link
Author

BTW, by rebase you mean pull --rebase or plain rebase?

@benjaminpg benjaminpg mentioned this pull request Mar 1, 2016
@ebidel
Copy link
Owner

ebidel commented Mar 1, 2016

Yea, git rebase master after you pull the upstream changes

@benjaminpg
Copy link
Author

Rebase done for #35

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants