@kensio/pinyinjs 1.7.8 → 1.7.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -2
- package/data/core.entries +2259 -2259
- package/data/core.freq +0 -0
- package/data/full.counts +0 -0
- package/data/full.entries +2289 -2289
- package/data/full.freq +0 -0
- package/data/manifest.json +8 -8
- package/data/standard.entries +2257 -2257
- package/data/standard.freq +0 -0
- package/dist/cli/flag-lists.d.ts +2 -1
- package/dist/cli/flag-lists.d.ts.map +1 -1
- package/dist/cli/flag-lists.js.map +1 -1
- package/dist/cli/format-options.d.ts +5 -1
- package/dist/cli/format-options.d.ts.map +1 -1
- package/dist/cli/format-options.js +9 -2
- package/dist/cli/format-options.js.map +1 -1
- package/dist/cli/html-commands.d.ts.map +1 -1
- package/dist/cli/html-commands.js +15 -3
- package/dist/cli/html-commands.js.map +1 -1
- package/dist/cli/systems.d.ts +15 -43
- package/dist/cli/systems.d.ts.map +1 -1
- package/dist/cli/systems.js +9 -12
- package/dist/cli/systems.js.map +1 -1
- package/dist/decode/guo-rule.d.ts +64 -0
- package/dist/decode/guo-rule.d.ts.map +1 -0
- package/dist/decode/guo-rule.js +138 -0
- package/dist/decode/guo-rule.js.map +1 -0
- package/dist/decode/reading-rules.d.ts +1 -0
- package/dist/decode/reading-rules.d.ts.map +1 -1
- package/dist/decode/reading-rules.js +3 -0
- package/dist/decode/reading-rules.js.map +1 -1
- package/dist/dictionary/frequency-table.d.ts +46 -0
- package/dist/dictionary/frequency-table.d.ts.map +1 -1
- package/dist/dictionary/frequency-table.js +37 -8
- package/dist/dictionary/frequency-table.js.map +1 -1
- package/dist/dictionary/merge-types.d.ts +12 -0
- package/dist/dictionary/merge-types.d.ts.map +1 -1
- package/dist/dictionary/merge-types.js.map +1 -1
- package/dist/dictionary/merge-word.d.ts.map +1 -1
- package/dist/dictionary/merge-word.js +2 -2
- package/dist/dictionary/merge-word.js.map +1 -1
- package/dist/dictionary/merge.d.ts.map +1 -1
- package/dist/dictionary/merge.js +11 -1
- package/dist/dictionary/merge.js.map +1 -1
- package/dist/dictionary/name-mass.d.ts +42 -0
- package/dist/dictionary/name-mass.d.ts.map +1 -0
- package/dist/dictionary/name-mass.js +66 -0
- package/dist/dictionary/name-mass.js.map +1 -0
- package/dist/dictionary/proper-noun.d.ts +8 -1
- package/dist/dictionary/proper-noun.d.ts.map +1 -1
- package/dist/dictionary/proper-noun.js +13 -3
- package/dist/dictionary/proper-noun.js.map +1 -1
- package/dist/dictionary/script-pairings.d.ts +12 -0
- package/dist/dictionary/script-pairings.d.ts.map +1 -1
- package/dist/dictionary/script-pairings.js +20 -0
- package/dist/dictionary/script-pairings.js.map +1 -1
- package/dist/dictionary/traditional-carry.d.ts +23 -0
- package/dist/dictionary/traditional-carry.d.ts.map +1 -0
- package/dist/dictionary/traditional-carry.js +201 -0
- package/dist/dictionary/traditional-carry.js.map +1 -0
- package/dist/format/annotate.d.ts.map +1 -1
- package/dist/format/annotate.js +3 -3
- package/dist/format/annotate.js.map +1 -1
- package/dist/format/html.d.ts +41 -6
- package/dist/format/html.d.ts.map +1 -1
- package/dist/format/html.js +34 -83
- package/dist/format/html.js.map +1 -1
- package/dist/format/language-tag.d.ts +57 -0
- package/dist/format/language-tag.d.ts.map +1 -0
- package/dist/format/language-tag.js +76 -0
- package/dist/format/language-tag.js.map +1 -0
- package/dist/format/syllable-span.d.ts +10 -0
- package/dist/format/syllable-span.d.ts.map +1 -0
- package/dist/format/syllable-span.js +87 -0
- package/dist/format/syllable-span.js.map +1 -0
- package/dist/format/transcribed.d.ts +36 -0
- package/dist/format/transcribed.d.ts.map +1 -0
- package/dist/format/transcribed.js +38 -0
- package/dist/format/transcribed.js.map +1 -0
- package/dist/format/transcription.d.ts.map +1 -1
- package/dist/format/transcription.js +7 -19
- package/dist/format/transcription.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/transcription/systems.d.ts +82 -0
- package/dist/transcription/systems.d.ts.map +1 -0
- package/dist/transcription/systems.js +64 -0
- package/dist/transcription/systems.js.map +1 -0
- package/package.json +1 -1
- package/dist/cli/system-table.d.ts +0 -12
- package/dist/cli/system-table.d.ts.map +0 -1
- package/dist/cli/system-table.js +0 -48
- package/dist/cli/system-table.js.map +0 -1
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a 繁體 spelling takes from the 简体 word it pairs with.
|
|
3
|
+
*
|
|
4
|
+
* jieba's dictionary was counted over a 简体 corpus, and all three of the fields
|
|
5
|
+
* it settles arrive on one script and not the other. 听 is tagged `v` and
|
|
6
|
+
* counted 20,435 times. 聽 is tagged nothing, counted nowhere, and 麥 is not a
|
|
7
|
+
* name where 麦 is one. Every rule that asks what the word beside it is decides
|
|
8
|
+
* on the tag, every path the decoder weighs is priced on the count, and the
|
|
9
|
+
* capital comes straight off the proper-noun bit, so 繁體 text was read by
|
|
10
|
+
* rules that could not see it, priced by a model that had never met it and
|
|
11
|
+
* capitalised by a different answer from the one 简体 got.
|
|
12
|
+
*
|
|
13
|
+
* All three travel over the pairing the entries already hold. An entry names
|
|
14
|
+
* the 繁體 spelling of its own word. The entry keyed on that spelling is
|
|
15
|
+
* therefore the same word written the other way, and how a word is classed, how
|
|
16
|
+
* often it is met and whether it is a name are facts about the word rather than
|
|
17
|
+
* about the spelling. `corpus-mass.ts` makes the same move for the polyphone
|
|
18
|
+
* priors, where a vote cast for a 简体 word is cast again for whichever 繁體
|
|
19
|
+
* form the reading picks.
|
|
20
|
+
*
|
|
21
|
+
* A 繁體 spelling that is not a headword of its own needs none of this, because
|
|
22
|
+
* `artifact-claims.ts` lets its 简体 entry claim the key outright and the key
|
|
23
|
+
* carries that entry's fields. 銀行 is claimed by 银行 and always priced as it.
|
|
24
|
+
* What is left is the characters Unihan gives an entry to, which is why only
|
|
25
|
+
* single characters are paired here.
|
|
26
|
+
*/
|
|
27
|
+
import { convertCharacter } from "../script/conversion.js";
|
|
28
|
+
import { isSingleCharacter } from "../script/characters.js";
|
|
29
|
+
import { traditionalCharacterTable } from "./script-pairings.js";
|
|
30
|
+
/**
|
|
31
|
+
* jieba's tag for a character it has counted and not classified.
|
|
32
|
+
*
|
|
33
|
+
* Written on 5,666 entries and on nothing longer than one character, 简体 and
|
|
34
|
+
* 繁體 alike: 且, 丢, 乎, 井, 今 and 仍 carry it next to 來, 個 and 這. It says
|
|
35
|
+
* that the character was seen rather than what it is. Read here as no tag at
|
|
36
|
+
* all, and left in the artifact, because whether jieba wrote `zg` or wrote
|
|
37
|
+
* nothing is a fact about the source and only this decides what to make of it.
|
|
38
|
+
*
|
|
39
|
+
* Nothing longer than one character carries it. That leaves the rules forbidding
|
|
40
|
+
* an **untagged key** alone, since each of those asks about a word of two
|
|
41
|
+
* characters or more and no such key is tagged `zg`.
|
|
42
|
+
*/
|
|
43
|
+
const UNCATEGORISED = "zg";
|
|
44
|
+
/**
|
|
45
|
+
* Whether a tag says anything about the word.
|
|
46
|
+
*/
|
|
47
|
+
export function isTagged(partOfSpeech) {
|
|
48
|
+
return partOfSpeech !== "" && partOfSpeech !== UNCATEGORISED;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* The 繁體 character a 简体 one is written as, or undefined where it is neither.
|
|
52
|
+
*
|
|
53
|
+
* Read off the aggregate table rather than off {@link DictionaryEntry.hant},
|
|
54
|
+
* and that is the whole of what keeps this honest. An entry's own 繁體 form is
|
|
55
|
+
* whichever CC-CEDICT sense matched its reading, and for a single character
|
|
56
|
+
* that can be an oddity: CC-CEDICT holds `旹 时` as an old variant of 時, so
|
|
57
|
+
* 时's entry can name 旹 while every word 时 appears in says 時. Lending 时's
|
|
58
|
+
* 103,735 occurrences to 旹 made a character nobody writes the third commonest
|
|
59
|
+
* way to write `shí`. The table counts words, so 時 wins it thousands to one.
|
|
60
|
+
*/
|
|
61
|
+
function traditionalOf(table, entry) {
|
|
62
|
+
if (!isSingleCharacter(entry.hans)) {
|
|
63
|
+
return undefined;
|
|
64
|
+
}
|
|
65
|
+
const written = convertCharacter(table, entry.hans, entry.readings.cn[0]);
|
|
66
|
+
return written === entry.hans ? undefined : written;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* The 简体 entry each 繁體 character should take a field from.
|
|
70
|
+
*
|
|
71
|
+
* Where two 简体 characters are written the same way in 繁體 the commoner of
|
|
72
|
+
* them lends. Both fields are being used to guess at what a reader meant, and
|
|
73
|
+
* the commoner character is the likelier thing to have been meant. `hasField`
|
|
74
|
+
* is asked first, so that a commoner character with nothing to lend does not
|
|
75
|
+
* shut out a rarer one that has something.
|
|
76
|
+
*/
|
|
77
|
+
function lendersByTraditional(entries, table, hasField) {
|
|
78
|
+
const lenders = new Map();
|
|
79
|
+
for (const entry of entries) {
|
|
80
|
+
const written = hasField(entry) ? traditionalOf(table, entry) : undefined;
|
|
81
|
+
if (written === undefined) {
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
const held = lenders.get(written);
|
|
85
|
+
if (held === undefined || held.frequency < entry.frequency) {
|
|
86
|
+
lenders.set(written, entry);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return lenders;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Whether an entry has a tag worth lending.
|
|
93
|
+
*/
|
|
94
|
+
function canLendTag(entry) {
|
|
95
|
+
return isTagged(entry.partOfSpeech);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* The tag a spelling ends up with, and whether it took one.
|
|
99
|
+
*
|
|
100
|
+
* `nr`, `ns`, `nt` and `nz` are lent along with the rest now that
|
|
101
|
+
* {@link properFor} carries the bit they go with. Lending the tag without it
|
|
102
|
+
* would have left a spelling claiming a place name the same entry denies is a
|
|
103
|
+
* proper noun, which is why they were held back until the bit travelled.
|
|
104
|
+
*/
|
|
105
|
+
function tagFor(entry, lender) {
|
|
106
|
+
if (isTagged(entry.partOfSpeech) || lender === undefined) {
|
|
107
|
+
return undefined;
|
|
108
|
+
}
|
|
109
|
+
return lender.partOfSpeech;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* The count a spelling ends up with, and whether it took one.
|
|
113
|
+
*
|
|
114
|
+
* The larger of the two, rather than the lender's outright. A 繁體 spelling
|
|
115
|
+
* that jieba counted at all was counted incidentally in a corpus written the
|
|
116
|
+
* other way, and the word occurs at least as often as the commoner spelling of
|
|
117
|
+
* it was seen. Taking the smaller would price 過 by the handful of 繁體 lines
|
|
118
|
+
* jieba's corpus happens to contain.
|
|
119
|
+
*
|
|
120
|
+
* Only the form the reading picks takes it. 发 read `fā` is written 發, so 發
|
|
121
|
+
* takes 发's count and 髮 does not, which is the same line the conversion draws
|
|
122
|
+
* when it writes 出发 as 出發 and 头发 as 頭髮.
|
|
123
|
+
*
|
|
124
|
+
* **The count is carried whole and not shared out.** A share would say that
|
|
125
|
+
* 繁體 text is some fraction as common as 简体 text, and nothing measured here
|
|
126
|
+
* says what that fraction is. It would also be invisible: the buckets the
|
|
127
|
+
* decoder compares are log-spaced, one of them is a factor of 2.49, so halving
|
|
128
|
+
* a count moves it 0.76 of a bucket and a tenth of it moves it 2.5. Only a
|
|
129
|
+
* share of an order of magnitude would change a decode, and inventing one that
|
|
130
|
+
* large to fix a decode that is currently wrong would be trading one guess for
|
|
131
|
+
* another.
|
|
132
|
+
*/
|
|
133
|
+
function countFor(entry, lender) {
|
|
134
|
+
if (lender === undefined || lender.frequency <= entry.frequency) {
|
|
135
|
+
return undefined;
|
|
136
|
+
}
|
|
137
|
+
return lender.frequency;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Whether a spelling is a name, and whether that is a change.
|
|
141
|
+
*
|
|
142
|
+
* The bit is what survived `properNounOf`, so it is the answer both sources
|
|
143
|
+
* reached together rather than jieba's proposal, and it is taken whichever way
|
|
144
|
+
* it points. Demoting matters as much as promoting. 后 is a locative and 後
|
|
145
|
+
* arrived tagged `nr` with nothing under its own spelling to challenge it, so
|
|
146
|
+
* 退休後 came out `tuìxiū Hòu` where 退休后 came out `tuìxiū hòu`.
|
|
147
|
+
*
|
|
148
|
+
* This carries the 简体 answer whether or not that answer is right. jieba calls
|
|
149
|
+
* 连 a surname and 連 now agrees, where before the two differed and one of them
|
|
150
|
+
* happened to be correct. The two scripts saying one thing is what this is for.
|
|
151
|
+
* How good that one thing is for a bare character is #159.
|
|
152
|
+
*/
|
|
153
|
+
function properFor(entry, lender) {
|
|
154
|
+
if (lender === undefined || lender.isProperNoun === entry.isProperNoun) {
|
|
155
|
+
return undefined;
|
|
156
|
+
}
|
|
157
|
+
return lender.isProperNoun;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Give every 繁體 headword the tag and the count its 简体 word carries.
|
|
161
|
+
*
|
|
162
|
+
* Neither overwrites something the source stated. A spelling jieba classified
|
|
163
|
+
* keeps its own tag, and a spelling jieba counted more often than its 简体 word
|
|
164
|
+
* keeps its own count.
|
|
165
|
+
*/
|
|
166
|
+
export function carryToTraditional(entries) {
|
|
167
|
+
const table = traditionalCharacterTable(entries);
|
|
168
|
+
const tagLenders = lendersByTraditional(entries, table, canLendTag);
|
|
169
|
+
const countLenders = lendersByTraditional(entries, table, (entry) => entry.frequency > 0);
|
|
170
|
+
let carriedTags = 0;
|
|
171
|
+
let carriedCounts = 0;
|
|
172
|
+
let carriedCapitals = 0;
|
|
173
|
+
const carried = entries.map((entry) => {
|
|
174
|
+
const tagLender = tagLenders.get(entry.hans);
|
|
175
|
+
const partOfSpeech = tagFor(entry, tagLender);
|
|
176
|
+
const frequency = countFor(entry, countLenders.get(entry.hans));
|
|
177
|
+
const isProperNoun = properFor(entry, tagLender);
|
|
178
|
+
if (partOfSpeech === undefined &&
|
|
179
|
+
frequency === undefined &&
|
|
180
|
+
isProperNoun === undefined) {
|
|
181
|
+
return entry;
|
|
182
|
+
}
|
|
183
|
+
if (partOfSpeech !== undefined) {
|
|
184
|
+
carriedTags += 1;
|
|
185
|
+
}
|
|
186
|
+
if (frequency !== undefined) {
|
|
187
|
+
carriedCounts += 1;
|
|
188
|
+
}
|
|
189
|
+
if (isProperNoun !== undefined) {
|
|
190
|
+
carriedCapitals += 1;
|
|
191
|
+
}
|
|
192
|
+
return {
|
|
193
|
+
...entry,
|
|
194
|
+
...(partOfSpeech !== undefined && { partOfSpeech }),
|
|
195
|
+
...(frequency !== undefined && { frequency }),
|
|
196
|
+
...(isProperNoun !== undefined && { isProperNoun }),
|
|
197
|
+
};
|
|
198
|
+
});
|
|
199
|
+
return { entries: carried, carriedTags, carriedCounts, carriedCapitals };
|
|
200
|
+
}
|
|
201
|
+
//# sourceMappingURL=traditional-carry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"traditional-carry.js","sourceRoot":"","sources":["../../src/dictionary/traditional-carry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAE3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAE5D,OAAO,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAC;AAEjE;;;;;;;;;;;;GAYG;AACH,MAAM,aAAa,GAAG,IAAI,CAAC;AAE3B;;GAEG;AACH,MAAM,UAAU,QAAQ,CAAC,YAAoB;IAC3C,OAAO,YAAY,KAAK,EAAE,IAAI,YAAY,KAAK,aAAa,CAAC;AAC/D,CAAC;AAYD;;;;;;;;;;GAUG;AACH,SAAS,aAAa,CACpB,KAA+C,EAC/C,KAAsB;IAEtB,IAAI,CAAC,iBAAiB,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;QACnC,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,MAAM,OAAO,GAAG,gBAAgB,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,QAAQ,CAAC,EAAE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C;QACjD,IACE,YAAY,KAAK,SAAS;YAC1B,SAAS,KAAK,SAAS;YACvB,YAAY,KAAK,SAAS,EAC1B,CAAC;YACD,OAAO,KAAK,CAAC;QACf,CAAC;QACD,IAAI,YAAY,KAAK,SAAS,EAAE,CAAC;YAC/B,WAAW,IAAI,CAAC,CAAC;QACnB,CAAC;QACD,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;YAC5B,aAAa,IAAI,CAAC,CAAC;QACrB,CAAC;QACD,IAAI,YAAY,KAAK,SAAS,EAAE,CAAC;YAC/B,eAAe,IAAI,CAAC,CAAC;QACvB,CAAC;QACD,OAAO;YACL,GAAG,KAAK;YACR,GAAG,CAAC,YAAY,KAAK,SAAS,IAAI,EAAE,YAAY,EAAE,CAAC;YACnD,GAAG,CAAC,SAAS,KAAK,SAAS,IAAI,EAAE,SAAS,EAAE,CAAC;YAC7C,GAAG,CAAC,YAAY,KAAK,SAAS,IAAI,EAAE,YAAY,EAAE,CAAC;SACpD,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,eAAe,EAAE,CAAC;AAC3E,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"annotate.d.ts","sourceRoot":"","sources":["../../src/format/annotate.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAU,KAAK,WAAW,
|
|
1
|
+
{"version":3,"file":"annotate.d.ts","sourceRoot":"","sources":["../../src/format/annotate.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAU,KAAK,WAAW,EAAuB,MAAM,WAAW,CAAC;AAC1E,OAAO,EAAE,KAAK,cAAc,EAAiB,MAAM,sBAAsB,CAAC;AAC1E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAE9D;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,QAAQ,OAAO,CAAC;AAE7B;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,mEAAmE;IACnE,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IACpC,QAAQ,CAAC,MAAM,EAAE,SAAS,cAAc,EAAE,CAAC;CAC5C;AAED;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,SAAS,cAAc,EAAE,GAAG,UAAU,EAAE,CAc7E;AA2ED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE,SAAS,cAAc,EAAE,EACjC,OAAO,GAAE,WAAgB,GACxB,MAAM,CAIR;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACpC,UAAU,EAAE,UAAU,EACtB,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,WAAgB,GACxB,MAAM,CAER;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,aAAa,CAC3B,UAAU,EAAE,UAAU,EACtB,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,WAAgB,GACxB,MAAM,CAER"}
|
package/dist/format/annotate.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* The pinyin sits above the characters rather than beside them, so the pieces
|
|
5
5
|
* are regrouped against the text they annotate.
|
|
6
6
|
*/
|
|
7
|
-
import { escape, toHtml,
|
|
7
|
+
import { escape, toHtml, writePieces } from "./html.js";
|
|
8
8
|
import { convertPieces } from "../decode/convert.js";
|
|
9
9
|
/**
|
|
10
10
|
* What the characters being annotated declare themselves to be.
|
|
@@ -101,9 +101,9 @@ function writeAnnotation(annotation, options) {
|
|
|
101
101
|
// characters — but {@link toAnnotatedHtml} takes pieces from the caller,
|
|
102
102
|
// and there is no base to hang an annotation on, so it is written as the
|
|
103
103
|
// plain markup it would have got from {@link toHtml}.
|
|
104
|
-
return pieces
|
|
104
|
+
return writePieces(pieces, options);
|
|
105
105
|
}
|
|
106
|
-
const reading = pieces
|
|
106
|
+
const reading = writePieces(pieces, options);
|
|
107
107
|
// The tag goes on the <ruby> rather than around the base, and the syllables
|
|
108
108
|
// inside the <rt> override it with their own. `<rb>` would be the obvious
|
|
109
109
|
// place for it and is not an element any more: the WHATWG parser drops it,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"annotate.js","sourceRoot":"","sources":["../../src/format/annotate.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,MAAM,EAAoB,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"annotate.js","sourceRoot":"","sources":["../../src/format/annotate.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,MAAM,EAAoB,MAAM,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAC1E,OAAO,EAAuB,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAG1E;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,IAAI,CAAC;AAW7B;;;;;;;;GAQG;AACH,MAAM,UAAU,aAAa,CAAC,MAAiC;IAC7D,MAAM,MAAM,GAAiB,EAAE,CAAC;IAChC,KAAK,MAAM,CAAC,EAAE,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,EAAE,EAAE,CAAC;QAC3C,MAAM,IAAI,GAAG,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;QAC3B,IAAI,IAAI,EAAE,MAAM,KAAK,SAAS,IAAI,SAAS,CAAC,KAAK,EAAE,MAAM,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;YACnE,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG;gBAC1B,MAAM,EAAE,IAAI,CAAC,MAAM;gBACnB,MAAM,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC;aAChC,CAAC;YACF,SAAS;QACX,CAAC;QACD,MAAM,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,KAAK,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C;IAED,MAAM,OAAO,GAAG,WAAW,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC7C,4EAA4E;IAC5E,0EAA0E;IAC1E,2EAA2E;IAC3E,2EAA2E;IAC3E,yBAAyB;IACzB,MAAM,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC,eAAe,QAAQ,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC;IAC9D,OAAO,GAAG,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,iBAAiB,OAAO,wBAAwB,CAAC;AACrF,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,UAAU,eAAe,CAC7B,MAAiC,EACjC,OAAO,GAAgB,EAAE;IAEzB,OAAO,aAAa,CAAC,MAAM,CAAC;SACzB,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,eAAe,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;SACzD,IAAI,CAAC,EAAE,CAAC,CAAC;AACd,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,sBAAsB,CACpC,UAAsB,EACtB,IAAY,EACZ,OAAO,GAAgB,EAAE;IAEzB,OAAO,eAAe,CAAC,aAAa,CAAC,UAAU,EAAE,IAAI,EAAE,OAAO,CAAC,EAAE,OAAO,CAAC,CAAC;AAC5E,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,aAAa,CAC3B,UAAsB,EACtB,IAAY,EACZ,OAAO,GAAgB,EAAE;IAEzB,OAAO,MAAM,CAAC,aAAa,CAAC,UAAU,EAAE,IAAI,EAAE,OAAO,CAAC,EAAE,OAAO,CAAC,CAAC;AACnE,CAAC"}
|
package/dist/format/html.d.ts
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A conversion as markup, and the options that decide what the markup carries.
|
|
3
|
+
*
|
|
4
|
+
* One element per syllable, which is what lets a page colour a tone or mark a
|
|
5
|
+
* guess. What goes inside one of those elements is `syllable-span.ts` and the
|
|
6
|
+
* ruby that puts the reading over the hanzi is `annotate.ts`.
|
|
7
|
+
*/
|
|
1
8
|
export { convertToAnnotatedHtml, convertToHtml, toAnnotatedHtml, } from "./annotate.js";
|
|
2
9
|
import type { ConvertedPiece, ConvertOptions } from "../decode/convert.js";
|
|
10
|
+
import type { TranscriptionSystem } from "../transcription/systems.js";
|
|
11
|
+
export { writePiece } from "./syllable-span.js";
|
|
3
12
|
/**
|
|
4
13
|
* How a conversion is marked up.
|
|
5
14
|
*/
|
|
@@ -15,18 +24,32 @@ export interface HtmlOptions extends ConvertOptions {
|
|
|
15
24
|
* Whether readings the decode was guessing at are marked. Defaults to true.
|
|
16
25
|
*
|
|
17
26
|
* `py-uncertain`, plus a `data-alternatives` attribute listing what was
|
|
18
|
-
* rejected. See
|
|
19
|
-
* wrong.
|
|
27
|
+
* rejected. See `isUncertain` for what qualifies and how often it is wrong.
|
|
20
28
|
*/
|
|
21
29
|
readonly markUncertain?: boolean;
|
|
22
30
|
/**
|
|
23
31
|
* Whether each syllable declares what language it is in. Defaults to true.
|
|
24
32
|
*
|
|
25
33
|
* `lang="zh-Latn-CN-pinyin"`, or `zh-Latn-TW-pinyin` where the conversion
|
|
26
|
-
* reads `zh-TW`. See
|
|
27
|
-
*
|
|
34
|
+
* reads `zh-TW`. See `languageTag` for why that matters, and what to do
|
|
35
|
+
* instead of turning it off.
|
|
28
36
|
*/
|
|
29
37
|
readonly lang?: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* A system to write the reading in instead of pinyin.
|
|
40
|
+
*
|
|
41
|
+
* `BOPOMOFO`, `WADE_GILES`, `YALE`, `GWOYEU` or `IPA`, or a
|
|
42
|
+
* {@link TranscriptionSystem} of the caller's own. Left out, the reading is
|
|
43
|
+
* the pinyin the conversion wrote.
|
|
44
|
+
*
|
|
45
|
+
* The word segmentation is the conversion's either way and only the join
|
|
46
|
+
* changes, which is the division `toTranscription` makes and for the same
|
|
47
|
+
* reason. What a word is belongs to the language, and how its syllables are
|
|
48
|
+
* run together belongs to the system. Everything else a syllable carries is
|
|
49
|
+
* untouched, so tone classes, `py-uncertain` and `data-alternatives` mean
|
|
50
|
+
* what they always did.
|
|
51
|
+
*/
|
|
52
|
+
readonly transcription?: TranscriptionSystem;
|
|
30
53
|
}
|
|
31
54
|
/**
|
|
32
55
|
* Escape text for markup.
|
|
@@ -39,9 +62,21 @@ export interface HtmlOptions extends ConvertOptions {
|
|
|
39
62
|
*/
|
|
40
63
|
export declare function escape(text: string): string;
|
|
41
64
|
/**
|
|
42
|
-
* Mark up
|
|
65
|
+
* Mark up a run of pieces, with the system's join between two syllables.
|
|
66
|
+
*
|
|
67
|
+
* Pinyin needs none. Its syllables are run together and the marks that divide
|
|
68
|
+
* them are pieces of their own. Every other system decides the join for itself,
|
|
69
|
+
* and the join is what separates the five at this level, so it is written
|
|
70
|
+
* between the spans rather than inside one. `<span>Pei³</span>-<span>ching¹
|
|
71
|
+
* </span>` is one word in Wade-Giles and leaves each syllable its own element
|
|
72
|
+
* to carry a tone class on.
|
|
73
|
+
*
|
|
74
|
+
* A piece that wrote nothing does not break the run, which is what carries the
|
|
75
|
+
* join over pinyin's own hyphen: 干干净净 is four syllables of one word, and
|
|
76
|
+
* the mark between the second and the third is dropped rather than counted as a
|
|
77
|
+
* gap.
|
|
43
78
|
*/
|
|
44
|
-
export declare function
|
|
79
|
+
export declare function writePieces(pieces: readonly ConvertedPiece[], options: HtmlOptions): string;
|
|
45
80
|
/**
|
|
46
81
|
* Mark up a converted text, one element per syllable.
|
|
47
82
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"html.d.ts","sourceRoot":"","sources":["../../src/format/html.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"html.d.ts","sourceRoot":"","sources":["../../src/format/html.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EACL,sBAAsB,EACtB,aAAa,EACb,eAAe,GAChB,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC3E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAGvE,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD;;GAEG;AACH,MAAM,WAAW,WAAY,SAAQ,cAAc;IACjD;;;;;OAKG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,OAAO,CAAC;IAC/B;;;;;OAKG;IACH,QAAQ,CAAC,aAAa,CAAC,EAAE,OAAO,CAAC;IACjC;;;;;;OAMG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC;IACxB;;;;;;;;;;;;;OAaG;IACH,QAAQ,CAAC,aAAa,CAAC,EAAE,mBAAmB,CAAC;CAC9C;AAYD;;;;;;;;GAQG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAK3C;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,WAAW,CACzB,MAAM,EAAE,SAAS,cAAc,EAAE,EACjC,OAAO,EAAE,WAAW,GACnB,MAAM,CAgBR;AAED;;;;;GAKG;AACH,wBAAgB,MAAM,CACpB,MAAM,EAAE,SAAS,cAAc,EAAE,EACjC,OAAO,GAAE,WAAgB,GACxB,MAAM,CAER"}
|
package/dist/format/html.js
CHANGED
|
@@ -1,49 +1,13 @@
|
|
|
1
|
-
import { isUncertain } from "../decode/confidence.js";
|
|
2
|
-
export { convertToAnnotatedHtml, convertToHtml, toAnnotatedHtml, } from "./annotate.js";
|
|
3
|
-
import { READING_CHARGE } from "../decode/lattice.js";
|
|
4
|
-
import { DEFAULT_LOCALE } from "../script/script.js";
|
|
5
|
-
import { writeSyllable } from "../syllable/syllable.js";
|
|
6
|
-
/**
|
|
7
|
-
* The class every syllable carries, whatever else it carries.
|
|
8
|
-
*/
|
|
9
|
-
const SYLLABLE_CLASS = "py-syllable";
|
|
10
|
-
const UNCERTAIN_CLASS = "py-uncertain";
|
|
11
1
|
/**
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* A syllable element holds Mandarin written in the Latin alphabet, which is
|
|
15
|
-
* neither the `zh` of the surrounding page nor the `en` of a page that quotes
|
|
16
|
-
* it — and nothing about `yín` on its own says so. The tag is what a screen
|
|
17
|
-
* reader consults before deciding how to pronounce it, and what a browser
|
|
18
|
-
* consults for hyphenation and font selection; without one, `xíng` is read as
|
|
19
|
-
* whatever the page around it claims to be, which is how pinyin ends up
|
|
20
|
-
* spoken as English.
|
|
21
|
-
*
|
|
22
|
-
* The subtags are all registered and mean exactly this: `Latn` for the script,
|
|
23
|
-
* the region for the reading standard, and the `pinyin` variant, whose prefix
|
|
24
|
-
* in the IANA registry is `zh-Latn`. The region is the one distinction the
|
|
25
|
-
* conversion itself makes — 垃圾 is `lājī` under `zh-CN` and `lèsè` under
|
|
26
|
-
* `zh-TW` — so it is read off {@link ConvertOptions.locale} rather than
|
|
27
|
-
* guessed at.
|
|
2
|
+
* A conversion as markup, and the options that decide what the markup carries.
|
|
28
3
|
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
* The cost is the tag repeated on every syllable, which is the price of
|
|
33
|
-
* wrapping nothing around the whole conversion. A caller who would rather
|
|
34
|
-
* declare it once can set `lang: false` and put the same tag on a wrapper of
|
|
35
|
-
* their own, which is inherited by everything inside it.
|
|
4
|
+
* One element per syllable, which is what lets a page colour a tone or mark a
|
|
5
|
+
* guess. What goes inside one of those elements is `syllable-span.ts` and the
|
|
6
|
+
* ruby that puts the reading over the hanzi is `annotate.ts`.
|
|
36
7
|
*/
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
return "zh-Latn-CN-pinyin";
|
|
41
|
-
}
|
|
42
|
-
case "zh-TW": {
|
|
43
|
-
return "zh-Latn-TW-pinyin";
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
8
|
+
export { convertToAnnotatedHtml, convertToHtml, toAnnotatedHtml, } from "./annotate.js";
|
|
9
|
+
import { writePiece } from "./syllable-span.js";
|
|
10
|
+
export { writePiece } from "./syllable-span.js";
|
|
47
11
|
/**
|
|
48
12
|
* How each character that means something in markup is written as text.
|
|
49
13
|
*/
|
|
@@ -69,49 +33,36 @@ export function escape(text) {
|
|
|
69
33
|
});
|
|
70
34
|
}
|
|
71
35
|
/**
|
|
72
|
-
*
|
|
36
|
+
* Mark up a run of pieces, with the system's join between two syllables.
|
|
73
37
|
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
return [...new Set(written)];
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Mark up one piece of a conversion.
|
|
38
|
+
* Pinyin needs none. Its syllables are run together and the marks that divide
|
|
39
|
+
* them are pieces of their own. Every other system decides the join for itself,
|
|
40
|
+
* and the join is what separates the five at this level, so it is written
|
|
41
|
+
* between the spans rather than inside one. `<span>Pei³</span>-<span>ching¹
|
|
42
|
+
* </span>` is one word in Wade-Giles and leaves each syllable its own element
|
|
43
|
+
* to carry a tone class on.
|
|
44
|
+
*
|
|
45
|
+
* A piece that wrote nothing does not break the run, which is what carries the
|
|
46
|
+
* join over pinyin's own hyphen: 干干净净 is four syllables of one word, and
|
|
47
|
+
* the mark between the second and the third is dropped rather than counted as a
|
|
48
|
+
* gap.
|
|
89
49
|
*/
|
|
90
|
-
export function
|
|
91
|
-
const {
|
|
92
|
-
if (
|
|
93
|
-
return
|
|
50
|
+
export function writePieces(pieces, options) {
|
|
51
|
+
const { transcription } = options;
|
|
52
|
+
if (transcription === undefined) {
|
|
53
|
+
return pieces.map((piece) => writePiece(piece, options)).join("");
|
|
94
54
|
}
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
if (alternatives.length > 0) {
|
|
105
|
-
classes.push(UNCERTAIN_CLASS);
|
|
106
|
-
}
|
|
107
|
-
const attributes = [`class="${classes.join(" ")}"`];
|
|
108
|
-
if (lang) {
|
|
109
|
-
attributes.push(`lang="${languageTag(options.locale)}"`);
|
|
110
|
-
}
|
|
111
|
-
if (alternatives.length > 0) {
|
|
112
|
-
attributes.push(`data-alternatives="${escape(alternatives.join(" "))}"`);
|
|
55
|
+
const written = [];
|
|
56
|
+
let isJoined = false;
|
|
57
|
+
for (const piece of pieces) {
|
|
58
|
+
const markup = writePiece(piece, options);
|
|
59
|
+
if (piece.syllable !== undefined && isJoined) {
|
|
60
|
+
written.push(transcription.separator);
|
|
61
|
+
}
|
|
62
|
+
written.push(markup);
|
|
63
|
+
isJoined = piece.syllable !== undefined || (isJoined && markup === "");
|
|
113
64
|
}
|
|
114
|
-
return
|
|
65
|
+
return written.join("");
|
|
115
66
|
}
|
|
116
67
|
/**
|
|
117
68
|
* Mark up a converted text, one element per syllable.
|
|
@@ -120,6 +71,6 @@ export function writePiece(piece, options) {
|
|
|
120
71
|
* once and render more than one way.
|
|
121
72
|
*/
|
|
122
73
|
export function toHtml(pieces, options = {}) {
|
|
123
|
-
return pieces
|
|
74
|
+
return writePieces(pieces, options);
|
|
124
75
|
}
|
|
125
76
|
//# sourceMappingURL=html.js.map
|
package/dist/format/html.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"html.js","sourceRoot":"","sources":["../../src/format/html.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"html.js","sourceRoot":"","sources":["../../src/format/html.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EACL,sBAAsB,EACtB,aAAa,EACb,eAAe,GAChB,MAAM,eAAe,CAAC;AAGvB,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD,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AK,CAAC,QAAQ,KAAK,SAAS,IAAI,CAAC,QAAQ,IAAI,MAAM,KAAK,EAAE,CAAC,CAAC;IACzE,CAAC;IACD,OAAO,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAC1B,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,MAAM,CACpB,MAAiC,EACjC,OAAO,GAAgB,EAAE;IAEzB,OAAO,WAAW,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AACtC,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a written reading declares itself to be, in BCP 47.
|
|
3
|
+
*
|
|
4
|
+
* One place that knows the subtags and the order they go in, since the tag is
|
|
5
|
+
* the same question whether the reading is pinyin or one of the five systems
|
|
6
|
+
* that can stand in for it.
|
|
7
|
+
*/
|
|
8
|
+
import { type Locale } from "../script/script.js";
|
|
9
|
+
import type { TranscriptionSystem } from "../transcription/systems.js";
|
|
10
|
+
/**
|
|
11
|
+
* The BCP 47 region subtag for a reading standard.
|
|
12
|
+
*/
|
|
13
|
+
export declare function regionOf(locale: Locale): string;
|
|
14
|
+
/**
|
|
15
|
+
* What a syllable declares itself to be, in the system it was written in.
|
|
16
|
+
*
|
|
17
|
+
* A syllable element holds Mandarin written in some script that is not the `zh`
|
|
18
|
+
* of the surrounding page and not the `en` of a page that quotes it, and
|
|
19
|
+
* nothing about `yín` on its own says so. The tag is what a screen reader
|
|
20
|
+
* consults before deciding how to pronounce it, and what a browser consults for
|
|
21
|
+
* hyphenation and font selection. Without one, `xíng` is read as whatever the
|
|
22
|
+
* page around it claims to be, which is how pinyin ends up spoken as English.
|
|
23
|
+
*
|
|
24
|
+
* The subtags are registered and mean exactly this. The script is `Latn` for a
|
|
25
|
+
* romanisation and `Bopo` for bopomofo, the region is the reading standard, and
|
|
26
|
+
* the variant names the system where the IANA registry has one. It has `pinyin`
|
|
27
|
+
* and `wadegile`, both with the prefix `zh-Latn`, and `fonipa` for the IPA.
|
|
28
|
+
*
|
|
29
|
+
* | System | `zh-CN` | `zh-TW` |
|
|
30
|
+
* | --- | --- | --- |
|
|
31
|
+
* | pinyin | `zh-Latn-CN-pinyin` | `zh-Latn-TW-pinyin` |
|
|
32
|
+
* | bopomofo | `zh-Bopo-CN` | `zh-Bopo-TW` |
|
|
33
|
+
* | Wade-Giles | `zh-Latn-CN-wadegile` | `zh-Latn-TW-wadegile` |
|
|
34
|
+
* | Yale | `zh-Latn-CN` | `zh-Latn-TW` |
|
|
35
|
+
* | Gwoyeu Romatzyh | `zh-Latn-CN` | `zh-Latn-TW` |
|
|
36
|
+
* | IPA | `zh-Latn-CN-fonipa` | `zh-Latn-TW-fonipa` |
|
|
37
|
+
*
|
|
38
|
+
* **The region is carried by every one of them**, because the distinction it
|
|
39
|
+
* marks is in the reading rather than in the spelling. 垃圾 is `lājī` under
|
|
40
|
+
* `zh-CN` and `lèsè` under `zh-TW`, and it is two different words in bopomofo
|
|
41
|
+
* for the same reason, so the region is read off {@link ConvertOptions.locale}
|
|
42
|
+
* rather than guessed at.
|
|
43
|
+
*
|
|
44
|
+
* Yale and Gwoyeu Romatzyh name themselves nowhere, the registry having no
|
|
45
|
+
* variant for either, so both go out saying only that they are Mandarin in the
|
|
46
|
+
* Latin alphabet. See {@link TranscriptionSystem.variant}.
|
|
47
|
+
*
|
|
48
|
+
* Tone notation does not enter into it. `hang2` is pinyin spelt with a tone
|
|
49
|
+
* number, not another romanisation, so it takes the same tag as `háng`.
|
|
50
|
+
*
|
|
51
|
+
* The cost is the tag repeated on every syllable, which is the price of
|
|
52
|
+
* wrapping nothing around the whole conversion. A caller who would rather
|
|
53
|
+
* declare it once can set `lang: false` and put the same tag on a wrapper of
|
|
54
|
+
* their own, which is inherited by everything inside it.
|
|
55
|
+
*/
|
|
56
|
+
export declare function languageTag(locale?: Locale, system?: TranscriptionSystem): string;
|
|
57
|
+
//# sourceMappingURL=language-tag.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"language-tag.d.ts","sourceRoot":"","sources":["../../src/format/language-tag.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAkB,KAAK,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AASvE;;GAEG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAS/C;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,wBAAgB,WAAW,CACzB,MAAM,GAAE,MAAuB,EAC/B,MAAM,CAAC,EAAE,mBAAmB,GAC3B,MAAM,CAKR"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a written reading declares itself to be, in BCP 47.
|
|
3
|
+
*
|
|
4
|
+
* One place that knows the subtags and the order they go in, since the tag is
|
|
5
|
+
* the same question whether the reading is pinyin or one of the five systems
|
|
6
|
+
* that can stand in for it.
|
|
7
|
+
*/
|
|
8
|
+
import { DEFAULT_LOCALE } from "../script/script.js";
|
|
9
|
+
/**
|
|
10
|
+
* The pinyin variant's script and its own subtag, which a conversion writes by
|
|
11
|
+
* default.
|
|
12
|
+
*/
|
|
13
|
+
const PINYIN_SCRIPT = "Latn";
|
|
14
|
+
const PINYIN_VARIANT = "pinyin";
|
|
15
|
+
/**
|
|
16
|
+
* The BCP 47 region subtag for a reading standard.
|
|
17
|
+
*/
|
|
18
|
+
export function regionOf(locale) {
|
|
19
|
+
switch (locale) {
|
|
20
|
+
case "zh-CN": {
|
|
21
|
+
return "CN";
|
|
22
|
+
}
|
|
23
|
+
case "zh-TW": {
|
|
24
|
+
return "TW";
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* What a syllable declares itself to be, in the system it was written in.
|
|
30
|
+
*
|
|
31
|
+
* A syllable element holds Mandarin written in some script that is not the `zh`
|
|
32
|
+
* of the surrounding page and not the `en` of a page that quotes it, and
|
|
33
|
+
* nothing about `yín` on its own says so. The tag is what a screen reader
|
|
34
|
+
* consults before deciding how to pronounce it, and what a browser consults for
|
|
35
|
+
* hyphenation and font selection. Without one, `xíng` is read as whatever the
|
|
36
|
+
* page around it claims to be, which is how pinyin ends up spoken as English.
|
|
37
|
+
*
|
|
38
|
+
* The subtags are registered and mean exactly this. The script is `Latn` for a
|
|
39
|
+
* romanisation and `Bopo` for bopomofo, the region is the reading standard, and
|
|
40
|
+
* the variant names the system where the IANA registry has one. It has `pinyin`
|
|
41
|
+
* and `wadegile`, both with the prefix `zh-Latn`, and `fonipa` for the IPA.
|
|
42
|
+
*
|
|
43
|
+
* | System | `zh-CN` | `zh-TW` |
|
|
44
|
+
* | --- | --- | --- |
|
|
45
|
+
* | pinyin | `zh-Latn-CN-pinyin` | `zh-Latn-TW-pinyin` |
|
|
46
|
+
* | bopomofo | `zh-Bopo-CN` | `zh-Bopo-TW` |
|
|
47
|
+
* | Wade-Giles | `zh-Latn-CN-wadegile` | `zh-Latn-TW-wadegile` |
|
|
48
|
+
* | Yale | `zh-Latn-CN` | `zh-Latn-TW` |
|
|
49
|
+
* | Gwoyeu Romatzyh | `zh-Latn-CN` | `zh-Latn-TW` |
|
|
50
|
+
* | IPA | `zh-Latn-CN-fonipa` | `zh-Latn-TW-fonipa` |
|
|
51
|
+
*
|
|
52
|
+
* **The region is carried by every one of them**, because the distinction it
|
|
53
|
+
* marks is in the reading rather than in the spelling. 垃圾 is `lājī` under
|
|
54
|
+
* `zh-CN` and `lèsè` under `zh-TW`, and it is two different words in bopomofo
|
|
55
|
+
* for the same reason, so the region is read off {@link ConvertOptions.locale}
|
|
56
|
+
* rather than guessed at.
|
|
57
|
+
*
|
|
58
|
+
* Yale and Gwoyeu Romatzyh name themselves nowhere, the registry having no
|
|
59
|
+
* variant for either, so both go out saying only that they are Mandarin in the
|
|
60
|
+
* Latin alphabet. See {@link TranscriptionSystem.variant}.
|
|
61
|
+
*
|
|
62
|
+
* Tone notation does not enter into it. `hang2` is pinyin spelt with a tone
|
|
63
|
+
* number, not another romanisation, so it takes the same tag as `háng`.
|
|
64
|
+
*
|
|
65
|
+
* The cost is the tag repeated on every syllable, which is the price of
|
|
66
|
+
* wrapping nothing around the whole conversion. A caller who would rather
|
|
67
|
+
* declare it once can set `lang: false` and put the same tag on a wrapper of
|
|
68
|
+
* their own, which is inherited by everything inside it.
|
|
69
|
+
*/
|
|
70
|
+
export function languageTag(locale = DEFAULT_LOCALE, system) {
|
|
71
|
+
const script = system?.script ?? PINYIN_SCRIPT;
|
|
72
|
+
const variant = system === undefined ? PINYIN_VARIANT : system.variant;
|
|
73
|
+
const tag = `zh-${script}-${regionOf(locale)}`;
|
|
74
|
+
return variant === undefined ? tag : `${tag}-${variant}`;
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=language-tag.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"language-tag.js","sourceRoot":"","sources":["../../src/format/language-tag.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,cAAc,EAAe,MAAM,qBAAqB,CAAC;AAGlE;;;GAGG;AACH,MAAM,aAAa,GAAG,MAAM,CAAC;AAC7B,MAAM,cAAc,GAAG,QAAQ,CAAC;AAEhC;;GAEG;AACH,MAAM,UAAU,QAAQ,CAAC,MAAc;IACrC,QAAQ,MAAM,EAAE,CAAC;QACf,KAAK,OAAO,EAAE,CAAC;YACb,OAAO,IAAI,CAAC;QACd,CAAC;QACD,KAAK,OAAO,EAAE,CAAC;YACb,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,MAAM,UAAU,WAAW,CACzB,MAAM,GAAW,cAAc,EAC/B,MAA4B;IAE5B,MAAM,MAAM,GAAG,MAAM,EAAE,MAAM,IAAI,aAAa,CAAC;IAC/C,MAAM,OAAO,GAAG,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC;IACvE,MAAM,GAAG,GAAG,MAAM,MAAM,IAAI,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;IAC/C,OAAO,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,IAAI,OAAO,EAAE,CAAC;AAC3D,CAAC"}
|