Native2Ascii task not working

2019-06-04 07:32发布

问题:

I'm trying to use the native2ascii ant task but it seems that is not doing anything. Here's my ant task:

<target name="-pre-init">
        <native2ascii src="src/com/bluecubs/xinco/messages" dest="src/com/bluecubs/xinco/messages/test" 
        includes="**/_*.properties"/>
        <copy todir="src/com/bluecubs/xinco/messages">
            <fileset dir="src/com/bluecubs/xinco/messages/test"/>
        </copy>
        <delete dir="src/com/bluecubs/xinco/messages/test" />
</target>

I did the copy part to see if it was an overwriting issue but the files come out exactly the same.

This is the output I get when running the task:

Converting 12 files from Z:\Netbeans\Xinco\2.01.xx\Xinco\src\com\bluecubs\xinco\messages to Z:\Netbeans\Xinco\2.01.xx\Xinco\src\com\bluecubs\xinco\messages\test
Copying 12 files to Z:\Netbeans\Xinco\2.01.xx\Xinco\src\com\bluecubs\xinco\messages
Deleting directory Z:\Netbeans\Xinco\2.01.xx\Xinco\src\com\bluecubs\xinco\messages\test

Edit:

Additional information: OS: Windows 7 (but answer should work on any OD) File encoding: Western (ISO-8859-1) obtained with this article.

Files location

Any idea?

回答1:

native2ascii converts native characters like áéí to escaped unicode sequences. It means that á will be \u00e1, é -> \u00e9 and í -> \u00ed. After running native2ascii your files will be standard ASCII files which are more portable.

native2ascii does not touch the characters which are already in the escaped unicode form. Your properties files are already in escaped unicode form so it does not change anything. For example _XincoMessages_cz.properties contains this line:

general.accessrights=opr\u00E1vnen\u00ED k pr\u00EDstupu

It's escaped unicode. The nonescaped unicode form is this:

general.accessrights=oprávnení k prístupu

Wordpad vs. Netbans: When you open the properties files with Wordpad it opens it as a simple text file and shows \u00e1 as \u00e1. It does not convert it back to á. Netbeans does this conversion and you see the 'á' character. Furthermore, it writes it back to the disk as \u00e1 (!) when you save the file. To see the raw files use for example a Total or Double Commander which doesn't do any converting. (Note that Netbeans does this conversion just for properties files.)

If you put for example an á character to your _XincoMessages_cz.properties file it will be changed to \u00e1 if your run your ant task. Of course now don't use Netbeans for the editing, a simple notepad will do.

Loading properties files in java converts the escaped unicode characters to real unicode characters. An example:

final Reader inStream = new FileReader("..../_XincoMessages_cz.properties");
final Properties properties = new Properties();
properties.load(inStream);
System.out.println(properties.getProperty("general.accessrights"));

It prints:

oprávnení k prístupu

The ASCII/escaped unicode form in properites files is usually handled well by java applications. Finally, I think your properties files are good in their current format.



回答2:

It ended being a view issue. Looking the files in a raw editor (i.e. Wordpad) showed that the files were already converted by the task. Viewing them from NetBeans shows them the same.



标签: ant ascii