<p>I found one (may be the only preexisted one throughout the Internet) on Github. Link: <a href="https://github.com/Jerryzhao-z/chinese2cangjie" rel="nofollow noreferrer">https://github.com/Jerryzhao-z/chinese2cangjie</a></p>
<hr />
<p>Edit:</p>
<p>I've tried the script by following steps and it worked on Windows 10.</p>
<ol>
<li>Install Python 3.7 and configure system environment variants.</li>
<li>Download source code ZIP and unzip it. Enter unzipped &quot;chinese2cangjie-master&quot; folder.</li>
<li>Create a new .txt file in that folder and rename it into &quot;Convert.<strong>bat</strong>&quot; (Note: the extension is changed). Edit this file and input following command lines and save.</li>
</ol>
<pre><code>python c_transform.py --input input.txt --output output.txt --mode 0
pause
</code></pre>
<ol start="4">
<li>Create a new .txt file in the folder and rename it into &quot;input.txt&quot;. Edit this file and input Chinese characters need converting (such as <em>&quot;冇倉頡輸入法&quot;</em>) and Save.</li>
<li>Create a new .txt file in the folder and rename it into &quot;output.txt&quot;. Leave it empty.</li>
<li>Run &quot;Convert.bat&quot; and wait. After finishing, open &quot;output.txt&quot; and you'll get Cangjie codes (such as <em>&quot;xkb oiar grmbc jjomn oh egi&quot;</em>).</li>
<li>If you want to convert Cangjie to character, just input Cangjie codes in the &quot;input.txt&quot; and change the number 0 to 1 in &quot;Convert.bat&quot; and run. You will get characters in &quot;output.txt&quot;.</li>
</ol>
<p>By the way, I actually don't understand Cangjie but I found the sentence &quot;<em>kb2 oiar grmbc jjomn oh egi&quot;</em> you gave will not be converted into <em>&quot;冇倉頡輸入法&quot;</em> but <em>&quot;kb２倉頡輸入法&quot;</em> instead. That means &quot;冇&quot; is represented by &quot;xkb&quot; according to the reversed convertion, but not &quot;kb2&quot;. I don't know which is right, however, you can modify the dictionary files (&quot;Cangjie5.txt&quot; and/or &quot;char2cangjie.json&quot;) to avoid this if needed, I guess.</p>

CC BY-SA 4.0
2021-08-01T22:49:31.960Z
Thank you! Looking at the code, it seems it should be able to do what I want it to. But I'm encountering all sorts of errors and I'm not sure how to fix them. I know I can report issues on github, but have you gotten this working yourself? If so, could you give me some sample inputs to see if I'm just typing something wrong? Thanks!
YQ002lc2
CC BY-SA 4.0
2021-08-02T03:35:48.763Z
Sorry, I haven't tested the code yet. I will try it later this afternoon and reply to you then.
xzqsr
CC BY-SA 4.0
2021-08-02T09:48:30.477Z
Hi, I just edited my answer! @YQ002lc2
xzqsr
CC BY-SA 4.0
2021-08-02T10:13:29.150Z
Thank you for your edit! I followed your instructions and I'm getting an error. I'll try to add it below.
YQ002lc2
CC BY-SA 4.0
2021-08-02T10:16:47.597Z
Traceback (most recent call last):
  File "~/chinese2cangjie-master/c_transform.py", line 134, in <module>
    outfile = c_trans.chinese2cangjie(infile = args.input, outfile = args.output, mapfile = args.map)
  File "~/chinese2cangjie-master/c_transform.py", line 113, in chinese2cangjie
    self.__check_prepare(infile, mode, mapfile)
  File "~/chinese2cangjie-master/c_transform.py", line 33, in __check_prepare
    mapfunction = json.load(open(mapfile), encoding="utf8")
  File "/usr/lib/python3.9/json/__init__.py", line 293, in load
    return loads(fp.read(),
YQ002lc2
CC BY-SA 4.0
2021-08-02T10:16:55.657Z
File "/usr/lib/python3.9/json/__init__.py", line 359, in loads
    return cls(**kw).decode(s)
TypeError: __init__() got an unexpected keyword argument 'encoding'
./Convert.bat: line 2: pause: command not found
YQ002lc2
CC BY-SA 4.0
2021-08-02T10:22:11.880Z
btw, regarding cangjie, xkb is technically more correct. (cangjie codes don't usually include numbers) I just usually type it using kb2. Thanks you for your explanation though! I may edit those at some point.
YQ002lc2
CC BY-SA 4.0
2021-08-02T13:47:23.360Z
I'm afriad I can't figure out how the error occurred according to the Traceback. But mine works fine and you can try it if you don't mind. I put it on my Google Drive and you can [download it here](https://drive.google.com/file/d/1R8sOrpQ8ga2fuw65T4GUkznBpiHDg67v/view). Unzip it, enter the folder and just double click "Convert.bat" to run. And then the result will be in the "output.txt".
xzqsr
CC BY-SA 4.0
2021-08-02T13:49:39.753Z
And thanks for your explanation to xkb and kb2 :)
xzqsr
CC BY-SA 4.0
2021-08-03T07:34:48.460Z
Thank you for your efforts and for clarifying the syntax! 
I'm glad it's working on your end! 
Unfortunately, I'm still getting the same errors on my end.
I'm wondering if it's a bug in python 3.9 or something else. I might report it to github. 
You're welcome about the xkb & kb2 explanation.
YQ002lc2
CC BY-SA 4.0
2021-08-03T09:12:25.987Z
You're welcome! I've just checked the code again and the error seems to occur from c_transform.py at line 33. Could you please give a try to change that line into `mapfunction = json.load(open(mapfile))` ? I'm not very sure for that because I'm not very good at Python.
xzqsr
CC BY-SA 4.0
2021-08-04T12:23:48.120Z
That worked! Thank you!
YQ002lc2
CC BY-SA 4.0
2021-08-04T12:25:13.040Z
For some reason, it displays a bunch of letters with numbers. 
But it works. 
Good job! 

Sample display:
...
tthaf1
ichaf0
kehaf0
dchaf0
ipmt0
ijcc1
sehde0
tmfb0
orrxu0
bbul0
file saved in output.txt
./Convert.bat: line 2: pause: command not found
YQ002lc2
CC BY-SA 4.0
2021-08-04T18:46:07.850Z
Congratulations! I'm glad to hear that it can finally work on your end, although it still looks a little bit strange, especially the "line 2: pause: command not found" in sample display. That bunch of letters also appeared on my screen but I didn't meet "line 2: pause: command not found". I'll try to find how it happened later, if I could.
xzqsr
CC BY-SA 4.0
2021-08-06T22:50:23.000Z
Yes, thank you! Ok, you can tinker if you like. For my part, I'm satisfied that it does what I want and appreciate your help with that! Take care and thanks again!
YQ002lc2
CC BY-SA 4.0
2021-08-01T08:16:19.270Z
2021-08-02T09:46:19.173Z
2021-08-02T09:46:19.173Z
xzqsr
<p>Does anyone know of a Cangjie converter that can convert bulk texts to and from Cangjie codes?</p>
<p>Example conversions:</p>
<p>kb2 oiar grmbc jjomn oh egi --&gt; 冇倉頡輸入法</p>
<p>冇倉頡輸入法  --&gt; kb2 oiar grmbc jjomn oh egi</p>
<p>Thanks.</p>

<resources>
Cangjie converter
# Cangjie converter

(Asked by: username_0 on 2021-07-30)

Does anyone know of a Cangjie converter that can convert bulk texts to and from Cangjie codes?

Example conversions:

kb2 oiar grmbc jjomn oh egi --> 冇倉頡輸入法

冇倉頡輸入法 --> kb2 oiar grmbc jjomn oh egi

Thanks.

**Tags:** resources

---

## 1 answers

### Answer by username_1 on 2021-08-01. Score: 1 | Accepted answer

I found one (may be the only preexisted one throughout the Internet) on Github. Link: https://github.com/Jerryzhao-z/chinese2cangjie

Edit:
I've tried the script by following steps and it worked on Windows 10.

Install Python 3.7 and configure system environment variants.
Download source code ZIP and unzip it. Enter unzipped "chinese2cangjie-master" folder.
Create a new .txt file in that folder and rename it into "Convert.bat" (Note: the extension is changed). Edit this file and input following command lines and save.

python c_transform.py --input input.txt --output output.txt --mode 0
pause


Create a new .txt file in the folder and rename it into "input.txt". Edit this file and input Chinese characters need converting (such as "冇倉頡輸入法") and Save.
Create a new .txt file in the folder and rename it into "output.txt". Leave it empty.
Run "Convert.bat" and wait. After finishing, open "output.txt" and you'll get Cangjie codes (such as "xkb oiar grmbc jjomn oh egi").
If you want to convert Cangjie to character, just input Cangjie codes in the "input.txt" and change the number 0 to 1 in "Convert.bat" and run. You will get characters in "output.txt".

By the way, I actually don't understand Cangjie but I found the sentence "kb2 oiar grmbc jjomn oh egi" you gave will not be converted into "冇倉頡輸入法" but "kb２倉頡輸入法" instead. That means "冇" is represented by "xkb" according to the reversed convertion, but not "kb2". I don't know which is right, however, you can modify the dictionary files ("Cangjie5.txt" and/or "char2cangjie.json") to avoid this if needed, I guess.

> **Comments:**
> **username_0**: Thank you! Looking at the code, it seems it should be able to do what I want it to. But I'm encountering all sorts of errors and I'm not sure how to fix them. I know I can report issues on github, but have you gotten this working yourself? If so, could you give me some sample inputs to see if I'm just typing something wrong? Thanks!  
> **username_1**: Sorry, I haven't tested the code yet. I will try it later this afternoon and reply to you then.  
> **username_1**: Hi, I just edited my answer! @YQ002lc2  
> **username_0**: Thank you for your edit! I followed your instructions and I'm getting an error. I'll try to add it below.  
> **username_0**: Traceback (most recent call last):   File "~/chinese2cangjie-master/c_transform.py", line 134, in <module>     outfile = c_trans.chinese2cangjie(infile = args.input, outfile = args.output, mapfile = args.map)   File "~/chinese2cangjie-master/c_transform.py", line 113, in chinese2cangjie     self.__check_prepare(infile, mode, mapfile)   File "~/chinese2cangjie-master/c_transform.py", line 33, in __check_prepare     mapfunction = json.load(open(mapfile), encoding="utf8")   File "/usr/lib/python3.9/json/__init__.py", line 293, in load     return loads(fp.read(),  
> **username_0**: File "/usr/lib/python3.9/json/__init__.py", line 359, in loads     return cls(**kw).decode(s) TypeError: __init__() got an unexpected keyword argument 'encoding' ./Convert.bat: line 2: pause: command not found  
> **username_0**: btw, regarding cangjie, xkb is technically more correct. (cangjie codes don't usually include numbers) I just usually type it using kb2. Thanks you for your explanation though! I may edit those at some point.  
> **username_1**: I'm afriad I can't figure out how the error occurred according to the Traceback. But mine works fine and you can try it if you don't mind. I put it on my Google Drive and you can [download it here](https://drive.google.com/file/d/1R8sOrpQ8ga2fuw65T4GUkznBpiHDg67v/view). Unzip it, enter the folder and just double click "Convert.bat" to run. And then the result will be in the "output.txt".  
> **username_1**: And thanks for your explanation to xkb and kb2 :)  
> **username_0**: Thank you for your efforts and for clarifying the syntax!  I'm glad it's working on your end!  Unfortunately, I'm still getting the same errors on my end. I'm wondering if it's a bug in python 3.9 or something else. I might report it to github.  You're welcome about the xkb & kb2 explanation.  
> **username_1**: You're welcome! I've just checked the code again and the error seems to occur from c_transform.py at line 33. Could you please give a try to change that line into `mapfunction = json.load(open(mapfile))` ? I'm not very sure for that because I'm not very good at Python.  
> **username_0**: That worked! Thank you!  
> **username_0**: For some reason, it displays a bunch of letters with numbers.  But it works.  Good job!   Sample display: ... tthaf1 ichaf0 kehaf0 dchaf0 ipmt0 ijcc1 sehde0 tmfb0 orrxu0 bbul0 file saved in output.txt ./Convert.bat: line 2: pause: command not found  
> **username_1**: Congratulations! I'm glad to hear that it can finally work on your end, although it still looks a little bit strange, especially the "line 2: pause: command not found" in sample display. That bunch of letters also appeared on my screen but I didn't meet "line 2: pause: command not found". I'll try to find how it happened later, if I could.  
> **username_0**: Yes, thank you! Ok, you can tinker if you like. For my part, I'm satisfied that it does what I want and appreciate your help with that! Take care and thanks again!  

---

