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

Escaping "Grater than" and "Less than" symbols #7

Open
h6ah4i opened this issue Jul 8, 2014 · 4 comments
Open

Escaping "Grater than" and "Less than" symbols #7

h6ah4i opened this issue Jul 8, 2014 · 4 comments
Labels

Comments

@h6ah4i
Copy link

h6ah4i commented Jul 8, 2014

"Grater than" (>) and "Less than" (<) symbols should be converted as Entity Reference when exported as a XML file. If these symbols are used directly, incorrect XML file will be generated.


Example of the issue
  • String

    <ABC>

  • Exported XML

    <string name="foo"><ABC></string>

    • NOTE: <ABC> will be treated as a TAG!!!
@ocram
Copy link
Contributor

ocram commented Jul 8, 2014

Please try changing the Output format to Android XML with escaped HTML when exporting. Does this help?

In general, it's valid to use <b>, <i> and <u> tags in Android XML for translations.

So we can't just encode any < and >. But we should be able to encode any < or > that is not part of one of these three tags.

@h6ah4i
Copy link
Author

h6ah4i commented Jul 8, 2014

You are right, thank you.

I found the solution of this problem;

  • Solution 1 :
  • Solution 2 : \u003cABC\u003e

@ocram
Copy link
Contributor

ocram commented Jul 9, 2014

So did you try the "Output format" with a value of "Android XML with escaped"? Did it work for you?

Considering your solutions, I'd prefer not to wrap everything in a CDATA section, so number two would be the better one. However, it should be enough to use &lt; or &gt; for the brackets. There's no need for unicode sequences, is there?

@h6ah4i
Copy link
Author

h6ah4i commented Jul 9, 2014

Thank you for your advice. Before introducing Localize, I used both entity referenced characters and CDATA sections in the same XML file.

Text resources were imported as follows:

I tried both "Android XML" and "Android XML with escaped", but those results were not expected.


Problem situation

Original XML
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="cdata_abc"><![CDATA[<ABC>]]></string>
    <string name="escaped_abc">&lt;ABC&gt;</string>
</resources>
Imported as
  • <ABC>
  • &lt;ABC&gt;
Exported XML (Android XML)
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="cdata_abc"><ABC></string>
    <string name="escaped_abc">&#38;lt;ABC&#38;gt;</string>
</resources>
Exported XML (Android XML with escaped HTML)
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="cdata_abc">&#60;ABC&#62;</string>
    <string name="escaped_abc">&#38;lt;ABC&#38;gt;</string>
</resources>

My solution

Modified
  • <![CDATA[<ABC>]]>
  • \u003cABC\u003e
Exported XML (Android XML)
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="cdata_abc"><![CDATA[<ABC>]]></string>
    <string name="escaped_abc">\u003cABC\u003e</string>
</resources>

@ocram ocram added the bug label Jul 14, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants