android2po icon indicating copy to clipboard operation
android2po copied to clipboard

Single % sign in strings.xml

Open pryds opened this issue 11 years ago • 2 comments

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: https://github.com/pryds/ve/issues/15

pryds avatar Feb 24 '14 13:02 pryds

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.

miracle2k avatar Feb 26 '14 19:02 miracle2k

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

bkeller-vuzix avatar Feb 09 '23 17:02 bkeller-vuzix