From d486c9e924ef3fbfe13866718b9eabbf57d8c17b Mon Sep 17 00:00:00 2001 From: Mingyu Date: Wed, 26 Nov 2025 07:49:59 +0000 Subject: [PATCH] mobile done --- src/core/i18n.js | 15 +++++++++++ src/i18n/en.json | 7 +++--- src/i18n/zh-tw.json | 7 +++--- src/systems/features/dice.js | 3 +++ src/systems/ui/desktop.js | 6 ++--- src/systems/ui/mobile.js | 48 +++++++++++++++++++++++++++++++++--- 6 files changed, 73 insertions(+), 13 deletions(-) diff --git a/src/core/i18n.js b/src/core/i18n.js index 5325cf9..315b4e4 100644 --- a/src/core/i18n.js +++ b/src/core/i18n.js @@ -5,6 +5,20 @@ class Internationalization { constructor() { this.currentLanguage = 'en'; this.translations = {}; + this._listeners = {}; + } + + addEventListener(event, callback) { + if (!this._listeners[event]) { + this._listeners[event] = []; + } + this._listeners[event].push(callback); + } + + dispatchEvent(event, data) { + if (this._listeners[event]) { + this._listeners[event].forEach(callback => callback(data)); + } } async init() { @@ -82,6 +96,7 @@ class Internationalization { localStorage.setItem('rpgCompanionLanguage', lang); await this.loadTranslations(lang); this.applyTranslations(document.body); + this.dispatchEvent('languageChanged'); } } diff --git a/src/i18n/en.json b/src/i18n/en.json index 4143543..10835b6 100644 --- a/src/i18n/en.json +++ b/src/i18n/en.json @@ -118,9 +118,10 @@ "global.listView": "List view", "global.gridView": "Grid view", "global.save": "Save", - "desktop.tab.status":"Status", - "desktop.tab.inventory":"Inventory", - "desktop.tab.quests":"Quests", + "global.status":"Status", + "global.inventory":"Inventory", + "global.quests":"Quests", + "global.info":"Info", "infobox.noData.title": "No data yet", "infobox.noData.instruction": "Generate a new response in the roleplay or switch to \"Separate Generation\" in Settings to access and click the \"Refresh RPG Info\" button", "infobox.recentEvents.title": "Recent Events", diff --git a/src/i18n/zh-tw.json b/src/i18n/zh-tw.json index cd415b9..3714b09 100644 --- a/src/i18n/zh-tw.json +++ b/src/i18n/zh-tw.json @@ -118,9 +118,10 @@ "global.save": "保存", "global.listView": "清單檢視", "global.gridView": "格子檢視", - "desktop.tab.status": "狀態欄", - "desktop.tab.inventory": "物品欄", - "desktop.tab.quests": "任務", + "global.status": "狀態欄", + "global.inventory": "物品欄", + "global.quests": "任務", + "global.info":"資訊", "infobox.noData.title": "無資訊可顯示", "infobox.noData.instruction": "在RP中產生新的回复,或在設定中切換到“單獨生成”,然後點擊“刷新資訊”按鈕。", "infobox.recentEvents.title": "近期事件", diff --git a/src/systems/features/dice.js b/src/systems/features/dice.js index fe5a0c4..3e452d1 100644 --- a/src/systems/features/dice.js +++ b/src/systems/features/dice.js @@ -115,3 +115,6 @@ export function addDiceQuickReply() { // For now, the dice display in the sidebar serves as the button } } + +// Add event listener to update display on language change +i18n.addEventListener('languageChanged', updateDiceDisplay); diff --git a/src/systems/ui/desktop.js b/src/systems/ui/desktop.js index fa08743..fb35e4f 100644 --- a/src/systems/ui/desktop.js +++ b/src/systems/ui/desktop.js @@ -36,15 +36,15 @@ export function setupDesktopTabs() {
`); diff --git a/src/systems/ui/mobile.js b/src/systems/ui/mobile.js index e25b330..5977ef8 100644 --- a/src/systems/ui/mobile.js +++ b/src/systems/ui/mobile.js @@ -7,12 +7,52 @@ import { extensionSettings } from '../../core/state.js'; import { saveSettings } from '../../core/persistence.js'; import { closeMobilePanelWithAnimation, updateCollapseToggleIcon } from './layout.js'; import { setupDesktopTabs, removeDesktopTabs } from './desktop.js'; +import { i18n } from '../../core/i18n.js'; /** * Sets up the mobile toggle button (FAB) with drag functionality. * Handles touch/mouse events for positioning and panel toggling. */ export function setupMobileToggle() { + /** + * Updates the text labels of the mobile navigation tabs based on the current language. + */ + function updateMobileTabLabels() { + const $tabs = $('.rpg-mobile-tabs .rpg-mobile-tab'); + if ($tabs.length === 0) return; + + $tabs.each(function() { + const $tab = $(this); + const tabName = $tab.data('tab'); + let translationKey = ''; + + switch (tabName) { + case 'stats': + translationKey = 'global.status'; + break; + case 'info': + translationKey = 'global.info'; + break; + case 'inventory': + translationKey = 'global.inventory'; + break; + case 'quests': + translationKey = 'global.quests'; + break; + } + + if (translationKey) { + const translation = i18n.getTranslation(translationKey); + if (translation) { + $tab.find('span').text(translation); + } + } + }); + } + + // Listen for language changes to update tab labels dynamically + i18n.addEventListener('languageChanged', updateMobileTabLabels); + const $mobileToggle = $('#rpg-mobile-toggle'); const $panel = $('#rpg-companion-panel'); const $overlay = $('
'); @@ -547,19 +587,19 @@ export function setupMobileTabs() { // Tab 1: Stats (User Stats only) if (hasStats) { - tabs.push(''); + tabs.push(''); } // Tab 2: Info (Info Box + Character Thoughts) if (hasInfo) { - tabs.push(''); + tabs.push(''); } // Tab 3: Inventory if (hasInventory) { - tabs.push(''); + tabs.push(''); } // Tab 4: Quests if (hasQuests) { - tabs.push(''); + tabs.push(''); } const $tabNav = $('
' + tabs.join('') + '
');