Created
August 13, 2012 09:29
-
-
Save Bertg/3338673 to your computer and use it in GitHub Desktop.
I18n Interpolation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# I18n Interpolation plan | |
## Introduction | |
### Inline pluralisation | |
These propositions different interpolations indicators are used. `%{}'` and `%<{}>` are 2 of them. In this discussion we should focus on the content of these tags. What type of indicators we would be using is more of a compatibility and/or performance question. | |
#### Value interpolations | |
When creating a translatable string, it can be a hastle to create multiple keys for each pluralisation within a sentence. | |
These interpolation syntaxes could be used for more than just pluralisation. Gender differentiation can also be acomplished with these notations. | |
##### Tr8n syntax | |
`"THere %{count|| is, are} %{count| ninja, ninjas} in this room %{current_user.gender| girly, boys, awesome} room" # => There are 5 ninjas in this room girly room | There is 1 ninja in this room boys room` | |
* Compact notation | |
* Readable without prior knowledge | |
* Interpolation rules are "assumed" and not clear from the provided string | |
##### Twitter syntax | |
`"THere %<{ 'count': { 'one': 'is', 'other': 'are' } }> %{ 'count': { 'one': 'one ninja', 'other': '%{count} ninjas' } } in this room %<{ 'current_user.gender': { 'male': 'boys', 'female': 'girly', 'other': 'awesome' } }> room" # => There are 5 ninjas in this room girly room | There is one ninja in this room boys room` | |
* Verbose notation, clear what rules would be applied | |
* Less readable without prior knowledge | |
* Easily validatable translations | |
#### Decorator tokens | |
Today when we want to add markup to a translation, a string or html tags; we are forced to either put HTML in the string, | |
##### Tr8n syntax | |
`"You can [link: visit the site] or [strong: read this bold text]" # => You can <a href="/home">visit the site</a> or <strong>read this boldtext</a> ` | |
##### Proposed I18n filters | |
See: https://github.com/svenfuchs/i18n/issues/148 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There's also the Java's MessageFormat (JS port)