Add support for placeholders
I need translated strings with placeholders, so I looked at the i18n chrome spec(https://developer.chrome.com/extensions/i18n-messages) and created this based on it: https://github.com/ebidel/i18n-msg/pull/25
I'm trying to follow the spec without implementing all of it so it can probably be extended in the future.
Currently there are two ways we can use placeholders:
Placeholders in the json file
{
"bye": {
"message": "Come back to $our_site$ soon!",
"placeholders": {
"our_site": {
"content": "Example.com",
}
}
}
}
These work pretty much as documented by chrome. We have a placeholders attribute that contains the placeholders. In this case there is one called our_site with a content of Example.com. When we find this placeholder we can do a simple string replacement. Replace $our_site$ with with the content of the our_site placeholder.
Placeholders in a component attribute
{
"bye": {
"message": "Come back to $our_site$ soon!",
"placeholders": {
"our_site": {
"content": "$1",
}
}
}
}
In this case the content of the placeholder is $1. In this case I am currently just checking that the first character is a $. If it is then I assume you are looking for an attribute. In this example, since it is $1 it will look for the first placeholder passed to the component($2 is the second, and so on). The placeholders are passed as an array in an attribute called placeholders:
<i18n-msg msgid="seconds" placeholders='["Example.com"]'>PLACEHOLDER_STRING</i18n-msg>
The result in both cases is: Come back to Example.com soon!
+1