Android export/import issues
Nailik opened this issue · comments
Hi while testing i found some more issues with Android import export:
- importing
\n\n
exports to"\n\n"
<![CDATA[
is not always recognized (in my example it starts with<![CDATA[<b>
maybe that's the issue\u2022
is not recognized and will be escaped to\\u2022
- importing
%1$s %2$s
etc exports to%s %s
-> seems like a bug because the ui shows 2 different placeholders (with id 0 and 1)
Hey! The Android import and export is currently so complex, I cannot simply guess, what's the actual and desired behaviour for each of the cases you've reported. Can you please share the exact relevant parts of Android Strings XML, you are importing and the relevant parts being exported?
importing %1$s %2$s etc exports to %s %s -> seems like a bug because the ui shows 2 different placeholders (with id 0 and 1)
This is intended, since it has exactly the same meaning. You can omit the 1$
and 2$
, when you don't need to modify the order of the placeholders being rendered in the text.
- any
\n\n
should be exported as\n\n
because it's just to newlines
example:
<string name="some_text">text\n\nmore text</string>
is exported as<string name="some_text">text"\n\n"more text</string>
- Unicode characters like
\u2022
should not be escaped
example:
<string name="some_bullet_text">\u2022 some text</string>
is exported as<string name="some_bullet_text">\\u2022 some text</string>
For
<![CDATA[
is not always recognized (in my example it starts with <![CDATA[<b>
maybe that's the issue
actually CDATA
was recognized because the text contains the _androidWrapWithCdata
flag but html tags are encoded.
The string uses the following html tags:
- b
- br
- a
- span
- ul
- li
The string should be wrapped with CDATA instead of being html encoded
This is intended, since it has exactly the same meaning. You can omit the 1$ and 2$, when you don't need to modify the order of the placeholders being rendered in the text.
Could you add an export option to disable this? i really would like it because it shows more specific that there are multiple parameters when using 1$ and 2$ ...
<string name="some_text">text\n\nmore text</string>
Thanks, you're right here that \n is always rendered as new line despite it's quoted or not...
maybe that's the issue actually CDATA was recognized because the text contains the _androidWrapWithCdata flag but html tags are encoded.
Can you also share an example of such string which is not being recognized?
Could you add an export option to disable this? i really would like it because it shows more specific that there are multiple parameters when using 1$ and 2$ ...
The thing is that we don't really want to complicate the UI and overall importing / exporting process. You shouldn't care much about the syntax of the data exported from Tolgee, since you are probably don't have to modify them. .. %s .. %s
is perfectly valid syntax for your case. I don't see much need for having such export option, which is useless from semantic point of view, right?
Could you add an export option to disable this? i really would like it because it shows more specific that there are multiple parameters when using 1$ and 2$ ...
The thing is that we don't really want to complicate the UI and overall importing / exporting process. You shouldn't care much about the syntax of the data exported from Tolgee, since you are probably don't have to modify them.
.. %s .. %s
is perfectly valid syntax for your case. I don't see much need for having such export option, which is useless from semantic point of view, right?
Actually it makes a difference:
<string name="sometext"><![CDATA[<a href=\"%1$s://link\">Link</a> und <a href=\"%1$s://link2\">Link2</a>]]></string>
works when using resources.getString(id, *args)
and only one argument (because of same base link)
but
<string name="sometext"><![CDATA[<a href=\"%s://link\">Link</a> und <a href=\"%s://link2\">Link2</a>]]></string>
crashes with
java.util.MissingFormatArgumentException: Format specifier '%s'
at java.util.Formatter.format(Formatter.java:2528)
at java.util.Formatter.format(Formatter.java:2464)
at java.lang.String.format(String.java:3644)
at android.content.res.Resources.getString(Resources.java:571)
Therefore when using multiple placeholder they should all be defined using $1, $2 etc
You're right, this is a bug in export behaviour. Thanks for the valuable feedback!
<string name="sometext"><![CDATA[<a href=\"%1$s://link\">Link</a> und <a href=\"%1$s://link2\">Link2</a>]]></string>
I have tested this case and it works correctly.
It imports the placeholders as {0} ... {0}
and exports as: <string name="sometext"><![CDATA[<a href=\"%s://link\">Link</a> und <a href=\"%1$s://link2\">Link2</a>]]></string>
Which perfectly works.
my bad, wrong import i imported with <string name="sometext"><![CDATA[<a href=\"%s://link\">Link</a> und <a href=\"%s://link2\">Link2</a>]]>