In the previous article, I introduced how to use the eclipse international toolProgramString in extenalize, we can see that the process is very simple. I really like Eclipse. It can do a lot of things for you, which is clean and beautiful, but it will never do anything without your consent!
Now let's talk about how to handle the situation where the resource contains parameters. For example, to display the information in the dialog box: "The account currently has 900 yuan, and the deadline is--1. Thank you !", Because the numbers and dates in the middle are dynamic, they cannot be directly stored in the resource file. However, you do not need to specify three resources for this information (three strings separated by numbers and dates). You can specify resources in the resource file (. properties) as follows:
My. Resource. Key = the account still has {0} yuan. The deadline is {1}. Thank you!
{0} and {1} indicate that they will be replaced with dynamic values, and then written in the program:
Float amount =...; Date dt=...; String msg= Messageformat. Format (messages. getstring ("My. Resource. Key "),NewObject [] {amount, DT });
In this way, the MSG variable contains the dynamically generated prompt information. You may want to format the date. To implement this function, you only need to slightly modify the resource, as shown below:
The account currently has {0} RMB. The end date is {1, date, yyyy-mm-dd}. Thank you!
It's really easy. I don't know if you have used this method. I used it for the first time in the PPP project. So let's take a look at it.
The next problem is encoding. It is okay to write the resource file in English and can be displayed normally. However, Chinese characters cannot be directly written in the resource file and must be converted to Unicode. JDK itself provides the native2ascii tool to implement this function, but it is always inconvenient to use command lines. Although some people like to use command lines ...... If you are willing to use eclipse to serve you, you can use the two plug-ins I will introduce below. using them, you do not need to explicitly convert the encoding step.
The first one is the properties Editor, which seems to be written by a Japanese. After installation, it will be associated with the extension. properties file is associated. You can use it to open the resource file and switch between the local language and the Unicode view. Generally, You can edit the local language and convert it to Unicode automatically when saving the file. This editor is very convenient when you need to search for a resource (value) and modify it. For example, you want to change "hello" in the resource to "hello ", if you are dealing with a bunch of Unicode codes, it is really a headache. Install this plug-in using eclipse 2.1.1 or later.
Another plug-in that we often use in projects is ...... I really don't know what its name is. The package name here is "29 localization Editor", which is a very convenient international translation tool. Use it to open. after the properties file, you can create a new key or a new language. All you need to do is fill in the resource values that have not been translated into a new language in the table, you can select to display only untranslated entries or all entries. But I'm sorry, I haven't found any online yet. Please contact me if necessary.
Figure 1 localization editor user interface
Now, let's take a look at eclipse internationalization. If your application is an Eclipse plug-in, you can go further: pack the resource file into a Language Pack. For more information about this method (fragment), please try again later.