Skip to content

Commit 7782c4e

Browse files
committed
rime: give each Windows input language its own ime.json folder
One manifest is one Windows input language profile, so each dispatcher again compares the flat guid only: langProfileFromJson returns the single profile, the python and node dispatchers and the go loader match it directly, and the header-only helper loses the array walk. The rime engine serves zh-Hant-TW and zh-CN, so both backends now ship input_methods/rime and input_methods/rime-cn, each with its own profile GUID, while the shared engine (librime.py, rime_keyevent.py, rime_service.py, rime.dll, data/, icons/) sits once under python/rimebase and the two wrappers re-export one RimeTextService. The installer stages the engine folder plus the two IME folders.
1 parent 95f4737 commit 7782c4e

34 files changed

Lines changed: 439 additions & 468 deletions

‎PIMELauncher/src/elevation.rs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Generated by omp (Qwen3.8-Flash-Next) without human creative authorship.
2+
// SPDX-License-Identifier: LGPL-2.1-or-later
3+
14
/// Whether the launcher should surface the elevation warning for this process.
25
///
36
/// Only the interactive watchdog instance warns: the worker child inherits the

‎PIMETextService/DllEntry.cpp‎

Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,11 @@ STDAPI DllUnregisterServer(void) {
7878
return module ? module->unregisterServer() : E_FAIL;
7979
}
8080

81-
// One ime.json may declare more than one language profile: the primary pair
82-
// under "locale"/"fallbackLocale", and any number of extra profiles under
83-
// "additionalProfiles", each with its own profile GUID. A manifest such as
84-
// the rime one, whose engine is used under both the Traditional and the
85-
// Simplified Chinese Windows locale, then registers under both buckets
86-
// instead of only the one its first locale name resolves to.
81+
// One ime.json is one language profile: `guid` names the profile and
82+
// "locale"/"fallbackLocale" the Windows input-language bucket it appears under
83+
// (PIMETextService/DllEntry.cpp → libIME2/ImeModule.cpp:registerLangProfiles).
84+
// An IME that serves two buckets ships one folder per bucket, so
85+
// langProfileFromJson returns the single profile the manifest declares.
8786
static inline std::vector<Ime::LangProfileInfo> langProfileFromJson(const std::wstring& file, int iconIndex) {
8887
std::vector<Ime::LangProfileInfo> profiles;
8988
// load the json file to get the info of input method
@@ -126,34 +125,6 @@ static inline std::vector<Ime::LangProfileInfo> langProfileFromJson(const std::w
126125
iconFile,
127126
iconIndex
128127
});
129-
130-
// Extra language profiles for the same text service, each with its own
131-
// profile GUID so both appear in the language list.
132-
if (j.contains("additionalProfiles") && j["additionalProfiles"].is_array()) {
133-
for (const auto& extra : j["additionalProfiles"]) {
134-
if (!extra.is_object()) {
135-
continue;
136-
}
137-
auto extraGuid = jsonValueOr<std::string>(extra, "guid", "");
138-
auto extraLocale = jsonValueOr<std::string>(extra, "locale", "");
139-
if (extraGuid.empty() || extraLocale.empty()) {
140-
continue;
141-
}
142-
CLSID extraClsid = {0};
143-
if (FAILED(CLSIDFromString(utf8ToUtf16(extraGuid.c_str()).c_str(), &extraClsid))) {
144-
continue;
145-
}
146-
auto extraFallback = utf8ToUtf16(jsonValueOr<std::string>(extra, "fallbackLocale", "").c_str());
147-
profiles.push_back(Ime::LangProfileInfo{
148-
name,
149-
extraClsid,
150-
utf8ToUtf16(extraLocale.c_str()),
151-
std::move(extraFallback),
152-
iconFile,
153-
iconIndex
154-
});
155-
}
156-
}
157128
return profiles;
158129
}
159130

‎PIMETextService/ImeProfileGuids.h‎

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -47,33 +47,15 @@ inline bool imeProfileGuidEqual(const std::string& a, const std::string& b) noex
4747
return true;
4848
}
4949

50-
// True when `id` names the profile of a parsed ime.json object: the flat
51-
// "guid" key, or one "guid" of the "additionalProfiles" array. A non-object
52-
// entry, a missing or non-string "guid" key, and an empty "guid" are skipped
53-
// without throwing; an empty `id` therefore matches nothing.
50+
// True when `id` names the profile of a parsed ime.json object: its flat
51+
// "guid" key. One manifest is one Windows language profile, so no array is
52+
// walked; a missing or non-string "guid" key and an empty "guid" are skipped
53+
// without throwing, and an empty `id` therefore matches nothing.
5454
inline bool imeProfileGuidMatches(const nlohmann::json& content, const std::string& id) noexcept {
5555
const auto guid = content.find("guid");
56-
if (guid != content.end() && guid->is_string() &&
57-
imeProfileGuidEqual(id, guid->get_ref<const std::string&>())) {
58-
return true;
59-
}
60-
const auto profiles = content.find("additionalProfiles");
61-
if (profiles != content.end() && profiles->is_array()) {
62-
for (const auto& profile : *profiles) {
63-
if (!profile.is_object()) {
64-
continue; // a null or scalar entry carries no guid
65-
}
66-
const auto entry = profile.find("guid");
67-
if (entry == profile.end() || !entry->is_string() ||
68-
entry->get_ref<const std::string&>().empty()) {
69-
continue; // a guid-less entry cannot name the profile
70-
}
71-
if (imeProfileGuidEqual(id, entry->get_ref<const std::string&>())) {
72-
return true;
73-
}
74-
}
75-
}
76-
return false;
56+
return guid != content.end() && guid->is_string() &&
57+
!guid->get_ref<const std::string&>().empty() &&
58+
imeProfileGuidEqual(id, guid->get_ref<const std::string&>());
7759
}
7860

7961
} // namespace PIME

‎PIMETextService/PIMEImeModule.cpp‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,10 @@ bool ImeModule::loadImeInfo(const std::string& guid, std::wstring& filePath, jso
120120
if (!content.is_object() || content.is_discarded()) {
121121
continue;
122122
}
123-
// The flat guid plus every additionalProfiles guid name
124-
// this service; the match is a header-only helper so the
125-
// local gates can run it without the Windows SDK.
123+
// One folder is one language profile, so the flat
124+
// guid names it; the match is a header-only helper
125+
// so the local gates can run it without the
126+
// Windows SDK.
126127
bool matched = imeProfileGuidMatches(content, guid);
127128
if (matched) {
128129
// found the language profile
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name":"中州韻輸入法 (PIME - Go)",
3+
"version": "0.1",
4+
"guid": "{9882E350-9462-4D42-9882-7847044EA725}",
5+
"locale": "zh-CN",
6+
"fallbackLocale": "zh-CN",
7+
"icon": "",
8+
"win8_icon": "",
9+
"moduleName": "rime",
10+
"serviceName": "RimeTextService"
11+
}

‎go-backend/input_methods/rime/ime.json‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33
"version": "0.1",
44
"guid": "{3F6B5A12-8D44-4E71-9A2E-6B4F9C1D2A30}",
55
"locale": "zh-Hant-TW",
6-
"fallbackLocale": "zh-TW",
7-
"additionalProfiles": [
8-
{"guid": "{9882E350-9462-4D42-9882-7847044EA725}", "locale": "zh-CN", "fallbackLocale": "zh-CN"}
9-
],
6+
"fallbackLocale": "zh-TW",
107
"icon": "",
118
"win8_icon": "",
129
"moduleName": "rime",

‎go-backend/server.go‎

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -334,27 +334,8 @@ func (s *Server) convertResponse(resp *pime.Response) map[string]interface{} {
334334
}
335335

336336
// loadInputMethods 加载所有输入法
337-
// additionalProfileGuids 回傳 ime.json 的 additionalProfiles 中每個語言檔的
338-
// GUID(轉小寫,與 RegisterService 的鍵一致)。缺 guid 或格式不對的條目略過,
339-
// 與 flat 的 guid 鍵相同。
340-
func additionalProfileGuids(imeConfig map[string]interface{}) []string {
341-
guids := []string{}
342-
profiles, ok := imeConfig["additionalProfiles"].([]interface{})
343-
if !ok {
344-
return guids
345-
}
346-
for _, item := range profiles {
347-
profile, ok := item.(map[string]interface{})
348-
if !ok {
349-
continue
350-
}
351-
if profileGuid, ok := profile["guid"].(string); ok && profileGuid != "" {
352-
guids = append(guids, strings.ToLower(profileGuid))
353-
}
354-
}
355-
return guids
356-
}
357-
337+
// 每個 input_methods 目錄就是一個 Windows 輸入語言檔:一份 ime.json、一個
338+
// profile GUID,所以這裡只需註冊該目錄自己的 guid。
358339
func loadInputMethods(server *Server) {
359340
// 获取当前目录
360341
exePath, err := os.Executable()
@@ -398,9 +379,8 @@ func loadInputMethods(server *Server) {
398379
continue
399380
}
400381

401-
// 同一個 service 也可由額外語言檔(additionalProfiles,另一個 Windows
402-
// 輸入語言)的 GUID 啟動,所以每個 profile GUID 都註冊同一個實作。
403-
guids := append([]string{guid}, additionalProfileGuids(imeConfig)...)
382+
// 一個目錄一個語言檔:註冊自己的 guid 即可。
383+
guids := []string{guid}
404384

405385
log.Printf("加载输入法: %s (%s)", name, guid)
406386

@@ -413,8 +393,9 @@ func loadInputMethods(server *Server) {
413393
return meow.New(client)
414394
})
415395
}
416-
case "rime":
417-
// RIME 输入法
396+
case "rime", "rime-cn":
397+
// RIME 输入法:兩個語言檔(zh-Hant-TW 與 zh-CN)共用同一個實作,
398+
// 各自的 ime.json 只帶自己的 profile GUID。
418399
for _, id := range guids {
419400
server.RegisterService(id, func(client *pime.Client, g string) pime.TextService {
420401
return rime.New(client)

‎installer/installer.nsi‎

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -368,16 +368,22 @@ SectionGroup /e $(PYTHON_SECTION_GROUP) python_section_group
368368
SectionGroup /e $(PYTHON_CHS_SECTION_GROUP) python_chs_section_group
369369
Section $(RIME) rime
370370
SectionIn 2
371-
SetOutPath "$INSTDIR\python\input_methods\rime"
372-
File /r /x "brise" "..\python\input_methods\rime\*.*"
373-
SetOutPath "$INSTDIR\python\input_methods\rime\data"
374-
File "..\python\input_methods\rime\brise\*.txt"
375-
File "..\python\input_methods\rime\brise\*.yaml"
376-
File "..\python\input_methods\rime\brise\preset\*.yaml"
377-
File "..\python\input_methods\rime\brise\supplement\*.yaml"
378-
File "..\python\input_methods\rime\brise\extra\*.yaml"
379-
SetOutPath "$INSTDIR\python\input_methods\rime\data\opencc"
371+
SetOutPath "$INSTDIR\python\rimebase"
372+
File /r /x "brise" "..\python\rimebase\*.*"
373+
SetOutPath "$INSTDIR\python\rimebase\data"
374+
File "..\python\rimebase\brise\*.txt"
375+
File "..\python\rimebase\brise\*.yaml"
376+
File "..\python\rimebase\brise\preset\*.yaml"
377+
File "..\python\rimebase\brise\supplement\*.yaml"
378+
File "..\python\rimebase\brise\extra\*.yaml"
379+
SetOutPath "$INSTDIR\python\rimebase\data\opencc"
380380
File "..\python\opencc\*.json" "..\python\opencc\*.ocd"
381+
; one folder per Windows input language: the two profiles of the
382+
; same engine, each with its own ime.json and thin wrapper
383+
SetOutPath "$INSTDIR\python\input_methods\rime"
384+
File "..\python\input_methods\rime\*.*"
385+
SetOutPath "$INSTDIR\python\input_methods\rime-cn"
386+
File "..\python\input_methods\rime-cn\*.*"
381387
StrCpy $INST_PYTHON "True"
382388
SectionEnd
383389
SectionGroupEnd

‎node/loadServices.js‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,8 @@ function loadServiceById(id, baseDir) {
9595
}
9696

9797
let matches = String(config.guid).toLowerCase() === targetId;
98-
// 同一個 service 也可由額外語言檔(additionalProfiles)的 GUID 啟動。
99-
if (!matches && Array.isArray(config.additionalProfiles)) {
100-
matches = config.additionalProfiles.some(
101-
(profile) => profile && typeof profile.guid === 'string' &&
102-
profile.guid.toLowerCase() === targetId);
103-
}
98+
// 一個目錄就是一個語言檔:DllRegisterServer 為每個 ime.json 各發一次
99+
// AddLanguageProfile,所以這裡只需比對該目錄自己的 guid。
104100
if (matches) {
105101
try {
106102
service = require(path.join(imeDir, dir, config.moduleName));
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name":"中州韻輸入法 (PIME)",
3+
"version": "0.1",
4+
"guid": "{53C15256-7A5F-4B54-86E8-0636E0745C3E}",
5+
"locale": "zh-CN",
6+
"fallbackLocale": "zh-CN",
7+
"icon": "../rimebase/icon.ico",
8+
"win8_icon": "",
9+
"moduleName": "rime_ime",
10+
"serviceName": "RimeTextService"
11+
}

0 commit comments

Comments
 (0)