-
Notifications
You must be signed in to change notification settings - Fork 87
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
Handling of variants for singular and plural should be possible #193
Comments
This is implemented with version 2.4.0. The code complicated now and this should be refactored to use regular expressions. |
The syntax for selectors has changed in version 2.5.0. To identify a variant we use a regular expression now instead of a simple string comparison. Let's revisit the example above:
If a variable needs to be replaced within or after a selector, we need to use |
Hi, does this work in javascript ? How ? |
Did you run into an error with the code above? Can you tell me what you did an what worked and what not, to find out if there is any issue? |
Thanks for your help. I just don't know how to write the multilines syntax in my js translation file. |
Of course this does not work :
|
Can you give this a try:
|
Works perfectly ! Thanks a lot. |
Hi, it seems like there is a bug in the logic. Can you fix this ? |
This works :
|
This also works:
I'm not sure at the moment if this needs a fix. |
Well your regex are better ;) |
Currently variable replacement has no logic attached. Let's say we have a variable
photoCount
, if its values is0
we would like to render "hasn't added any photos yet",if its values is
1
we would like to render "added a new photo",otherwise we would like to render "added $photoCount new photos". We would have to define 3 differnt translation keys to be able to do that.
Recently Mozilla release the Fluent project which has a feature called selctors that allow to specify variants for key replacement.
In the spirit of selectors we could define a translation key like
The translation key has two selectors
photoCount
andsex
. We could request a translation likeT9n.get('sharedPhotos', true, {userName: 'Anne', photoCount: 0}, sex: 'female')
-> Anne hasn't added any photos yet, she also liked a comment on a post
T9n.get('sharedPhotos', true, {userName: 'Brian', Jeff: 1, sex: 'male'})
-> Jeff added a new photo, he also liked a comment on a post
T9n.get('sharedPhotos', true, {userName: 'Brian', photoCount: 3})
-> Brian added 3 new photos, that user also liked a comment on a post
There are three small differences with Fluent selectos, first the varaible name is surrounded by
@{
and}
and second, if the variable should be replaced with the given value within a replacment string, we have to prepend$
, see $photoCount in the example above. Lastly the default value is marked with[*]
instead of*[other]
.The text was updated successfully, but these errors were encountered: