{"action":"created","issue":{"url":"https://api.github.com/repos/ebidel/i18n-msg/issues/26","repository_url":"https://api.github.com/repos/ebidel/i18n-msg","labels_url":"https://api.github.com/repos/ebidel/i18n-msg/issues/26/labels{/name}","comments_url":"https://api.github.com/repos/ebidel/i18n-msg/issues/26/comments","events_url":"https://api.github.com/repos/ebidel/i18n-msg/issues/26/events","html_url":"https://github.com/ebidel/i18n-msg/issues/26","id":116278357,"number":26,"title":"Add support for placeholders","user":{"login":"soonick","id":281836,"avatar_url":"https://avatars.githubusercontent.com/u/281836?v=3","gravatar_id":"","url":"https://api.github.com/users/soonick","html_url":"https://github.com/soonick","followers_url":"https://api.github.com/users/soonick/followers","following_url":"https://api.github.com/users/soonick/following{/other_user}","gists_url":"https://api.github.com/users/soonick/gists{/gist_id}","starred_url":"https://api.github.com/users/soonick/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/soonick/subscriptions","organizations_url":"https://api.github.com/users/soonick/orgs","repos_url":"https://api.github.com/users/soonick/repos","events_url":"https://api.github.com/users/soonick/events{/privacy}","received_events_url":"https://api.github.com/users/soonick/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-11-11T07:01:23Z","updated_at":"2016-02-26T12:26:29Z","closed_at":null,"body":"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:\r\nhttps://github.com/ebidel/i18n-msg/pull/25\r\n\r\nI'm trying to follow the spec without implementing all of it so it can probably be extended in the future.\r\n\r\nCurrently there are two ways we can use placeholders:\r\n\r\n**Placeholders in the json file**\r\n\r\n```json\r\n{\r\n  \"bye\": {\r\n    \"message\": \"Come back to $our_site$ soon!\",\r\n    \"placeholders\": {\r\n      \"our_site\": {\r\n        \"content\": \"Example.com\",\r\n      }\r\n    }\r\n  }\r\n}\r\n```\r\n\r\nThese 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.\r\n\r\n**Placeholders in a component attribute**\r\n\r\n```json\r\n{\r\n  \"bye\": {\r\n    \"message\": \"Come back to $our_site$ soon!\",\r\n    \"placeholders\": {\r\n      \"our_site\": {\r\n        \"content\": \"$1\",\r\n      }\r\n    }\r\n  }\r\n}\r\n```\r\n\r\nIn 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:\r\n\r\n```html\r\n<i18n-msg msgid=\"seconds\" placeholders='[\"Example.com\"]'>PLACEHOLDER_STRING</i18n-msg>\r\n```\r\n\r\nThe result in both cases is: *Come back to Example.com soon!*"},"comment":{"url":"https://api.github.com/repos/ebidel/i18n-msg/issues/comments/189257130","html_url":"https://github.com/ebidel/i18n-msg/issues/26#issuecomment-189257130","issue_url":"https://api.github.com/repos/ebidel/i18n-msg/issues/26","id":189257130,"user":{"login":"benjaminpg","id":9454052,"avatar_url":"https://avatars.githubusercontent.com/u/9454052?v=3","gravatar_id":"","url":"https://api.github.com/users/benjaminpg","html_url":"https://github.com/benjaminpg","followers_url":"https://api.github.com/users/benjaminpg/followers","following_url":"https://api.github.com/users/benjaminpg/following{/other_user}","gists_url":"https://api.github.com/users/benjaminpg/gists{/gist_id}","starred_url":"https://api.github.com/users/benjaminpg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/benjaminpg/subscriptions","organizations_url":"https://api.github.com/users/benjaminpg/orgs","repos_url":"https://api.github.com/users/benjaminpg/repos","events_url":"https://api.github.com/users/benjaminpg/events{/privacy}","received_events_url":"https://api.github.com/users/benjaminpg/received_events","type":"User","site_admin":false},"created_at":"2016-02-26T12:26:29Z","updated_at":"2016-02-26T12:26:29Z","body":"Oh my, I just sent a pull request for something similar... nonetheless I used a different aproach to insert the placeholders, to be more precise the one used in Spring MVC and its MessageSource class. Rather than label each placeholder it just use $n (n is a numeric value) as replace pattern. That way it's not necessary to declare each placeholder in your locale. On the other hand, in my case I got to parse the message to find these pattern and check if I was using it, which makes my solution less eficient. I think it would be better if I used something like \"usePlaceholders: true\"."}}