package com.cf.imes.framework.common.util.i18n.core.util;

import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;

import java.util.Locale;

/**
 * 国际化工具类
 *
 * @author Gqr
 * @since 2025/11/18 11:18
 */
@Slf4j
@Component
@AllArgsConstructor
public class I18nUtils {

    private MessageSource messageSource;

    /**
     * 获取国际化描述
     *
     * @param code
     * @param args
     * @return
     */
    public String getMessage(String code, Object... args) {
        return messageSource.getMessage(code, args, code, LocaleContextHolder.getLocale());
    }

    /**
     * 获取国际化描述
     *
     * @param locale
     * @param code
     * @param args
     * @return
     */
    public String getMessage(Locale locale, String code, Object... args) {
        return messageSource.getMessage(code, args, code, locale);
    }
}
