[kupfer] plugin.google_translate: Fix regex parsing of languages



commit 0e04c5a5f1baeff3b19b1f9cc8eb10991c10fd67
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date:   Sat Nov 14 01:07:40 2009 +0100

    plugin.google_translate: Fix regex parsing of languages
    
    Fix regex so we parse lang codes and language names correctly.
    Previously, chinese were missing from the list, since the code
    includes a hyphen "-" and the name whitespace and parantethis like
    "Chinese (Simplified)".

 kupfer/plugin/google_translate.py |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)
---
diff --git a/kupfer/plugin/google_translate.py b/kupfer/plugin/google_translate.py
index 5618520..d094466 100644
--- a/kupfer/plugin/google_translate.py
+++ b/kupfer/plugin/google_translate.py
@@ -79,8 +79,10 @@ def _translate(text, lang):
 		conn.close()
 
 
-_RE_GET_LANG = re.compile(r'\<option[ \w]+value="(\w+)"\>(\w+)\</option\>', 
-		re.UNICODE|re.IGNORECASE)
+_RE_GET_LANG = re.compile(r"""\<option[ \w]+ value="([\w\-]+)"\> # code 'zh-TW'
+                              ([^<]+?)             # match localized lang name
+                              \</option\>
+                           """, re.UNICODE|re.IGNORECASE|re.VERBOSE)
 
 def _load_languages():
 	''' Load available languages from Google.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]