Skip to content

Commit

Permalink
Merge pull request #51 from minoguep/add-support-for-auto-language-an…
Browse files Browse the repository at this point in the history
…d-preferred_variants

Add support for 'auto' language type which is available from LanguageTool API
  • Loading branch information
jxmorris12 authored Dec 20, 2021
2 parents 3df7ce4 + 2b2d567 commit e8d7a1a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions language_tool_python/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def __init__(self, language=None, motherTongue=None, remote_server=None, newSpel
self.disabled_categories = set()
self.enabled_categories = set()
self.enabled_rules_only = False
self.preferred_variants = set()
self._instances[id(self)] = self

def __enter__(self):
Expand Down Expand Up @@ -134,6 +135,8 @@ def _create_params(self, text: str) -> Dict[str, str]:
params['disabledCategories'] = ','.join(self.disabled_categories)
if self.enabled_categories:
params['enabledCategories'] = ','.join(self.enabled_categories)
if self.preferred_variants:
params['preferredVariants'] = ','.join(self.preferred_variants)
# return urllib.parse.urlencode(params).encode()
return params

Expand Down Expand Up @@ -187,6 +190,7 @@ def _get_languages(self) -> set:
for e in self._query_server(url, num_tries=1):
languages.add(e.get('code'))
languages.add(e.get('longCode'))
languages.add("auto")
return languages

def _start_server_if_needed(self):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_major_functionality.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def test_langtool_load():
def test_langtool_languages():
import language_tool_python
lang_tool = language_tool_python.LanguageTool("en-US")
assert lang_tool._get_languages() == {'es-AR', 'ta-IN', 'en-CA', 'da', 'eo', 'pt-AO', 'de', 'gl', 'ru-RU', 'de-DE', 'en', 'br', 'en-ZA', 'pt-MZ', 'ast-ES', 'sk-SK', 'en-AU', 'ta', 'ga', 'be', 'pl', 'tl-PH', 'sl', 'ar', 'es', 'sl-SI', 'en-NZ', 'el', 'el-GR', 'ru', 'zh-CN', 'en-GB', 'be-BY', 'pl-PL', 'km-KH', 'pt', 'uk-UA', 'ca', 'de-DE-x-simple-language', 'ro', 'ca-ES', 'de-CH', 'ja-JP', 'tl', 'pt-PT', 'gl-ES', 'pt-BR', 'km', 'ga-IE', 'ja', 'sv', 'sk', 'en-US', 'de-AT', 'ca-ES-valencia', 'uk', 'it', 'zh', 'br-FR', 'da-DK', 'ast', 'fr', 'fa', 'nl', 'ro-RO', 'nl-BE'}
assert lang_tool._get_languages() == {'es-AR', 'ta-IN', 'en-CA', 'da', 'eo', 'pt-AO', 'de', 'gl', 'ru-RU', 'de-DE', 'en', 'br', 'en-ZA', 'pt-MZ', 'ast-ES', 'sk-SK', 'en-AU', 'ta', 'ga', 'be', 'pl', 'tl-PH', 'sl', 'ar', 'es', 'sl-SI', 'en-NZ', 'el', 'el-GR', 'ru', 'zh-CN', 'en-GB', 'be-BY', 'pl-PL', 'km-KH', 'pt', 'uk-UA', 'ca', 'de-DE-x-simple-language', 'ro', 'ca-ES', 'de-CH', 'ja-JP', 'tl', 'pt-PT', 'gl-ES', 'pt-BR', 'km', 'ga-IE', 'ja', 'sv', 'sk', 'en-US', 'de-AT', 'ca-ES-valencia', 'uk', 'it', 'zh', 'br-FR', 'da-DK', 'ast', 'fr', 'fa', 'nl', 'ro-RO', 'nl-BE', 'auto'}

def test_match():
import language_tool_python
Expand Down

0 comments on commit e8d7a1a

Please sign in to comment.