From 539a56279625242c497b4b4093f2defbb9d80334 Mon Sep 17 00:00:00 2001
From: lty <876263681@qq.com>
Date: 星期四, 29 一月 2026 14:05:44 +0800
Subject: [PATCH] #i18n翻译
---
src/main/webapp/static/js/i18n/i18n-helper.js | 96 +++++++++++++++++++++++++++++++++++------------
1 files changed, 71 insertions(+), 25 deletions(-)
diff --git a/src/main/webapp/static/js/i18n/i18n-helper.js b/src/main/webapp/static/js/i18n/i18n-helper.js
index 46dbf9c..9b955e7 100644
--- a/src/main/webapp/static/js/i18n/i18n-helper.js
+++ b/src/main/webapp/static/js/i18n/i18n-helper.js
@@ -61,7 +61,30 @@
});
function t(key, params) {
- var text = messages[key] || key;
+ var text = messages[key];
+
+ // Support nested keys (e.g. "form.select.noMatch") if not found directly
+ if (text === undefined && key.indexOf('.') !== -1) {
+ var parts = key.split('.');
+ var current = messages;
+ for (var i = 0; i < parts.length; i++) {
+ if (current[parts[i]] !== undefined) {
+ current = current[parts[i]];
+ } else {
+ current = undefined;
+ break;
+ }
+ }
+ if (current !== undefined && typeof current === 'string') {
+ text = current;
+ }
+ }
+
+ // Fallback to key if still not found
+ if (text === undefined) {
+ text = key;
+ }
+
if (params) {
for (var prop in params) {
text = text.replace(new RegExp('{{' + prop + '}}', 'g'), params[prop]);
@@ -96,6 +119,14 @@
var text = t(key);
$(this).attr('placeholder', text);
});
+
+ // Handle data-i18n-lay-tips
+ $root.find('[data-i18n-lay-tips]').each(function() {
+ var key = $(this).attr('data-i18n-lay-tips');
+ if (!key) return;
+ var text = t(key);
+ $(this).attr('lay-tips', text);
+ });
// Trigger a custom event for JS to listen to if needed (only if full page update)
if (!root) {
@@ -111,6 +142,10 @@
function getLanguage() {
return lang;
+ }
+
+ function checkReady() {
+ return isReady;
}
// Initialize
@@ -139,24 +174,21 @@
// Update 'Go to [input] page [button]'
$('.layui-laypage-skip').each(function() {
var $this = $(this);
- // Replace "鍒扮" (First text node)
- var contents = $this.contents();
- for (var i = 0; i < contents.length; i++) {
- if (contents[i].nodeType === 3 && contents[i].textContent.trim() !== '') {
- // Assuming the first non-empty text node is "鍒扮"
- contents[i].textContent = t('jump_to');
- break;
+
+ // Iterate over all child nodes to find text nodes containing specific keywords
+ $this.contents().each(function() {
+ if (this.nodeType === 3) { // Text node
+ var text = this.textContent;
+ // Replace "鍒扮" or "Go to"
+ if (text.indexOf('鍒扮') !== -1 || text.indexOf('Go to') !== -1) {
+ this.textContent = t('jump_to');
+ }
+ // Replace "椤�" or "page" (but excluding "items/page" if somehow mixed, though usually that's in select)
+ else if (text.indexOf('椤�') !== -1 || (text.indexOf('page') !== -1 && text.indexOf('items/page') === -1)) {
+ this.textContent = t('page');
+ }
}
- }
-
- // Replace "椤�" (Text node after input)
- var input = $this.find('.layui-input');
- if (input.length) {
- var nextNode = input[0].nextSibling;
- if (nextNode && nextNode.nodeType === 3) {
- nextNode.textContent = t('page');
- }
- }
+ });
// Replace Button text
var btn = $this.find('.layui-laypage-btn');
@@ -170,14 +202,28 @@
var text = $(this).text();
var limit = text.match(/\d+/);
if (limit) {
- $(this).text(limit[0] + t('items_per_page'));
+ var newText = limit[0] + t('items_per_page');
+ $(this).text(newText);
+
+ // If this is the selected option, update the custom Layui select input if present
+ if ($(this).is(':selected')) {
+ var $select = $(this).parent();
+ var $layuiSelect = $select.next('.layui-form-select');
+ if ($layuiSelect.length) {
+ $layuiSelect.find('.layui-select-title input').val(newText);
+ }
+ }
}
});
- // Force render of select to update displayed text if needed,
- // but usually Layui re-renders select only on form.render.
- // For pagination limits, it's a browser native select usually?
- // No, Layui table might use native select for limits in some versions,
- // but often it's native. Let's check visually or assume native for now.
+
+ // Also update the dd options in the custom select (if Layui rendered it)
+ $('.layui-laypage-limits .layui-form-select dl dd').each(function() {
+ var text = $(this).text();
+ var limit = text.match(/\d+/);
+ if (limit) {
+ $(this).text(limit[0] + t('items_per_page'));
+ }
+ });
}
return {
@@ -186,6 +232,6 @@
getLanguage: getLanguage,
updatePage: updatePage,
updateLayuiPagination: updateLayuiPagination,
- isReady: function() { return isReady; }
+ isReady: checkReady
};
})();
--
Gitblit v1.9.1