From 383baf471aa06bac402f0496b600f1d87ef734d1 Mon Sep 17 00:00:00 2001 From: sight <26325820+Sight-wcg@users.noreply.github.com> Date: Sat, 24 May 2025 22:47:33 +0800 Subject: [PATCH] =?UTF-8?q?wip(i18n):=20=E4=BF=AE=E5=A4=8D=E6=89=93?= =?UTF-8?q?=E5=8C=85=E5=90=8E=20laydate=20=E5=92=8C=20layer=20=E5=BC=82?= =?UTF-8?q?=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/laydate.js | 12 ++++++++++-- src/modules/layer.js | 8 ++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/modules/laydate.js b/src/modules/laydate.js index e6783442..d5301772 100644 --- a/src/modules/laydate.js +++ b/src/modules/laydate.js @@ -177,7 +177,7 @@ ,isPreview: true //是否显示值预览 ,btns: ['clear', 'now', 'confirm'] //右下角显示的按钮,会按照数组顺序排列 // 为实现 lang 选项就近生效,去除此处的默认值,原型 lang() 方法中有兜底值 - ,lang: isLayui && layui.cache.i18n.locale //语言,只支持cn/en,即中文和英文 + ,lang: '' //语言,只支持cn/en,即中文和英文 ,theme: 'default' //主题 ,position: null //控件定位方式定位, 默认absolute,支持:fixed/absolute/static ,calendar: false //是否开启公历重要节日,仅支持中文版 @@ -286,9 +286,17 @@ }else{ window.console && console.log && console.log('layui[laydate]: Locale "' + i18n.locale + '" not found. Please add i18n messages for this locale first.'); } + // 同步 locale + if(!options.lang){ + options.lang = i18n.locale; + } } - return text[options.lang] || text['cn']; + if(!options.lang) { + options.lang = 'cn' + }; + + return text[options.lang]; }; Class.prototype.markerOfChineseFestivals = { diff --git a/src/modules/layer.js b/src/modules/layer.js index 5de17104..7c75c77e 100644 --- a/src/modules/layer.js +++ b/src/modules/layer.js @@ -161,8 +161,6 @@ var $t = isLayui return result; }; -// default btnText 需要在 $t 之后初始化 -ready.btn = [$t('lay.layer.confirm'), $t('lay.layer.cancel')]; // 默认内置方法。 @@ -228,7 +226,7 @@ var layer = { } return layer.open($.extend({ content: content, - btn: ready.btn, + btn: [$t('lay.layer.confirm'), $t('lay.layer.cancel')], yes: yes, btn2: cancel }, type ? {} : options)); @@ -291,6 +289,8 @@ var Class = function(setings){ var that = this, creat = function(){ that.creat(); }; + // TODO 临时的同步方案 + ready.config.title = $t('lay.layer.defaultTitle'); that.index = ++layer.index; that.config.maxWidth = $(win).width() - 15*2; // 初始最大宽度:当前屏幕宽,左右留 15px 边距 that.config = $.extend({}, that.config, ready.config, setings); @@ -522,7 +522,7 @@ Class.pt.creat = function(){ switch(config.type){ case 0: - config.btn = ('btn' in config) ? config.btn : ready.btn[0]; + config.btn = ('btn' in config) ? config.btn : $t('lay.layer.confirm'); layer.closeAll('dialog'); break; case 2: