How to Configure Emoji and Translation Filters in the Wanxiang Rime Schema
Wanxiang provides two built-in Lua filters—emoji and chinese_english—that append visual symbols or bilingual translations to candidates when activated via schema switches in wanxiang.schema.yaml.
The Wanxiang RIME input method schema (amzxyz/rime_wanxiang) enriches the candidate list through optional super_replacer filters that operate on tab-separated dictionary files. By configuring these filters, you can display emoji characters next to Chinese phrases or show English-Chinese translation pairs without modifying the core dictionary. This guide details the switch configuration, data file formats, and runtime activation methods.
Understanding the Filter Architecture
Wanxiang implements emoji and translation support through a single Lua module called super_replacer, defined in wanxiang/lua/super_replacer.lua. This module acts as a dynamic replacer that loads external data files and appends content to candidates only when specific option switches are enabled.
The architecture separates presentation logic from data storage:
emojifilter: Readslua/data/emoji.txtand appends graphic symbols to candidates when the switch is set to "表情开" (emoji on).chinese_englishfilter: Readslua/data/english_chinese.txtandlua/data/chinese_english.txtto display bilingual translation comments (e.g., "hello 〔你好 | 哈喽〕") when the switch is set to "翻译开" (translation on).
Both filters use tab-separated values (TSV) where the first column represents the input trigger and subsequent columns define the replacement or comment text.
Enabling Filters in wanxiang.schema.yaml
To activate these features, you must define switches in the schema configuration and map them to the super_replacer engine.
Step 1: Declare the switches (lines 24–32 in wanxiang.schema.yaml):
switches:
- name: emoji
states: [ 表情关, 表情开 ]
reset: 0
- name: chinese_english
states: [ 翻译关, 翻译开 ]
reset: 0
Step 2: Configure the super_replacer (lines 124–138 in wanxiang.schema.yaml):
super_replacer:
types:
- option: emoji
mode: append
comment_mode: none
tags: [abc]
prefix: "_em_"
files:
- lua/data/emoji.txt
- option: chinese_english
mode: append
comment_mode: none
tags: [abc]
prefix: "_en_"
files:
- lua/data/english_chinese.txt
- lua/data/chinese_english.txt
The option field must match the switch name exactly. The files array specifies the data sources, while mode: append ensures the content appears after the candidate text rather than replacing it.
Runtime Toggle and Session Persistence
Once configured, users can toggle these filters without editing configuration files.
Via the Rime UI:
Press Control+grave (default schema selector shortcut) to open the 方案选单. Navigate to:
- 表情开 / 表情关 — Enables or disables the emoji filter.
- 翻译开 / 翻译关 — Enables or disables the translation filter.
Persistence Configuration:
Switch states are automatically remembered across sessions because both emoji and chinese_english are listed in the save_options array in wanxiang/default.yaml (line 28):
switcher:
save_options:
- emoji
- chinese_english
- ascii_mode
- full_shape
# ... other options
This ensures your preferences persist after reloading the Rime engine or restarting your system.
Customizing Emoji and Translation Data
You can extend the built-in dictionaries by editing the tab-separated data files. Changes require a Rime reload (Ctrl+Shift+F5 in the Rime menu) to take effect.
Adding Custom Emoji:
Edit wanxiang/lua/data/emoji.txt and append entries in the format:
keyword<TAB>text_representation<TAB>emoji_symbol
For example:
笑脸 🙂
火箭 🚀
When the emoji filter is active, typing 笑脸 will display the candidate followed by 🙂.
Adding Translation Pairs:
Edit wanxiang/lua/data/english_chinese.txt (English to Chinese) or wanxiang/lua/data/chinese_english.txt (Chinese to English):
world 世界
example 例子
The translation filter will then display "世界" as a comment when you type "world" (or vice versa depending on the file).
Core Implementation Files
| File | Purpose | Key Components |
|---|---|---|
wanxiang/wanxiang.schema.yaml |
Schema definition | Switch declarations (lines 24–32), super_replacer configuration (lines 124–138) |
wanxiang/default.yaml |
Default settings | save_options list (line 28) for persistence |
wanxiang/lua/super_replacer.lua |
Filter engine | Lua logic for reading TSV files and appending content |
wanxiang/lua/data/emoji.txt |
Emoji database | Tab-separated keyword-to-symbol mappings |
wanxiang/lua/data/english_chinese.txt |
EN→CN dictionary | Bilingual pairs for translation comments |
wanxiang/lua/data/chinese_english.txt |
CN→EN dictionary | Reverse translation pairs |
Summary
- Two filters available:
emojifor symbols andchinese_englishfor bilingual translations, both implemented viasuper_replacer.lua. - Schema configuration: Define switches in
wanxiang.schema.yaml(lines 24–32) and link them to file paths in thesuper_replacerblock (lines 124–138). - Runtime control: Toggle via
Control+gravemenu using "表情开/关" and "翻译开/关" options. - Data customization: Edit TSV files in
lua/data/to add new emoji or translations, then reload Rime withCtrl+Shift+F5. - Persistence: Switch states are saved automatically via
default.yamlsave_options.
Frequently Asked Questions
How do I permanently enable the emoji filter by default?
Set reset: 1 instead of reset: 0 in the switch definition within wanxiang.schema.yaml. This initializes the filter to the "on" state (表情开) when Rime starts, though users can still toggle it off via the schema menu.
Can I use custom data files for the emoji filter?
Yes. Modify the files array under the emoji option in the super_replacer configuration to point to your own TSV files. Ensure the format matches keyword<TAB>text<TAB>symbol, and place the files in a location accessible to the Rime Lua engine (typically under the lua/ directory).
Why don't my new emoji appear immediately after editing the text file?
The super_replacer module loads data into memory when Rime initializes. You must reload the Rime engine using the menu shortcut (usually Ctrl+Shift+F5 or F5 depending on your frontend) to re-import the updated emoji.txt or translation files.
What is the difference between mode: append and other modes in super_replacer?
As implemented in wanxiang.schema.yaml, mode: append adds the matched content after the candidate text. The comment_mode: none setting ensures the addition appears as part of the candidate rather than as a separate comment field, creating the inline display effect for emoji and translations.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →