国际化优化
This commit is contained in:
parent
40d7c2f886
commit
cba45ba926
@ -1,5 +1,6 @@
|
||||
package com.goeing.printserver.main.gui;
|
||||
|
||||
import com.goeing.printserver.main.utils.MessageUtils;
|
||||
import jakarta.annotation.PreDestroy;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -56,13 +57,13 @@ public class GUILauncher {
|
||||
|
||||
// 显示欢迎通知
|
||||
printServerTray.displayMessage(
|
||||
"打印服务器已启动",
|
||||
"打印服务器正在后台运行,点击托盘图标可打开主窗口",
|
||||
MessageUtils.getMessage("tray.notification.title"),
|
||||
MessageUtils.getMessage("tray.notification.message"),
|
||||
TrayIcon.MessageType.INFO
|
||||
);
|
||||
|
||||
// 更新托盘提示
|
||||
printServerTray.updateTooltip("打印服务器 - 运行中");
|
||||
printServerTray.updateTooltip(MessageUtils.getMessage("app.name") + " - " + MessageUtils.getMessage("app.status.running"));
|
||||
|
||||
log.info("图形界面已启动");
|
||||
} catch (Exception e) {
|
||||
|
||||
@ -1,5 +1,8 @@
|
||||
package com.goeing.printserver.main.gui;
|
||||
|
||||
import com.goeing.printserver.main.utils.LocaleChangeListener;
|
||||
import com.goeing.printserver.main.utils.LocaleManager;
|
||||
import com.goeing.printserver.main.utils.MessageUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
@ -10,13 +13,14 @@ import java.awt.event.ActionListener;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* 打印服务器系统托盘
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class PrintServerTray {
|
||||
public class PrintServerTray implements LocaleChangeListener {
|
||||
|
||||
private PrintQueueGUI printQueueGUI;
|
||||
private TrayIcon trayIcon;
|
||||
@ -26,6 +30,8 @@ public class PrintServerTray {
|
||||
@Autowired
|
||||
public PrintServerTray() {
|
||||
// 移除构造函数中的PrintQueueGUI依赖,改为在initialize方法中注入
|
||||
// 注册语言变更监听器
|
||||
LocaleManager.getInstance().addLocaleChangeListener(this);
|
||||
}
|
||||
|
||||
@Autowired
|
||||
@ -62,7 +68,7 @@ public class PrintServerTray {
|
||||
|
||||
// 创建托盘图标
|
||||
Image trayImage = createTrayImage();
|
||||
trayIcon = new TrayIcon(trayImage, "打印服务器");
|
||||
trayIcon = new TrayIcon(trayImage, MessageUtils.getMessage("app.name"));
|
||||
trayIcon.setImageAutoSize(true);
|
||||
|
||||
// 创建弹出菜单
|
||||
@ -121,8 +127,8 @@ public class PrintServerTray {
|
||||
PopupMenu popupMenu = new PopupMenu();
|
||||
|
||||
// 添加菜单项
|
||||
MenuItem openItem = new MenuItem("打开主窗口");
|
||||
MenuItem exitItem = new MenuItem("退出");
|
||||
MenuItem openItem = new MenuItem(MessageUtils.getMessage("tray.open"));
|
||||
MenuItem exitItem = new MenuItem(MessageUtils.getMessage("tray.exit"));
|
||||
|
||||
// 设置事件监听器
|
||||
openItem.addActionListener(e -> printQueueGUI.show());
|
||||
@ -162,5 +168,22 @@ public class PrintServerTray {
|
||||
systemTray.remove(trayIcon);
|
||||
log.info("系统托盘图标已移除");
|
||||
}
|
||||
// 移除语言变更监听器
|
||||
LocaleManager.getInstance().removeLocaleChangeListener(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 当语言变更时更新系统托盘
|
||||
*/
|
||||
@Override
|
||||
public void onLocaleChanged(Locale newLocale) {
|
||||
if (traySupported && trayIcon != null) {
|
||||
// 更新托盘图标提示文本
|
||||
trayIcon.setToolTip(MessageUtils.getMessage("app.name"));
|
||||
|
||||
// 更新弹出菜单
|
||||
PopupMenu popupMenu = createPopupMenu();
|
||||
trayIcon.setPopupMenu(popupMenu);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2,6 +2,7 @@ package com.goeing.printserver.main.utils;
|
||||
|
||||
import org.springframework.context.MessageSource;
|
||||
import org.springframework.context.i18n.LocaleContextHolder;
|
||||
import org.springframework.context.support.ResourceBundleMessageSource;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
@ -16,14 +17,23 @@ public class MessageUtils {
|
||||
|
||||
private static MessageSource messageSource;
|
||||
|
||||
// 静态初始化块,确保在类加载时就初始化一个默认的MessageSource
|
||||
static {
|
||||
ResourceBundleMessageSource defaultMessageSource = new ResourceBundleMessageSource();
|
||||
defaultMessageSource.setBasenames("messages");
|
||||
defaultMessageSource.setDefaultEncoding("UTF-8");
|
||||
messageSource = defaultMessageSource;
|
||||
System.out.println("MessageUtils static initialization with default messageSource");
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private MessageSource autowiredMessageSource;
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
// Spring容器启动后,使用注入的MessageSource替换默认的
|
||||
messageSource = autowiredMessageSource;
|
||||
// 添加日志确认初始化完成
|
||||
System.out.println("MessageUtils initialized with messageSource: " + (messageSource != null));
|
||||
System.out.println("MessageUtils initialized with autowired messageSource: " + (messageSource != null));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -42,9 +42,9 @@ tab.settings=Settings
|
||||
tab.current.task=Current Task
|
||||
tab.queued.tasks=Queued Tasks
|
||||
tab.printer.status=Printer Status
|
||||
tab.statistics=Statistics
|
||||
tab.task.search=Task Search
|
||||
tab.settings=Settings
|
||||
|
||||
# Tab Titles
|
||||
|
||||
# Table Headers
|
||||
table.fileUrl=File URL
|
||||
@ -66,6 +66,15 @@ table.header.end.time=End Time
|
||||
# Printer Status Panel
|
||||
printer.status=Printer Status
|
||||
printer.refresh=Refresh
|
||||
printer.status.title=Printer Status
|
||||
printer.status.available=Available
|
||||
|
||||
# Buttons
|
||||
button.refresh=Refresh
|
||||
|
||||
# Table Column Headers (Printer Status)
|
||||
table.header.printer.name=Printer Name
|
||||
table.header.default=Default
|
||||
|
||||
# Statistics Panel
|
||||
stats.title=Print Statistics
|
||||
@ -134,5 +143,13 @@ menu.file.exit=Exit
|
||||
menu.view=View
|
||||
menu.view.always.on.top=Always on Top
|
||||
menu.language=Language
|
||||
|
||||
# System Tray
|
||||
app.name=Print Queue Monitor
|
||||
tray.open=Open Main Window
|
||||
tray.exit=Exit
|
||||
tray.notification.title=Print Server Started
|
||||
tray.notification.message=Print Server is running in the background, click the tray icon to open the main window
|
||||
app.status.running=Running
|
||||
menu.help=Help
|
||||
menu.help.about=About
|
||||
@ -34,9 +34,9 @@ main.status.waiting=Queue Status: Waiting (Queue has {0} tasks)
|
||||
tab.current=Current Task
|
||||
tab.queued=Queued Tasks
|
||||
tab.printers=Printer Status
|
||||
tab.statistics=Statistics
|
||||
tab.search=Task Search
|
||||
tab.settings=Settings
|
||||
|
||||
# Tab Titles
|
||||
|
||||
# Tab Titles
|
||||
tab.current.task=Current Task
|
||||
@ -58,7 +58,6 @@ table.printerName=Printer Name
|
||||
# Table Column Headers
|
||||
table.header.file.url=File URL
|
||||
table.header.printer=Printer
|
||||
table.header.status=Status
|
||||
table.header.queued.time=Queued Time
|
||||
table.header.start.time=Start Time
|
||||
table.header.end.time=End Time
|
||||
@ -66,6 +65,16 @@ table.header.end.time=End Time
|
||||
# Printer Status Panel
|
||||
printer.status=Printer Status
|
||||
printer.refresh=Refresh
|
||||
printer.status.title=Printer Status
|
||||
printer.status.available=Available
|
||||
|
||||
# Buttons
|
||||
button.refresh=Refresh
|
||||
|
||||
# Table Column Headers (Printer Status)
|
||||
table.header.printer.name=Printer Name
|
||||
table.header.status=Status
|
||||
table.header.default=Default
|
||||
|
||||
# Statistics Panel
|
||||
stats.title=Print Statistics
|
||||
@ -134,5 +143,13 @@ menu.file.exit=Exit
|
||||
menu.view=View
|
||||
menu.view.always.on.top=Always on Top
|
||||
menu.language=Language
|
||||
|
||||
# System Tray
|
||||
app.name=Print Queue Monitor
|
||||
tray.open=Open Main Window
|
||||
tray.exit=Exit
|
||||
tray.notification.title=Print Server Started
|
||||
tray.notification.message=Print Server is running in the background, click the tray icon to open the main window
|
||||
app.status.running=Running
|
||||
menu.help=Help
|
||||
menu.help.about=About
|
||||
@ -42,9 +42,7 @@ tab.settings=设置
|
||||
tab.current.task=当前任务
|
||||
tab.queued.tasks=队列任务
|
||||
tab.printer.status=打印机状态
|
||||
tab.statistics=统计信息
|
||||
tab.task.search=任务搜索
|
||||
tab.settings=设置
|
||||
|
||||
# 表格标题
|
||||
table.fileUrl=文件URL
|
||||
@ -58,7 +56,6 @@ table.printerName=打印机名称
|
||||
# 表格列标题
|
||||
table.header.file.url=文件URL
|
||||
table.header.printer=打印机
|
||||
table.header.status=状态
|
||||
table.header.queued.time=队列时间
|
||||
table.header.start.time=开始时间
|
||||
table.header.end.time=结束时间
|
||||
@ -66,6 +63,16 @@ table.header.end.time=结束时间
|
||||
# 打印机状态面板
|
||||
printer.status=打印机状态
|
||||
printer.refresh=刷新
|
||||
printer.status.title=打印机状态
|
||||
printer.status.available=可用
|
||||
|
||||
# 按钮
|
||||
button.refresh=刷新
|
||||
|
||||
# 表格列标题(打印机状态)
|
||||
table.header.printer.name=打印机名称
|
||||
table.header.status=状态
|
||||
table.header.default=默认
|
||||
|
||||
# 统计面板
|
||||
stats.title=打印统计
|
||||
@ -135,4 +142,12 @@ menu.view=视图
|
||||
menu.view.always.on.top=窗口置顶
|
||||
menu.language=语言
|
||||
menu.help=帮助
|
||||
menu.help.about=关于
|
||||
menu.help.about=关于
|
||||
|
||||
# 系统托盘
|
||||
app.name=打印队列监控
|
||||
tray.open=打开主窗口
|
||||
tray.exit=退出
|
||||
tray.notification.title=打印服务器已启动
|
||||
tray.notification.message=打印服务器正在后台运行,点击托盘图标可打开主窗口
|
||||
app.status.running=运行中
|
||||
Loading…
Reference in New Issue
Block a user