From f2c7f6c73b4b4731a799fa0b5071d24d6eb54ca3 Mon Sep 17 00:00:00 2001 From: sight <26325820+Sight-wcg@users.noreply.github.com> Date: Fri, 23 May 2025 20:13:59 +0800 Subject: [PATCH] =?UTF-8?q?wip(i18n):=20util=20=E5=9B=BD=E9=99=85=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/layui.js | 37 +++++++++++++++++++++++++++++-------- src/modules/util.js | 24 ++++++++++++------------ 2 files changed, 41 insertions(+), 20 deletions(-) diff --git a/src/layui.js b/src/layui.js index 31bda958..1c77ce35 100644 --- a/src/layui.js +++ b/src/layui.js @@ -14,11 +14,6 @@ var zhCn = { locale: 'zh-cn', lay: { - common: { - noData: '暂无数据', - noMatch: '无匹配数据', - placeholder: '请选择' - }, code: { copy: '复制代码', copied: '已复制', @@ -53,7 +48,7 @@ date: '日期格式不正确', identity: '身份证号格式不正确' }, - verifyErrorPromptTitle: '提示', + verifyErrorPromptTitle: '提示' }, // 未使用的字段为保留字段,将来可能会使用 laydate: { @@ -102,7 +97,7 @@ cancel: '取消', defaultTitle: '信息', prompt: { - InputLengthPrompt: '最多输入 {length} 个字符', + InputLengthPrompt: '最多输入 {length} 个字符' }, photos: { noData: '没有图片', @@ -166,7 +161,7 @@ tree: { defaultNodeName: '未命名', noData: '无数据', - deleteNodePrompt: '确认删除该节点 ({name}) 吗?', + deleteNodePrompt: '确认删除该节点 ({name}) 吗?' }, upload: { fileType: { @@ -183,6 +178,32 @@ }, chooseText: '{length} 个文件' }, + util: { + timeAgo: { + days: '{days} 天前', + hours: '{hours} 小时前', + minutes: '{minutes} 分钟前', + future: '未来', + justNow: '刚刚' + }, + toDateString: { + meridiem: function(hours, minutes){ + var hm = hours * 100 + minutes; + if (hm < 600) { + return '凌晨'; + } else if (hm < 900) { + return '早上'; + } else if (hm < 1100) { + return '上午'; + } else if (hm < 1300) { + return '中午'; + } else if (hm < 1800) { + return '下午'; + } + return '晚上'; + } + } + } } } // 基础配置 diff --git a/src/modules/util.js b/src/modules/util.js index 83416c7b..c8f1325b 100644 --- a/src/modules/util.js +++ b/src/modules/util.js @@ -230,15 +230,15 @@ layui.define('jquery', function(exports) { // 30 天以内,返回「多久前」 if(stamp >= 1000*60*60*24){ - return ((stamp/1000/60/60/24)|0) + ' ' + layui.$t('天前'); + return ((stamp/1000/60/60/24)|0) + layui.$t('lay.util.timeAgo.days'); } else if(stamp >= 1000*60*60){ - return ((stamp/1000/60/60)|0) + ' ' + layui.$t('小时前'); + return ((stamp/1000/60/60)|0) + layui.$t('lay.util.timeAgo.hours'); } else if(stamp >= 1000*60*3){ // 3 分钟以内为:刚刚 - return ((stamp/1000/60)|0) + ' ' + layui.$t('分钟前'); + return ((stamp/1000/60)|0) + layui.$t('lay.util.timeAgo.minutes'); } else if(stamp < 0){ - return layui.$t('未来'); + return layui.$t('lay.util.timeAgo.future'); } else { - return layui.$t('刚刚'); + return layui.$t('lay.util.timeAgo.justNow'); } }, @@ -305,20 +305,20 @@ layui.define('jquery', function(exports) { var defaultMeridiem = function(hours, minutes){ var hm = hours * 100 + minutes; if (hm < 600) { - return layui.$t('凌晨'); + return '凌晨'; } else if (hm < 900) { - return layui.$t('早上'); + return '早上'; } else if (hm < 1100) { - return layui.$t('上午'); + return '上午'; } else if (hm < 1300) { - return layui.$t('中午'); + return '中午'; } else if (hm < 1800) { - return layui.$t('下午'); + return '下午'; } - return layui.$t('晚上'); + return '晚上'; }; - var meridiem = (options && options.customMeridiem) || defaultMeridiem; + var meridiem = (options && options.customMeridiem) || layui.$t('lay.util.toDateString.meridiem') || defaultMeridiem; var matches = { yy: function(){return String(years).slice(-2);},