@@ -4,10 +4,10 @@ Pure JavaScript implementation of OpenCC
44
55## Import
66
7- In HTML file :
7+ In HTML:
88
99``` html
10- <script src =" https://cdn.jsdelivr.net/npm/opencc-js@0.3.6 " ></script >
10+ <script src =" https://cdn.jsdelivr.net/npm/opencc-js@0.3.7 " ></script >
1111```
1212
1313Or in Node.js:
@@ -19,7 +19,6 @@ const OpenCC = require('opencc-js');
1919## Usage
2020
2121``` javascript
22-
2322OpenCC .Converter (' hk' , ' cn' ) // Traditional Chinese (Hong Kong) to Simplified Chinese
2423.then (convert => console .log (convert (' 漢字,簡體字' ))); // output: 汉字,简体字
2524```
@@ -33,25 +32,31 @@ The first argument is the source type, the second argument is the destination ty
3332- Simplified Chinese (Mainland China):` cn `
3433- Japanese _ Shinjitai_ :` jp `
3534
36- Trad (Hong Kong, with Hong Kong phrases) is currently not supported.
35+ Traditional Chinese (Hong Kong, with Hong Kong phrases) is currently not supported.
3736
3837## Custom Converter
3938
4039``` javascript
41- const convert = OpenCC .CustomConverter ({ ' 香蕉' : ' 🍌️' , ' 蘋果' : ' 🍎️' , ' 梨' : ' 🍐️' });
42- console .log (convert (' 香蕉蘋果梨' )); // output: 🍌️🍎️🍐️
40+ const dict = {
41+ ' 香蕉' : ' banana' ,
42+ ' 蘋果' : ' apple' ,
43+ ' 梨' : ' pear' ,
44+ };
45+ const convert = OpenCC .CustomConverter (dict);
46+ console .log (convert (' 香蕉 蘋果 梨' ));
47+ // outputs: banana apple pear
4348```
4449
4550## DOM operation
4651
4752``` javascript
48- (async () => {
49- const convert = await OpenCC .Converter (' hk' , ' cn' );
50- const startNode = document .documentElement ; // Convert the whole page
51- const HTMLConvertHandler = OpenCC .HTMLConverter (convert, startNode, ' zh-HK' , ' zh-CN' ); // Convert all zh-HK to zh-CN
52- HTMLConvertHandler .convert (); // Start conversion
53- HTMLConvertHandler .restore (); // Restore
54- })()
53+ (( async () => {
54+ const convert = await OpenCC .Converter (' hk' , ' cn' );
55+ const startNode = document .documentElement ; // Convert the whole page
56+ const HTMLConvertHandler = OpenCC .HTMLConverter (convert, startNode, ' zh-HK' , ' zh-CN' ); // Convert all zh-HK to zh-CN
57+ HTMLConvertHandler .convert (); // Start conversion
58+ HTMLConvertHandler .restore (); // Restore
59+ })());
5560```
5661
5762The conversion is skipped if the class list of a node contains ` ignore-opencc ` . All child nodes of the node will not be converted.
0 commit comments