package com.brilliance.isc.common.util;

import org.springframework.context.support.ResourceBundleMessageSource;

import java.util.Locale;

public class I18nUtil {


    public static String getMessage(String key) {
        return getMessage(key, null, Locale.SIMPLIFIED_CHINESE);
    }

    public static String getMessage(String key, Object... args) {
        ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
        // 通过setBasenames来设置国际化文件
        messageSource.setBasenames("i18n/messages");
        return messageSource.getMessage(key, args, Locale.SIMPLIFIED_CHINESE);
    }

    public static String getMessage(String key, Locale locale) {
        return getMessage(key, locale, null);
    }

    public static String getMessage(String key, Locale locale, Object... args) {
        ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
        // 通过setBasenames来设置国际化文件
        messageSource.setBasenames("i18n/messages");
        return messageSource.getMessage(key, args, locale);
    }

    public static String getI18NString(String moduleName, String key, Locale locale) {
        ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
        // 通过setBasenames来设置国际化文件
        messageSource.setBasenames("i18n/" + moduleName);
        return messageSource.getMessage(key, null, locale);
    }
}
