Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of the internationalization of Java language Resources

2025-02-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly shows you the "sample Analysis of the internationalization of Java language Resources", which is easy to understand and well-organized. I hope it can help you solve your doubts. Let the editor lead you to study and study the "sample Analysis of Java language Resources internationalization".

Steps for internationalization of language resources:

1. To define a resource file (such as language), you need to use the command native2ascii command for transcoding; (native2ascii is a transcoding tool in jdk, under the bin directory of jdk)

two。 Define the tool class (LangusgeUtils) to read the resource file

3. Define the calling resource file class (TestResourceBundle)

Note: the native2ascii command must be sent to the resource folder below the project, for example:

D:\ Adobe\ eclipse\ JavaObject\ jdbc_pool_dao_shop\ etc > native2ascii-encoding UTF-8 language language_zh_CN.properties

# set resource coding #-encoding UTF-8 encodes the source file (language). The encoding method is UTF-8# transcoded file language_zh_CN.properties zh representation language is simplified Chinese CN represents country native2ascii-encoding UTF-8 language language_zh_CN.properties

Related profile

# the resource file languageuser.login.info=1. The user logs in to user.reg.info=2. User registers the # encoded resource file language_zh_CN.propertiesuser.login.info=1.\ u7528\ u6237\ u767b\ u5f55user.reg.info=2.\ u7528\ u6237\ u6ce8\ u518c

Tool class

Serialization and deserialization of import java.util.Locale;import java.util.ResourceBundle;/** * objects * / public class LanguageUtils {/ / private static ResourceBundle rBundle = ResourceBundle.getBundle ("j0812", new Locale ("en", "US")) / Note: parameters only write the prefix of the resource file, do not write the language and country-related strings / / do not define the language and country as above, then the program runtime will find the language and country currently used by the operating system private static ResourceBundle rBundle = ResourceBundle.getBundle ("language"); public static String getResourceByKey (String key) {return rBundle.getString (country);}}

Test invocation tool class

Public class TestResourceBundle {public static void main (String [] args) {String loginInfo = LanguageUtils.getResourceByKey ("user.login.info"); String regInfo = LanguageUtils.getResourceByKey ("user.reg.info"); System.out.println (loginInfo); System.out.println (regInfo);}} these are all the contents of the article "sample Analysis of the internationalization of Java language Resources". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report