| | |
| | | }); |
| | | |
| | | 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]); |
| | |
| | | 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) { |
| | |
| | | |
| | | function getLanguage() { |
| | | return lang; |
| | | } |
| | | |
| | | function checkReady() { |
| | | return isReady; |
| | | } |
| | | |
| | | // Initialize |
| | |
| | | // 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'); |
| | |
| | | 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 { |
| | |
| | | getLanguage: getLanguage, |
| | | updatePage: updatePage, |
| | | updateLayuiPagination: updateLayuiPagination, |
| | | isReady: function() { return isReady; } |
| | | isReady: checkReady |
| | | }; |
| | | })(); |