Tiqa / redux-polyglot

Polyglot.js bindings for Redux
MIT License
58 stars 13 forks source link

Pluralization not working #100

Closed rbarkhouse closed 6 years ago

rbarkhouse commented 6 years ago

I'm trying to use the Polyglot plural syntax but it doesn't seem to be working as expected... I have the following string in my bundle:

"NumberOfNetworksReporting": "%{count} network is reporting |||| %{count} networks are reporting"

If I provide an object with interpolation values, it ends up printing the whole string with both forms, including the pipe characters:

<p>{props.p.tu('NumberOfNetworksReporting', { count: 0 })}</p>
<p>{props.p.tu('NumberOfNetworksReporting', { count: 1 })}</p>
<p>{props.p.tu('NumberOfNetworksReporting', { count: 2 })}</p>

Result:
0 NETWORK IS REPORTING |||| 0 NETWORKS ARE REPORTING
1 NETWORK IS REPORTING |||| 1 NETWORKS ARE REPORTING
2 NETWORK IS REPORTING |||| 2 NETWORKS ARE REPORTING

If I use Polyglot's alternate syntax (pass a number as the second argument), it appears to be doing the proper plural phrase selection, but it doesn't substitute the actual value:

<p>{props.p.tu('NumberOfNetworksReporting', 0)}</p>
<p>{props.p.tu('NumberOfNetworksReporting', 1)}</p>
<p>{props.p.tu('NumberOfNetworksReporting', 2)}</p>

Result:
%{COUNT} NETWORKS ARE REPORTING
%{COUNT} NETWORK IS REPORTING
%{COUNT} NETWORKS ARE REPORTING

Any suggestions? Rick

guillaumearm commented 6 years ago

Hello @rbarkhouse,

According to the polyglot.js documentation, it seems like you have to use ${smart_count} variable name to activate pluralization feature.

Anyway, I think some tests should be added about this features. (pluralization, interpolation).

rbarkhouse commented 6 years ago

Ack, you are very right, I didn't notice that in their docs. Thanks, and thanks for this library!