其他分享
首页 > 其他分享> > Tomcat_ResourceBundle类实现国际化

Tomcat_ResourceBundle类实现国际化

作者:互联网

ResourceBundle通过ResourceBundle类绑定属性文件实现国际化

package org.services.lang;

import javax.servlet.ServletOutputStream;
import java.io.IOException;
import java.util.Locale;
import java.util.ResourceBundle;

public class lang {

    private static final String DOC_FILE = "org.services.lang.doc";
    public static void printByLocale(Locale local, ServletOutputStream out, String name) throws IOException {
        //通过指定地区,获取当地的语言属性文件
        //Locale.SIMPLIFIED_CHINESE  简体中文  zh_CN
        //Locale.JAPAN               日文      ja
        //Locale.KOREA               韩文      ko kR
        ResourceBundle resourceBundle = ResourceBundle.getBundle(DOC_FILE,Locale.JAPAN);
        //获取属性文件里对应语言的翻译
        String nameVal = resourceBundle.getString(name);
        //将编码格式ISO-8859-1转换为UTF-8
        String strVal = new String(nameVal.getBytes("ISO-8859-1"),"UTF-8");
        //写入ServletOutStream输出流
        out.write(strVal.getBytes("UTF-8"));
    }

}

标签:国际化,java,String,Tomcat,Locale,UTF,ResourceBundle,import
来源: https://blog.csdn.net/qq_39663113/article/details/118272822