Skip to content

Commit b64e364

Browse files
lorumicwooorm
authored andcommitted
Fix incorrect results for Japanese
Closes GH-77. Reviewed-by: Titus Wormer <[email protected]>
1 parent 760067e commit b64e364

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

script/build.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,11 @@ function generate(basename) {
124124
})
125125
})
126126

127-
/* Push Japanese. */
127+
/* Push Japanese.
128+
* Unicode Kanji Table from http://www.rikai.com/library/kanjitables/kanji_codes.unicode.shtml */
129+
var kanjiRegexSource = '[\u3400-\u4DB5\u4E00-\u9FAF]'
128130
regularExpressions.jpn = new RegExp(
129-
expressions.Hiragana.source + '|' + expressions.Katakana.source,
131+
expressions.Hiragana.source + '|' + expressions.Katakana.source + '|' + kanjiRegexSource,
130132
'g'
131133
)
132134

test/api.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,36 @@ test('franc()', function(t) {
4848
'should work on unique-scripts with many latin characters (2)'
4949
)
5050

51+
t.equal(
52+
franc('すべての人は、生命、自由及び身体の安全に対する権利を有する。'),
53+
'jpn',
54+
'should detect Japanese even when Han ratio > 0.5 (udhr_jpn art 3) (1)'
55+
)
56+
57+
t.equal(
58+
franc(
59+
[
60+
'すべての人は、憲法又は法律によって与えられた基本的権利を侵害する行為に対し、',
61+
'権限を有する国内裁判所による効果的な救済を受ける権利を有する。'
62+
].join('')
63+
),
64+
'jpn',
65+
'should detect Japanese even when Han ratio > 0.5 (udhr_jpn art 8) (2)'
66+
)
67+
68+
t.equal(
69+
franc(
70+
[
71+
'成年の男女は、人種、国籍又は宗教によるいかなる制限をも受けることなく、婚姻し、',
72+
'かつ家庭をつくる権利を有する。成年の男女は、婚姻中及びその解消に際し、',
73+
'婚姻に関し平等の権利を有する。婚姻は、婚姻の意思を有する両当事者の自由かつ完全な合意によってのみ成立する。',
74+
'家庭は、社会の自然かつ基礎的な集団単位であって、社会及び国の保護を受ける権利を有する。'
75+
].join('')
76+
),
77+
'jpn',
78+
'should detect Japanese even when Han ratio > 0.5 (udhr_jpn art 16) (3)'
79+
)
80+
5181
t.notEqual(
5282
franc(fixtureB, {ignore: [franc(fixtureB)]}),
5383
franc(fixtureB),

0 commit comments

Comments
 (0)