From 8e024db8eab05974f3a9c9e936aefc8b8a182966 Mon Sep 17 00:00:00 2001 From: Sthkm3 Date: Mon, 9 Mar 2026 02:22:33 +0800 Subject: [PATCH] pre-1 --- src/i18n.js | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/src/i18n.js b/src/i18n.js index c8a7b7b..2720630 100644 --- a/src/i18n.js +++ b/src/i18n.js @@ -1,5 +1,31 @@ +/** + * 專案名稱: AutoCatAndSoup + * Copyright (C) 2026 Sthkm3 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + const i18n = {}; +const locale = java.util.Locale.getDefault().getLanguage(); + +let currentLang = "zh"; + +if (locale.startsWith("en")) { + currentLang = "en"; +} + // 支援的語系定義 const languages = { "zh": { @@ -75,8 +101,11 @@ const languages = { } }; -// 獲取當前語系 (預設英文,如果是中文則回傳中文) -let sysLang = java.util.Locale.getDefault().getLanguage(); -let currentStrings = sysLang.match(/^zh/) ? languages["zh"] : languages["en"]; +function t(key){ + if(languages[currentLang] && languages[currentLang][key]){ + return languages[currentLang][key]; + } + return key; +} -module.exports = currentStrings; +module.exports = t;