All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.alibaba.csb.sdk.i18n.MessageHelper Maven / Gradle / Ivy

There is a newer version: 1.1.5.11
Show newest version
package com.alibaba.csb.sdk.i18n;

import java.io.UnsupportedEncodingException;
import java.text.MessageFormat;
import java.util.Locale;
import java.util.ResourceBundle;

/**
 * Created by wiseking on 18/4/23.
 */
public class MessageHelper {
  private static Locale DEFAULT_LOCALE = new Locale("zh","CN");
  private static ResourceBundle rb = null;

  static {
    rb = ResourceBundle.getBundle("i18n/resource", DEFAULT_LOCALE);
    if(rb == null)
      throw new RuntimeException("BAD: CAN NOT found i18n MessageResource file!!!");
  }

  public static String getMessage(String key, String... params) {
    return getMessage(key, Locale.CHINA, params);
  }

  public static String getMessage(String key, Locale locale, String... params) {
    String ret = new MessageFormat(rb.getString(key),locale).format(params);
//    try {
//      return new String(ret.getBytes("UTF-8"), "GBK");
//    } catch (UnsupportedEncodingException e) {
//      //e.printStackTrace();
//    }
    return ret;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy