package com.vetti.common.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.EncodedResource;
import org.springframework.core.io.support.PropertiesLoaderUtils;

import java.io.IOException;
import java.text.MessageFormat;
import java.util.Properties;

/**
 * i18n 国际化工具类
 *
 * @author Wangxiangshun 2025-08-27
 */
public class I18nUtil {

    private static Logger logger = LoggerFactory.getLogger(I18nUtil.class);

    /**
     * 获取国际化信息
     * @param languageType
     * @return
     */
    public static Properties loadI18nProp(String languageType) {
        Properties prop = null;
        try {
            String i18n = languageType;
            String i18nFile = MessageFormat.format("i18n/messages_{0}.properties", i18n);
            Resource resource = new ClassPathResource(i18nFile);
            EncodedResource encodedResource = new EncodedResource(resource, "UTF-8");
            prop = PropertiesLoaderUtils.loadProperties(encodedResource);
        } catch (IOException e) {
            logger.error(e.getMessage(), e);
        }
        return prop;
    }
}
