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

Single % sign in strings.xml #26

Open
pryds opened this issue Feb 24, 2014 · 2 comments
Open

Single % sign in strings.xml #26

pryds opened this issue Feb 24, 2014 · 2 comments

Comments

@pryds
Copy link

pryds commented Feb 24, 2014

Hi

If a string in strings.xml contains a single "%" which should be shown in the UI, android2po doesn't seem to convert this into "%%" upon export, and back into "%" upon import. Shouldn't it do this? If I use "%%" in strings.xml, both are shown in the UI.

If I'm not mistaken, a string like:
"VAT in Denmark is 25%" should be converted into "VAT in Denmark is 25%%"
while:
"My name is %1$s." should remain with one %.

I have a translator mentioning that this causes problems in the translation process.
Please see: pryds/ve#15

@miracle2k
Copy link
Owner

There might be a bug here. Part of the problem seems to be that Android behaves strangely here:

http://stackoverflow.com/questions/4414389/android-xml-percent-symbol

That is, if you want to use formatting on your string, we will need to use "%%". If you use "%%" without passing it through a formatting function, it will output two percent signs.

Of course, android2po cannot know how you will use the string on your source code.

I see a couple of options:

  1. Support formatted=false and require its use for cases such as this, so that android2po knows how to handle it.

  2. Encode all percent signs. Since the translator is supposed to keep the variables verbatim anyway, why not treat it as regular text? I'm actually not quite sure how the "c-format" declarations affect the behaviour of gettext tools, if they serve any purpose other than being for information purposes. Maybe they do.

  3. Special-case a string based on whether it contains "true" format strings. That is, if there is %1$s, assume the string will be passed through string formatting on the Android side, and should be a format string in gettext as well.

    If there is no actual placeholder, assume that the string will not be formatted, and that a percent sign therefore means the actual character, and should be escaped such that gettext doesn't think of it as a placeholder.

    This is essentially an auto-detection for the "unformatted" attribute. I'm naturally concerned about side effects.

@bkeller-vuzix
Copy link

I needed this too, and we use formatted="false" in our XML. A solution for this is submitted with #73

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