package cn.iocoder.yudao.framework.i18n.core;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Locale;

@Getter
public enum Languages {
    SIMPLIFIED_CHINESE(0, Locale.SIMPLIFIED_CHINESE),
    ENGLISH(1, Locale.ENGLISH),
    // 集成法语
    FRENCH(2, Locale.FRENCH);

    private int code;
    private Locale locale;

    Languages(int code, Locale locale) {
        this.code = code;
        this.locale = locale;
    }

    public int getCode() {
        return code;
    }

    public Locale getLocale() {
        return locale;
    }

    public static Locale getLocaleByCode(int code) {
        for (Languages languages : values()) {
            if (languages.getCode() == code) {
                return languages.getLocale();
            }
        }
        // 默认返回简体中文
        return SIMPLIFIED_CHINESE.getLocale();
    }
}
