Skip to content

Commit

Permalink
fix lang detection behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
mogproject committed Sep 1, 2015
1 parent 3d7e3d0 commit 198501c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
5 changes: 2 additions & 3 deletions src/easy_menu/setting/setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,8 @@ def _find_lang(lang):
if not lang:
# environment LANG is the first priority
lang = os.environ.get('LANG')
if lang:
return lang.lower()
return locale.getdefaultlocale()[0].lower()
if not lang:
lang = locale.getdefaultlocale()[0]
return lang

@staticmethod
Expand Down
2 changes: 1 addition & 1 deletion src/easy_menu/view/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def _find_encoding(encoding, output):
def _find_i18n(lang):
if not lang:
return i18n.messages_en
elif lang.startswith('ja'):
elif lang.lower().startswith('ja'):
return i18n.messages_ja
else:
return i18n.messages_en
Expand Down
13 changes: 13 additions & 0 deletions tests/easy_menu/setting/test_setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,19 @@ def test_init(self):
self.assertEqual(s5.work_dir, '/tmp')
self.assertEqual(s5.root_menu, {})

def test_find_lang(self):
s = Setting()
old = os.environ['LANG']

del os.environ['LANG']
self.assertEqual(s._find_lang('ja_JP'), 'ja_JP')
s._find_lang(None).islower() # return value depends on the system

os.environ['LANG'] = 'en_US'
self.assertEqual(s._find_lang(None), 'en_US')

os.environ['LANG'] = old

def test_is_url(self):
self.assertEqual(Setting()._is_url('http://example.com/foo.yml'), True)
self.assertEqual(Setting()._is_url('https://example.com/foo.yml'), True)
Expand Down

0 comments on commit 198501c

Please sign in to comment.