本文整理汇总了Python中enchant.list_languages方法的典型用法代码示例。如果您正苦于以下问题:Python enchant.list_languages方法的具体用法?Python enchant.list_languages怎么用?Python enchant.list_languages使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类enchant
的用法示例。
在下文中一共展示了enchant.list_languages方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_spellchecker_languages
# 需要导入模块: import enchant [as 别名]
# 或者: from enchant import list_languages [as 别名]
def get_spellchecker_languages(directory = None):
"""
Check if spellchecker is installed and provide list of languages
"""
try:
import enchant
if (directory):
enchant.set_param("enchant.myspell.dictionary.path", directory)
langs = enchant.list_languages()
return sorted(langs)
except:
print("can not start spellchecker!!!")
import traceback
traceback.print_exc()
return None
# for testing module funcionality
示例2: set_args
# 需要导入模块: import enchant [as 别名]
# 或者: from enchant import list_languages [as 别名]
def set_args():
global args
parser = argparse.ArgumentParser()
parser.add_argument("-t", "--text", help="text to read from. If not specified the program will read from standard input")
parser.add_argument("-k", "--key", help="key used to encrypt. If no key is provided the program will try to crack and decrypt using the specified language", type=int)
parser.add_argument("-l", "--lang", help=f"available languages: {enchant.list_languages()} (default: en_US). Only useful if no key is provided", default='en_US')
parser.add_argument("-V", "--verbose", action='store_true', help="show extra information")
parser.add_argument("-A", "--all", action='store_true', help="show decrypted text for each tested key")
parser.add_argument("-D", "--debug", action='store_true', help="show information about text validation")
parser.add_argument("-T", "--threshold", help="valid word count percentage to mark the whole text as valid language (default: 50)", type=int, default=50)
parser.add_argument("--beep", action='store_true', help="plays a beep sound when program finishes. May require SOX to be installed")
args = parser.parse_args()
示例3: list_languages
# 需要导入模块: import enchant [as 别名]
# 或者: from enchant import list_languages [as 别名]
def list_languages(self):
# Note: We do NOT return enchant.list_dicts because that also returns
# the enchant dict objects and not only the language identifiers.
return enchant.list_languages()
示例4: initSpellchecker
# 需要导入模块: import enchant [as 别名]
# 或者: from enchant import list_languages [as 别名]
def initSpellchecker(self):
# TODO: disable spellchecker icon in case of not working enchant
try:
import enchant
spellDictDir = settings.get('spellchecker:directory')
if spellDictDir:
if enchant.__ver_major__ >= 1 and enchant.__ver_minor__ >= 6:
enchant.set_param("enchant.myspell.dictionary.path",
spellDictDir)
else:
print("Your pyenchant version is to old. Please " \
"upgrade to version 1.6.0 or higher, if you want " \
"to use spellchecker.")
return None
spellLang = settings.get('spellchecker:lang')
if spellLang in enchant.list_languages():
# enchant.dict_exists(spellLang) do now work for me on linux...
self.dict = enchant.Dict(spellLang)
else:
# try dictionary based on the current locale
try:
self.dict = enchant.Dict()
settings.set('spellchecker:lang', self.dict.tag)
except: # we don not have working dictionary...
return None
if self.dict:
self.usePWL(self.dict)
except:
print("can not start spellchecker!!!")
import traceback
traceback.print_exc()
return None
示例5: get_enchant_base_languages_dict
# 需要导入模块: import enchant [as 别名]
# 或者: from enchant import list_languages [as 别名]
def get_enchant_base_languages_dict():
"""Get ordered dictionary of enchant base languages.
locale_language, then "en", then the rest.
"""
global enchant_base_languages_dict
if enchant_base_languages_dict is None:
def get_language_sub_tag(tag):
return tag.split("_")[0]
enchant_base_languages_dict = OrderedDict()
enchant_languages = sorted(enchant.list_languages())
for full_tag in [get_locale_language(), FALLBACK_LANGUAGE]:
sub_tag = get_language_sub_tag(full_tag)
if sub_tag not in enchant_base_languages_dict:
for tag in [full_tag, sub_tag]:
try:
index = enchant_languages.index(tag)
except ValueError:
pass
else:
enchant_base_languages_dict[sub_tag] = tag
del enchant_languages[index]
break
for tag in enchant_languages:
sub_tag = get_language_sub_tag(tag)
if sub_tag not in enchant_base_languages_dict:
enchant_base_languages_dict[sub_tag] = tag
return enchant_base_languages_dict