diff --git a/.travis.yml b/.travis.yml index cc21fae8f..76434202e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,3 +17,7 @@ notifications: # channels: # - "irc.freenode.org#youtube-dl" # skip_join: true +addons: + apt: + packages: + - gettext diff --git a/Makefile b/Makefile index 3a390f0ce..728844ca0 100644 --- a/Makefile +++ b/Makefile @@ -36,14 +36,14 @@ install: youtube-dl youtube-dl.1 youtube-dl.bash-completion youtube-dl.zsh youtu codetest: flake8 . -test: +test: update-gmo #nosetests --with-coverage --cover-package=youtube_dl --cover-html --verbose --processes 4 test nosetests --verbose test $(MAKE) codetest ot: offlinetest -offlinetest: codetest +offlinetest: codetest update-gmo nosetests --verbose test --exclude test_download.py --exclude test_age_restriction.py --exclude test_subtitles.py --exclude test_write_annotations.py --exclude test_youtube_lists.py tar: youtube-dl.tar.gz diff --git a/test/test_utils.py b/test/test_utils.py index 501355c74..ae3cc66f2 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -30,6 +30,7 @@ from youtube_dl.utils import ( fix_xml_ampersands, InAdvancePagedList, intlist_to_bytes, + I18N, is_html, js_to_json, limit_length, @@ -746,6 +747,35 @@ The first line {'nocheckcertificate': False}, '--check-certificate', 'nocheckcertificate', 'false', 'true', '='), ['--check-certificate=true']) + def test_i18n(self): + old_locale = os.environ.get('LC_ALL') + if old_locale is not None: + del os.environ['LC_ALL'] + + instance = I18N() + instance.set_default_language('en_US') + self.assertEqual(instance.translate('Test URL: %s'), 'Test URL: %s') + + instance = I18N() + instance.set_default_language('zh_TW') + self.assertEqual(instance.translate('Test URL: %s'), '測試網址:%s') + + # A fake language code + instance = I18N() + instance.set_default_language('pp_QQ') + self.assertEqual(instance.translate('Test URL: %s'), 'Test URL: %s') + + # setting locale via environ is not applicable on Windows + if not sys.platform.startswith('win'): + os.environ['LC_ALL'] = 'zh_TW' + instance = I18N() + self.assertEqual(instance.translate('Test URL: %s'), '測試網址:%s') + + if old_locale is not None: + os.environ['LC_ALL'] = old_locale + else: + del os.environ['LC_ALL'] + if __name__ == '__main__': unittest.main()