summaryrefslogtreecommitdiff
path: root/searx/utils.py
diff options
context:
space:
mode:
authorpotato <mail@crazypotato.tk>2016-09-06 16:43:48 +0200
committerpotato <mail@crazypotato.tk>2016-09-06 16:43:48 +0200
commit983415bc38937a637e9b2aae191f2e087765800b (patch)
tree30a166d7cd791f4d38d961b43f35f9daeca0d2f2 /searx/utils.py
parentb7d578ae8041658fe6f088eb337f42238c25e2f5 (diff)
downloadsearxng-983415bc38937a637e9b2aae191f2e087765800b.tar.gz
searxng-983415bc38937a637e9b2aae191f2e087765800b.zip
[enh] is_valid_lang moved to utils
Diffstat (limited to 'searx/utils.py')
-rw-r--r--searx/utils.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/searx/utils.py b/searx/utils.py
index 744142e36..b3806d3fd 100644
--- a/searx/utils.py
+++ b/searx/utils.py
@@ -9,6 +9,7 @@ from HTMLParser import HTMLParser
from random import choice
from searx.version import VERSION_STRING
+from searx.languages import language_codes
from searx import settings
from searx import logger
@@ -255,3 +256,17 @@ def get_torrent_size(filesize, filesize_multiplier):
filesize = None
return filesize
+
+
+def is_valid_lang(lang):
+ is_abbr = (len(lang) == 2)
+ if is_abbr:
+ for l in language_codes:
+ if l[0][:2] == lang.lower():
+ return (True, l[0][:2], l[1].lower())
+ return False
+ else:
+ for l in language_codes:
+ if l[1].lower() == lang.lower():
+ return (True, l[0][:2], l[1].lower())
+ return False