browse: display errors when saving blobs
[git-cola.git] / test / i18n_test.py
blob1c458780b6a6faebb60a8df2b6741c59574df9e2
1 """Tests for the i18n translation module"""
2 from __future__ import absolute_import, division, print_function, unicode_literals
3 import os
5 import pytest
7 from cola import i18n
8 from cola.i18n import N_
9 from cola.compat import uchr
12 @pytest.fixture(autouse=True)
13 def i18n_context():
14 """Perform cleanup/teardown of the i18n module"""
15 yield
16 i18n.uninstall()
19 def test_translates_noun():
20 """Test that strings with @@noun are translated"""
21 i18n.install('ja_JP')
22 expect = uchr(0x30B3) + uchr(0x30DF) + uchr(0x30C3) + uchr(0x30C8)
23 actual = N_('Commit@@verb')
24 assert expect == actual
27 def test_translates_verb():
28 """Test that strings with @@verb are translated"""
29 i18n.install('de_DE')
30 expect = 'Commit aufnehmen'
31 actual = N_('Commit@@verb')
32 assert expect == actual
35 def test_translates_english_noun():
36 """Test that English strings with @@noun are properly handled"""
37 i18n.install('en_US.UTF-8')
38 expect = 'Commit'
39 actual = N_('Commit@@noun')
40 assert expect == actual
43 def test_translates_english_verb():
44 """Test that English strings with @@verb are properly handled"""
45 i18n.install('en_US.UTF-8')
46 expect = 'Commit'
47 actual = N_('Commit@@verb')
48 assert expect == actual
51 def test_translates_random_english():
52 """Test that random English strings are passed through as-is"""
53 i18n.install('en_US.UTF-8')
54 expect = 'Random'
55 actual = N_('Random')
56 assert expect == actual
59 def test_translate_push_pull_french():
60 i18n.install('fr_FR')
61 expect = 'Tirer'
62 actual = N_('Pull')
63 assert expect == actual
65 expect = 'Pousser'
66 actual = N_('Push')
67 assert expect == actual
70 def test_get_filename_for_locale():
71 """Ensure that the appropriate .po files are found"""
72 actual = i18n.get_filename_for_locale('does_not_exist')
73 assert actual is None
75 actual = i18n.get_filename_for_locale('id_ID')
76 assert os.path.basename(actual) == 'id_ID.po'
78 actual = i18n.get_filename_for_locale('ja_JP')
79 assert os.path.basename(actual) == 'ja.po'