package com.persagy.cameractl.utils;

import java.util.Locale;

import org.apache.tomcat.jni.Local;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;

import com.persagy.cameractl.service.windows.DahMainWindows;

/**
 * 国际化工具类
 */
@Component
public class MessageUtils {
	static Logger logger = LoggerFactory.getLogger(MessageUtils.class);
	private static MessageSource messageSource;

	public MessageUtils(MessageSource messageSource) {
		MessageUtils.messageSource = messageSource;
	}

	/**
	 * 获取单个国际化翻译值
	 */
	public static String get(String msgKey) {
		try {
			Locale locale= LocaleContextHolder.getLocale();
			String mes = messageSource.getMessage(msgKey, null, locale);
			return mes;
		} catch (Exception e) {
			logger.error("根据错误码" + msgKey + "获取错误信息失败：", e);
			return msgKey;
		}
	}
}
