You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@joshua.apache.org by mj...@apache.org on 2017/01/31 01:43:51 UTC
[2/2] incubator-joshua git commit: added check to see if iso-639
module installed
added check to see if iso-639 module installed
Project: http://git-wip-us.apache.org/repos/asf/incubator-joshua/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-joshua/commit/f92b1ee2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-joshua/tree/f92b1ee2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-joshua/diff/f92b1ee2
Branch: refs/heads/master
Commit: f92b1ee246c51c02e2ca0a4de86ca8092306ed6c
Parents: f4c2441
Author: Matt Post <po...@cs.jhu.edu>
Authored: Mon Jan 30 20:43:41 2017 -0500
Committer: Matt Post <po...@cs.jhu.edu>
Committed: Mon Jan 30 20:43:41 2017 -0500
----------------------------------------------------------------------
scripts/misc/iso639 | 59 ++++++++++++++++++++++++++++++++++++++----------
1 file changed, 47 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/f92b1ee2/scripts/misc/iso639
----------------------------------------------------------------------
diff --git a/scripts/misc/iso639 b/scripts/misc/iso639
index 8625754..e80b31c 100755
--- a/scripts/misc/iso639
+++ b/scripts/misc/iso639
@@ -39,21 +39,56 @@ Here is some example usage of that module:
"""
import sys
-import iso639
if len(sys.argv) != 2:
- print "Usage: iso639 LANG"
- print "where LANG is a language name or abbreviation."
- sys.exit(1)
+ print "Usage: iso639 LANG"
+ print "where LANG is a language name or abbreviation."
+ sys.exit(1)
+
+# Common manual mappings in order to avoid the potentially
+# not present iso639 module
+quickdict = {
+ 'English': 'en',
+ 'en': 'English',
+ 'Spanish': 'es',
+ 'es': 'Spanish',
+ 'Hebrew': 'he',
+ 'he': 'Hebrew',
+ 'German': 'de',
+ 'de': 'German',
+ 'French': 'fr',
+ 'fr': 'French',
+ 'Arabic': 'ar',
+ 'ar': 'Arabic',
+ 'Czech': 'cs',
+ 'cs': 'Czech',
+ 'Romanian': 'ro',
+ 'ro': 'Romanian',
+}
input = sys.argv[1]
-if len(input) == 2:
- lang = iso639.languages.get(part1 = input)
- print lang.name
-elif len(input) == 3:
- lang = iso639.languages.get(part3 = input)
- print lang.name
+if quickdict.has_key(input):
+ print quickdict[input]
+
else:
- lang = iso639.languages.get(name = input)
- print lang.part1
+ # Only load this if we have to
+
+ try:
+ import iso639
+
+ if len(input) == 2:
+ lang = iso639.languages.get(part1 = input)
+ print lang.name
+ elif len(input) == 3:
+ lang = iso639.languages.get(part3 = input)
+ print lang.name
+ else:
+ lang = iso639.languages.get(name = input)
+ print lang.part1
+
+ except ImportError:
+ sys.stderr.write('Can\'t load module iso639 ("pip install --user iso-639")\n')
+
+ except KeyError:
+ sys.stderr.write('Language not found: {}\n'.format(input))