ebidel / i18n-msg

Polymer element for i18n string replacement
https://ebidel.github.io/i18n-msg/
63 stars 21 forks source link

support placeholders similar to Chrome.i18n APIs #39

Open kvsrohit opened 8 years ago

kvsrohit commented 8 years ago

Hi Eric, I've redone benjaminpg's changes on latest clone with minor changes and slight variation on demo and test cases. You may want to checkout.

Cheers//rohit

kvsrohit commented 8 years ago

Placeholders

It's possible to insert text within the message which requires no translation (e.g: names, dates, numbers). To make available the use of placeholders the message must contain placeholders in Chrome.i18n format ($name$) whenever a parameter should be used, and to use these add the attribute "placeholders" having value array. Example:

"error": {
    "message": "Error: $details$",
    "description": "Generic error template. Expects error parameter to be passed in.",
    "placeholders": {
        "details": {
            "content": "$1",
            "example": "Failed to fetch RSS feed."
        }
   }
}

<i18-msg msgid="error" placeholders='["Failed to fetch data."]'></i18n-msg>

It's also possible to use {{}} and [[]] within the placeholders.