Skip to content

Commit a3901a8

Browse files
authored
init an API. Test with English README.md
1 parent e94ebcf commit a3901a8

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

README.md

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ The JavaScript version of Open Chinese Convert (OpenCC)
66

77
## Import
88

9-
**Import opencc-js in HTML**
9+
**Import opencc-js in HTML page**
1010

11-
Load the following four `script` in sequence:
11+
Import in HTML pages:
1212

1313
```html
1414
<script src="https://cdn.jsdelivr.net/npm/opencc-js@1.0.1/data.min.js"></script> <!-- Required -->
@@ -17,7 +17,7 @@ Load the following four `script` in sequence:
1717
<script src="https://cdn.jsdelivr.net/npm/opencc-js@1.0.1/bundle-browser.min.js"></script><!-- Required -->
1818
```
1919

20-
**Import opencc-js in Node.js**
20+
**Import opencc-js in Node.js script**
2121

2222
```sh
2323
npm install opencc-js
@@ -37,13 +37,6 @@ const converter = OpenCC.Converter({ from: 'hk', to: 'cn' });
3737
console.log(converter('漢語')); // output: 汉语
3838
```
3939

40-
- `cn`: Simplified Chinese (Mainland China)
41-
- `tw`: Traditional Chinese (Taiwan)
42-
- `twp`: with phrase conversion (ex: 自行車 -> 腳踏車)
43-
- `hk`: Traditional Chinese (Hong Kong)
44-
- `jp`: Japanese Shinjitai
45-
- `t`: Traditional Chinese (OpenCC standard. Do not use unless you know what you are doing)
46-
4740
**Custom Converter**
4841

4942
```javascript
@@ -74,4 +67,21 @@ HTMLConvertHandler.convert(); // Convert -> 汉语
7467
HTMLConvertHandler.restore(); // Restore -> 漢語
7568
```
7669

77-
All the tags which contains `ignore-opencc` in the class list will not be converted (including all sub-nodes of the tags).
70+
## API
71+
* `.Converter({})`: declare the converter's direction via locals.
72+
* default: `{ from: 'tw', to: 'cn' }`
73+
* syntax : `{ from: local1, to: local2 }`
74+
* locals: letter codes defining a writing local tradition, occasionally its idiomatic habits.
75+
* `cn`: Simplified Chinese (Mainland China)
76+
* `tw`: Traditional Chinese (Taiwan)
77+
* `twp`: with phrase conversion (ex: 自行車 -> 腳踏車)
78+
* `hk`: Traditional Chinese (Hong Kong)
79+
* `jp`: Japanese Shinjitai
80+
* `t`: Traditional Chinese (OpenCC standard. Do not use unless you know what you are doing)
81+
* `.CustomConverter([])` : defines custom dictionary.
82+
* default: `[]`
83+
* syntax : `[ ['item1','replacement1'], ['item2','replacement2'], … ]`
84+
* `.HTMLConverter(converter, rootNode, langAttrInitial, langAttrNew )` : uses previously defined converter() to converts all HTML elements text content from a starting root node and down, into the target local. Also converts all attributes `lang` from existing `langAttrInitial` to `langAttrNew` values.
85+
* `lang` attributes : html attribute defines the languages of the text content to the browser, at start (`langAttrInitial`) and after conversion (`langAttrNew`).
86+
* syntax convention: [IETF languages codes](https://www.w3.org/International/articles/bcp47/#macro), mainly `zh-TW`, `zh-HK`, `zh-CN`, `zh-SG`,…
87+
* `ignore-opencc` : html class signaling an element and its sub-nodes will not be converted.

0 commit comments

Comments
 (0)