From 8d3be0d8b623a405990448a5ea4fe471ab735ed7 Mon Sep 17 00:00:00 2001 From: horus Date: Sun, 19 Apr 2020 18:35:27 +0200 Subject: Update to get spoken language and minor upgrade the github handling. --- chinese.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 chinese.go (limited to 'chinese.go') diff --git a/chinese.go b/chinese.go new file mode 100644 index 0000000..48ccd5e --- /dev/null +++ b/chinese.go @@ -0,0 +1,25 @@ +package main + +import ( + "unicode" +) + +func IsChinese(str string) bool { + count_chinese := 0 + count_no_chinese := 0 + for _, char := range str { + if unicode.Is(unicode.Han, char) { + count_chinese++ + } else { + if !unicode.IsSpace(char) { + count_no_chinese++ + } + } + } + // >= 10% of the text is chinese + if count_chinese >= count_no_chinese/10 { + return true + } + + return false +} -- cgit v1.2.3