Skip to content
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

Translation of a text with a % character causes "SyntaxError: [sprintf] unexpected placeholder" #37

Closed
sleepy-angio opened this issue Nov 9, 2016 · 4 comments

Comments

@sleepy-angio
Copy link

sleepy-angio commented Nov 9, 2016

I'm using counterpart together with react translate and I am using it as such:

import counterpart from 'counterpart';
counterpart.translate('TOOLTIP_CHECKBOX')

if the TOOLTIP_CHECKBOX equals "About 25% of people..." the %-character will cause

SyntaxError: [sprintf] unexpected placeholder

Anybody know how to solve this?

@yanndinendal
Copy link
Contributor

@sleepy-angio : Yes, the % should be escaped as it's the format placeholder (https://en.wikipedia.org/wiki/Printf_format_string#Format_placeholder_specification).

So you should write %% instead (https://en.wikipedia.org/wiki/Printf_format_string#Type_field) (to "[print] a literal % character").

So:

  const TOOLTIP_CHECKBOX = "About 25%% of people...";

and the double percent should be kept as-is in all translations.

@martinandert
Copy link
Owner

Thanks for responding so quickly, @yanndinendal !

@martinandert
Copy link
Owner

See also #2 and #23. It's a sprintf quirk.

@sleepy-angio
Copy link
Author

sleepy-angio commented Nov 9, 2016

Ok, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants