mirror of
https://github.com/hs-web/hsweb-framework.git
synced 2026-05-07 21:55:57 +08:00
refactor: 优化国际化信息
This commit is contained in:
@@ -11,7 +11,7 @@ import reactor.core.publisher.*;
|
||||
import reactor.util.context.Context;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Locale;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.function.*;
|
||||
|
||||
@@ -36,6 +36,35 @@ public final class LocaleUtils {
|
||||
|
||||
static MessageSource messageSource = UnsupportedMessageSource.instance();
|
||||
|
||||
static Set<Locale> supportsLocales;
|
||||
|
||||
static {
|
||||
supportsLocales = new HashSet<>();
|
||||
supportsLocales.add(Locale.CHINESE);
|
||||
supportsLocales.add(Locale.ENGLISH);
|
||||
String prop = System.getProperty("hsweb.locale.supports");
|
||||
if (prop != null) {
|
||||
try {
|
||||
for (String locale : prop.split(",")) {
|
||||
if (locale.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
supportsLocales.add(Locale.forLanguageTag(locale));
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
System.err.println("error parse hsweb.locale.supports :" + prop);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取支持的语言地区,默认支持中文和英文,可通过jvm参数: -Dhsweb.locale.supports=zh,en 来指定支持的语言地区
|
||||
*
|
||||
* @return 支持的语言地区
|
||||
*/
|
||||
public static Set<Locale> getSupportLocales() {
|
||||
return Collections.unmodifiableSet(supportsLocales);
|
||||
}
|
||||
|
||||
/**
|
||||
* 从指定数据源中获取国际化消息
|
||||
|
||||
@@ -11,6 +11,15 @@ import static org.junit.Assert.*;
|
||||
|
||||
public class LocaleUtilsTest {
|
||||
|
||||
@Test
|
||||
public void testSupports(){
|
||||
|
||||
assertNotNull(LocaleUtils.getSupportLocales());
|
||||
|
||||
System.out.println(LocaleUtils.getSupportLocales());
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFlux() {
|
||||
|
||||
@@ -30,6 +30,7 @@ import org.hswebframework.web.crud.generator.Generators;
|
||||
import org.hswebframework.web.dict.DictDefine;
|
||||
import org.hswebframework.web.dict.defaults.DefaultDictDefine;
|
||||
import org.hswebframework.web.i18n.I18nSupportUtils;
|
||||
import org.hswebframework.web.i18n.LocaleUtils;
|
||||
import org.hswebframework.web.i18n.MultipleI18nSupportEntity;
|
||||
import org.hswebframework.web.validator.CreateGroup;
|
||||
|
||||
@@ -96,6 +97,10 @@ public class DictionaryEntity extends GenericEntity<String> implements RecordCre
|
||||
return getI18nMessage("describe", this.describe);
|
||||
}
|
||||
|
||||
public void putI18nName(String i18nKey) {
|
||||
putI18nName(i18nKey, LocaleUtils.getSupportLocales());
|
||||
}
|
||||
|
||||
public void putI18nName(String i18nKey,
|
||||
Collection<Locale> locales) {
|
||||
this.i18nMessages = I18nSupportUtils
|
||||
|
||||
@@ -27,6 +27,7 @@ import org.hswebframework.ezorm.rdb.mapping.annotation.JsonCodec;
|
||||
import org.hswebframework.web.api.crud.entity.GenericTreeSortSupportEntity;
|
||||
import org.hswebframework.web.dict.EnumDict;
|
||||
import org.hswebframework.web.i18n.I18nSupportUtils;
|
||||
import org.hswebframework.web.i18n.LocaleUtils;
|
||||
import org.hswebframework.web.i18n.MultipleI18nSupportEntity;
|
||||
import org.hswebframework.web.utils.DigestUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
@@ -107,6 +108,15 @@ public class DictionaryItemEntity extends GenericTreeSortSupportEntity<String>
|
||||
return getI18nMessage("text", this.text);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据消息key生成默认的的语言并填充到i18nMessages中
|
||||
*
|
||||
* @param i18nKey key,在国际化文件中定义.
|
||||
*/
|
||||
public void putI18nText(String i18nKey) {
|
||||
putI18nText(i18nKey, LocaleUtils.getSupportLocales());
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据消息key生成对应的语言并填充到i18nMessages中
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user