Closed lukeramsden closed 7 years ago
@lukeramsden I assume you want to put it in strings.xml, right?
<string formatted="false" name="percent">Increase with %s %% </string>
and then in js
viewModel.message = L('percent', 75);
will results in
@rborn Is there a way to escape it without using replacement? It's just in some static text. It wasn't working just escaping it with \
@lukeramsden the plugin uses sprintf
behind the scenes so a static text would still need %%
in it to display the percent sign.
So this should work without the replacement
<string formatted="false" name="percent">Increase with 42%% </string>
viewModel.message = L('percent');
So putting a % sign in your text requires formatted
to be false
? That should go in the docs
So after testing it, that works perfectly (even with XML bindings and not JS ones) so that should 100% go in the docs.
formatted="false"
needs to be there only if there are replacements (that's in the docs already).
You can use it without formatted if you don't have any replacements, but the key is the double %
https://linux.die.net/man/3/sprintf
% A '%' is written. No argument is converted. The complete conversion specification is '%%'.
@rborn Then why wouldn't the percent signs show up without that?
Here: https://github.com/rborn/nativescript-i18n/blob/master/i18n.ios.js#L10
This uses format which as you can see replicates sprintf
sprintf
treats %
as a modifier and tries to replace it with something based on the rules in the man page I sent you. If nothing is found it will remove the %
sign. So you need to tell it you really want it there by %%
😄
Makes more sense?
@rborn Yes I think so. As far as I could tell, the %% wasn't working without formatted="false"
, but I don't have time to test that because it requires me to build from scratch and I'm currently working on other things. Either way, what I put in the README works 😄
It works, I tested it, but leave it with formatted because will save us from issues opened in the cases where a user would have both replacement and %%
Thank you for all your help :)
No problem 😄
For some reason, I can't get the % sign to display. I've tried
75%
,75\%
and75%
, but none of them seem to work.