diff --git a/Sources/MiniPlayerApp.swift b/Sources/MiniPlayerApp.swift index 99f46cb..4ecf556 100644 --- a/Sources/MiniPlayerApp.swift +++ b/Sources/MiniPlayerApp.swift @@ -15,6 +15,7 @@ struct MiniPlayerApp: App { .onAppear { bridge.setup() setupBridgeEvents() + loadI18n() } } #if os(macOS) @@ -108,6 +109,20 @@ struct MiniPlayerApp: App { bridge.openFileDialog() } } + + // 加载 i18n 翻译 + private func loadI18n() { + // 检测系统语言 + let locale = Locale.current.language.languageCode?.identifier ?? "en" + let langFile = (locale == "zh") ? "zh" : "en" + + if let url = Bundle.module.url(forResource: "i18n/\(langFile)", withExtension: "json"), + let data = try? Data(contentsOf: url), + let dict = try? JSONSerialization.jsonObject(with: data) as? [String: String] { + engine.i18n.loadMessages(dict) + engine.i18n.locale = langFile + } + } } // MARK: - BricksView wrapper @@ -117,7 +132,7 @@ struct BricksAppView: View { @State private var jsonString: String? var body: some View { - ZStack { + ZStack(alignment: .topLeading) { if let json = jsonString { BricksView(json: json, engine: engine) } else { @@ -126,6 +141,11 @@ struct BricksAppView: View { jsonString = loadJSONString() } } + + // 左上角应用图标 + MiniPlayerIcon() + .frame(width: 32, height: 32) + .padding(12) } .sheet(isPresented: $bridge.showURLDialog) { URLInputDialog(bridge: bridge) diff --git a/Sources/Resources/i18n/en.json b/Sources/Resources/i18n/en.json new file mode 100644 index 0000000..6a1fe21 --- /dev/null +++ b/Sources/Resources/i18n/en.json @@ -0,0 +1,9 @@ +{ + "open": "Open", + "prev": "Prev", + "play_pause": "Play/Pause", + "next": "Next", + "url_placeholder": "Enter video URL...", + "load": "Load", + "fullscreen": "Fullscreen" +} diff --git a/Sources/Resources/i18n/zh.json b/Sources/Resources/i18n/zh.json new file mode 100644 index 0000000..6158fa1 --- /dev/null +++ b/Sources/Resources/i18n/zh.json @@ -0,0 +1,9 @@ +{ + "open": "打开", + "prev": "上一个", + "play_pause": "播放/暂停", + "next": "下一个", + "url_placeholder": "输入视频URL...", + "load": "加载", + "fullscreen": "全屏" +} diff --git a/Sources/Resources/miniplayer.ui b/Sources/Resources/miniplayer.ui index de8f1b5..c36bfeb 100644 --- a/Sources/Resources/miniplayer.ui +++ b/Sources/Resources/miniplayer.ui @@ -28,7 +28,7 @@ "widgettype": "Button", "id": "openBtn", "options": { - "label": "Open", + "label": "open", "icon": "folder", "cwidth": 8, "cheight": 4, @@ -48,7 +48,7 @@ "widgettype": "Button", "id": "prevBtn", "options": { - "label": "Prev", + "label": "prev", "icon": "backward.fill", "cwidth": 8, "cheight": 4, @@ -68,7 +68,7 @@ "widgettype": "Button", "id": "toggleBtn", "options": { - "label": "Play/Pause", + "label": "play_pause", "icon": "playpause.fill", "cwidth": 12, "cheight": 4, @@ -88,7 +88,7 @@ "widgettype": "Button", "id": "nextBtn", "options": { - "label": "Next", + "label": "next", "icon": "forward.fill", "cwidth": 8, "cheight": 4, @@ -112,7 +112,7 @@ "id": "videoUrlInput", "options": { "name": "url", - "placeholder": "Enter video URL...", + "placeholder": "url_placeholder", "cwidth": 30, "cheight": 4 } @@ -121,7 +121,7 @@ "widgettype": "Button", "id": "loadBtn", "options": { - "label": "Load", + "label": "load", "icon": "arrow.down.circle.fill", "cwidth": 8, "cheight": 4, @@ -142,7 +142,7 @@ "widgettype": "Button", "id": "fullscreenBtn", "options": { - "label": "Fullscreen", + "label": "fullscreen", "icon": "arrow.up.left.and.arrow.down.right", "cwidth": 10, "cheight": 4,