parent
5a360c5a74
commit
2fb1185cb6
5 changed files with 5 additions and 78 deletions
@ -1,31 +0,0 @@ |
|||||||
package net.mingsoft.config; |
|
||||||
|
|
||||||
import com.jagregory.shiro.freemarker.ShiroTags; |
|
||||||
import freemarker.template.TemplateException; |
|
||||||
import org.springframework.beans.factory.annotation.Autowired; |
|
||||||
import org.springframework.beans.factory.annotation.Value; |
|
||||||
import org.springframework.context.annotation.Configuration; |
|
||||||
|
|
||||||
import javax.annotation.PostConstruct; |
|
||||||
import java.io.IOException; |
|
||||||
|
|
||||||
/** |
|
||||||
* 读取国际化配置,传递给freemker |
|
||||||
*/ |
|
||||||
@Configuration |
|
||||||
public class I18NConfig { |
|
||||||
@Autowired |
|
||||||
protected freemarker.template.Configuration configuration; |
|
||||||
|
|
||||||
@Value("${ms.local.default:zh_CN}") |
|
||||||
private String defaultLocal; |
|
||||||
@Value("$ms.local.local-messages:zh_CN,en_US}") |
|
||||||
private String localMessages; |
|
||||||
|
|
||||||
@PostConstruct |
|
||||||
public void init() throws IOException, TemplateException { |
|
||||||
configuration.setSharedVariable("localDefault",defaultLocal); |
|
||||||
configuration.setSharedVariable("localMessages",localMessages.split(",")); |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
@ -1,39 +0,0 @@ |
|||||||
<#list localMessages as item> |
|
||||||
<script src="${base}/static/locale/lang/${modeldir}/${item}.js"></script> |
|
||||||
</#list> |
|
||||||
<script> |
|
||||||
(function(window) { |
|
||||||
var defaultLocal = '${localDefault}' //默认语言 |
|
||||||
|
|
||||||
var localeMessage = [] //添加语言 |
|
||||||
<#list localMessages as item> |
|
||||||
localeMessage.push('${item}') |
|
||||||
</#list> |
|
||||||
window.indexlocale = { |
|
||||||
language:defaultLocal |
|
||||||
} |
|
||||||
//获取后台index的语言 |
|
||||||
if(parent!=null&&parent.indexVue!=undefined&&parent.indexVue.locale!=undefined){ |
|
||||||
window.indexlocale = parent.indexVue.locale |
|
||||||
} |
|
||||||
window.i18n = new VueI18n({ |
|
||||||
locale: window.indexlocale.language, // 设置地区 |
|
||||||
fallbackLocale: defaultLocal, |
|
||||||
|
|
||||||
}) |
|
||||||
//加载语言 |
|
||||||
localeMessage.forEach(function (value) { |
|
||||||
if(window[value]!=undefined){ |
|
||||||
var message = window[value] |
|
||||||
if(window['base_'+value]!=undefined){ |
|
||||||
message = Object.assign({},message,window['base_'+value]) |
|
||||||
} |
|
||||||
i18n.setLocaleMessage(value,message) |
|
||||||
} |
|
||||||
}) |
|
||||||
var localElement = i18n.getLocaleMessage(i18n.locale) |
|
||||||
if(Object.keys(localElement).indexOf("el")!=-1){ |
|
||||||
ELEMENT.locale(localElement) |
|
||||||
} |
|
||||||
})(window); |
|
||||||
</script> |
|
||||||
Loading…
Reference in new issue