在Go中获取Unicode脚本名称

时间:2019-05-06 11:01:05

标签: go unicode

在Go中,我想获取给定特定语言的脚本的RangeTable。

import (
    "golang.org/x/text/language"
    "unicode"
)

...

script, confidence := language.French.Script() 
scriptAsString := script.String() // here scriptAsString = "Latn"
rangeTable, ok := unicode.Scripts[scriptAsString]
// here ok = false, because the Scripts map has key "Latin" and not "Latn"

问题在于以下函数返回script code

func (s Script) String() string 

地图unicode.Scripts的所有键都使用script name

您知道原生Go库中是否存在从script codescript name的方法?

编辑

此处已打开问题:github.com/golang/go/issues/31862

1 个答案:

答案 0 :(得分:0)

这是我所追求的那种映射:

var scriptCodeToScriptNames = map[string][]string {
    "Adlm": {"Adlam"},
    "Afak": {"Afaka"},
    "Aghb": {"Caucasian_Albanian"},
    "Ahom": {"Ahom"},
    "Arab": {"Arabic"},
    "Aran": {"Arabic"},
    "Armi": {"Imperial_Aramaic"},
    "Armn": {"Armenian"},
    "Avst": {"Avestan"},
    "Bali": {"Balinese"},
    "Bamu": {"Bamum"},
    "Bass": {"Bassa_Vah"},
    "Batk": {"Batak"},
    "Beng": {"Bengali"},
    "Bhks": {"Bhaiksuki"},
    "Bopo": {"Bopomofo"},
    "Brah": {"Brahmi"},
    "Brai": {"Braille"},
    "Bugi": {"Buginese"},
    "Buhd": {"Buhid"},
    "Cakm": {"Chakma"},
    "Cans": {"Canadian_Aboriginal"},
    "Cari": {"Carian"},
    "Cham": {"Cham"},
    "Cher": {"Cherokee"},
    "Copt": {"Coptic"},
    "Cpmn": {"Cypro-Minoan"},
    "Cprt": {"Cypriot"},
    "Cyrl": {"Cyrillic"},
    "Cyrs": {"Cyrillic"},
    "Deva": {"Devanagari"},
    "Dogr": {"Dogra"},
    "Dsrt": {"Deseret"},
    "Dupl": {"Duployan"},
    "Egyd": {"Egyptian_Demotic"},
    "Egyh": {"Egyptian_Hieratic"},
    "Egyp": {"Egyptian_Hieroglyphs"},
    "Elba": {"Elbasan"},
    "Ethi": {"Ethiopic"},
    "Geok": {"Khutsuri"},
    "Geor": {"Georgian"},
    "Glag": {"Glagolitic"},
    "Gong": {"Gunjala_Gondi"},
    "Gonm": {"Masaram_Gondi"},
    "Goth": {"Gothic"},
    "Gran": {"Grantha"},
    "Grek": {"Greek"},
    "Gujr": {"Gujarati"},
    "Guru": {"Gurmukhi"},
    "Hanb": {"Han", "Bopomofo"},
    "Hang": {"Hangul"},
    "Hani": {"Han"},
    "Hano": {"Hanunoo"},
    "Hans": {"Han"},
    "Hant": {"Han"},
    "Hatr": {"Hatran"},
    "Hebr": {"Hebrew"},
    "Hira": {"Hiragana"},
    "Hluw": {"Anatolian_Hieroglyphs"},
    "Hmng": {"Pahawh_Hmong"},
    "Hmnp": {"Nyiakeng_Puachue_Hmong"},
    "Hrkt": {"Hiragana", "Katakana"},
    "Hung": {"Old_Hungarian"},
    "Inds": {"Indus_(Harappan)"},
    "Ital": {"Old_Italic"},
    "Jamo": {"Hangul"},
    "Java": {"Javanese"},
    "Jpan": {"Han", "Hiragana", "Katakana"},
    "Jurc": {"Jurchen"},
    "Kali": {"Kayah_Li"},
    "Kana": {"Katakana"},
    "Khar": {"Kharoshthi"},
    "Khmr": {"Khmer"},
    "Khoj": {"Khojki"},
    "Kitl": {"Khitan_large_script"},
    "Kits": {"Khitan_small_script"},
    "Knda": {"Kannada"},
    "Kore": {"Hangul", "Han"},
    "Kpel": {"Kpelle"},
    "Kthi": {"Kaithi"},
    "Lana": {"Tai_Tham"},
    "Laoo": {"Lao"},
    "Latf": {"Latin"},
    "Latg": {"Latin"},
    "Latn": {"Latin"},
    "Leke": {"Leke"},
    "Lepc": {"Lepcha"},
    "Limb": {"Limbu"},
    "Lina": {"Linear_A"},
    "Linb": {"Linear_B"},
    "Lisu": {"Lisu"},
    "Loma": {"Loma"},
    "Lyci": {"Lycian"},
    "Lydi": {"Lydian"},
    "Mahj": {"Mahajani"},
    "Maka": {"Makasar"},
    "Mand": {"Mandaic"},
    "Mani": {"Manichaean"},
    "Marc": {"Marchen"},
    "Maya": {"Mayan_hieroglyphs"},
    "Mend": {"Mende_Kikakui"},
    "Merc": {"Meroitic_Cursive"},
    "Mero": {"Meroitic_Hieroglyphs"},
    "Mlym": {"Malayalam"},
    "Modi": {"Modi"},
    "Mong": {"Mongolian"},
    "Mroo": {"Mro"},
    "Mtei": {"Meetei_Mayek"},
    "Mult": {"Multani"},
    "Mymr": {"Myanmar"},
    "Narb": {"Old_North_Arabian"},
    "Nbat": {"Nabataean"},
    "Newa": {"Newa"},
    "Nkoo": {"Nko"},
    "Nshu": {"Nushu"},
    "Ogam": {"Ogham"},
    "Olck": {"Ol_Chiki"},
    "Orkh": {"Old_Turkic"},
    "Orya": {"Oriya"},
    "Osge": {"Osage"},
    "Osma": {"Osmanya"},
    "Palm": {"Palmyrene"},
    "Pauc": {"Pau_Cin_Hau"},
    "Perm": {"Old_Permic"},
    "Phag": {"Phags_Pa"},
    "Phli": {"Inscriptional_Pahlavi"},
    "Phlp": {"Psalter_Pahlavi"},
    "Phlv": {"Book_Pahlavi"},
    "Phnx": {"Phoenician"},
    "Plrd": {"Miao"},
    "Prti": {"Inscriptional_Parthian"},
    "Rjng": {"Rejang"},
    "Rohg": {"Hanifi_Rohingya"},
    "Roro": {"Rongorongo"},
    "Runr": {"Runic"},
    "Samr": {"Samaritan"},
    "Sara": {"Sarati"},
    "Sarb": {"Old_South_Arabian"},
    "Saur": {"Saurashtra"},
    "Sgnw": {"SignWriting"},
    "Shaw": {"Shavian"},
    "Shrd": {"Sharada"},
    "Shui": {"Shuishu"},
    "Sidd": {"Siddham"},
    "Sind": {"Khudawadi"},
    "Sinh": {"Sinhala"},
    "Sogd": {"Sogdian"},
    "Sogo": {"Old_Sogdian"},
    "Sora": {"Sora_Sompeng"},
    "Soyo": {"Soyombo"},
    "Sund": {"Sundanese"},
    "Sylo": {"Syloti_Nagri"},
    "Syrc": {"Syriac"},
    "Syre": {"Syriac"},
    "Syrj": {"Syriac"},
    "Syrn": {"Syriac"},
    "Tagb": {"Tagbanwa"},
    "Takr": {"Takri"},
    "Tale": {"Tai_Le"},
    "Talu": {"New_Tai_Lue"},
    "Taml": {"Tamil"},
    "Tang": {"Tangut"},
    "Tavt": {"Tai_Viet"},
    "Telu": {"Telugu"},
    "Teng": {"Tengwar"},
    "Tfng": {"Tifinagh"},
    "Tglg": {"Tagalog"},
    "Thaa": {"Thaana"},
    "Thai": {"Thai"},
    "Tibt": {"Tibetan"},
    "Tirh": {"Tirhuta"},
    "Ugar": {"Ugaritic"},
    "Vaii": {"Vai"},
    "Visp": {"Visible_Speech"},
    "Wara": {"Warang_Citi"},
    "Wcho": {"Wancho"},
    "Wole": {"Woleai"},
    "Xpeo": {"Old_Persian"},
    "Xsux": {"Cuneiform"},
    "Yiii": {"Yi"},
    "Zanb": {"Zanabazar_Square"},
    "Zinh": {"Inherited"},
    "Zyyy": {"Common"},
}