Danh mục

Flex 3 with Java- P6

Số trang: 50      Loại file: pdf      Dung lượng: 1.46 MB      Lượt xem: 8      Lượt tải: 0    
Thư viện của tui

Xem trước 5 trang đầu tiên của tài liệu này:

Thông tin tài liệu:

Tham khảo tài liệu flex 3 with java- p6, công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả
Nội dung trích xuất từ tài liệu:
Flex 3 with Java- P6 Chapter 125. Now create a new file under each subfolder and name it MyResource. properties. Once you create the properties file, change its encoding by right-clicking on it, selecting Properties, and then changing Text file encoding to UTF-8 as shown in the following screenshot. Make sure that you follow this process for each resource file. [ 237 ]Internationalization and Localization 6. Now copy the following key/value into each resource file: ° Add greeting_text=Hello into MyResource.properties under the en_US folder. ° Add greeting_text=Bonjour into MyResource.properties under the fr_FR folder. ° Add greeting_text=你好 into MyResource.properties under the zh_CN folder. 7. Once you create your properties file, we are ready to modify our application code. Open the SimpleLocalization.mxml file and modify it as shown in the following example: [ResourceBundle(MyResource)] As you can see in the above code, we have defined the tag that declares the resource bundle name we are using—MyResource. (Do not specify the .properties extension.) Next, we have changed the definition and we are now binding its text property with the resourceManager.getString(bundleName, key) methods returned value. resourceManager is an instance of the ResourceManager class that is available explicitly to all components that extend the UIComponent, Validator, and Formatter classes. The resourceManager property lets you access a singleton instance of the ResourceManager class, which loads resource bundles. It also provides various methods to access resource properties, such as getString(bundleName, key), which takes the bundle name and resource key as parameters and returns localized value of that key based on the current locale. [ 238 ] Chapter 128. Before you compile the application, a few compiler settings need to be updated. Right-click on your project name in the Flex Navigator view and select the Properties menu. Then, select Flex Compiler from the pane on the left-hand side and add -locale zh_CN -source-path ../locale/ {locale} in the Additional compiler arguments text field, as shown in the following screenshot:9. The –locale parameter specifies the locale that our application will be using, and –source-path specifies where to find those additional resource files. {locale} is a special variable which will get substituted by the value specified in the –locale parameter. [ 239 ]Internationalization and Localization When you compile your application for a specific locale, the compiler looks for localized framework files. For example, if you are compiling your application for the fr_FR locale, you need to have the French version of Flex framework. By default, Flex SDK comes with only the en_US version framework, but you can easily create localized framework by using the copylocale command-line utility provided by Flex SDK, as shown in following example. Open command prompt and change the directory to your \bin\ folder and type the following command: copylocale.exe en_US fr_FR Copylocale.exe creates a localized framework from the given locale and creates a new folder with the locale name under the \ frameworks\locale\ folder. So, the above \ command will create a fr_FR locale framework from the en_US framework and store it in the \ frameworks\locale\fr_FR folder. \fr_FR Flexs built-in components, such as Labeland Button, use resources just like your application and components do. These resource files are stored in a separate resource bundle library in the framework\locale folder. If a localized framework is missing, then Flex compiler will throw an error while compiling with the –locale option. 10. Now compile and run the application, and you should see Hello translated into Chinese. Now go ahead and change the –locale compiler parameter and set it to fr_FR. Now recompile and run the application; you should see Bonjour, a French word, instead of Hello.We saw a simple localization example where we compiled an application for aspecific locale by using the –locale compiler option. You can also add additionallocales into the –locale parameter to compile your application for multiplelocales, for example –locale en_US fr_FR zh_CN … (use a space between eachlocale). This will compile your application for all specified locales. By default,your application will run in an English locale, but you can dynamically change toother locales by using the resourceManager.localeChain property. Modify theSimpleLocalization.mxml code as shown here: [ResourceBundle(MyResource)] Chapter 12 text)} fontSize=48/> In the above code, we have added a new bindable Array type variable calledlocales and initialized it with default value ...

Tài liệu được xem nhiều: