|
@@ -1,14 +1,19 @@
|
|
|
+# -*- coding: utf-8 -*-
|
|
|
+
|
|
|
import os
|
|
|
import shutil
|
|
|
import stat
|
|
|
import sys
|
|
|
import unittest
|
|
|
+import gettext as gettext_module
|
|
|
|
|
|
from django.core.management import call_command, CommandError, execute_from_command_line
|
|
|
from django.core.management.utils import find_command
|
|
|
from django.test import SimpleTestCase
|
|
|
from django.test import override_settings
|
|
|
from django.utils import translation
|
|
|
+from django.utils.translation import ugettext
|
|
|
+from django.utils.encoding import force_text
|
|
|
from django.utils._os import upath
|
|
|
from django.utils.six import StringIO
|
|
|
|
|
@@ -188,3 +193,28 @@ class CompilationErrorHandling(MessageCompilationTests):
|
|
|
def test_error_reported_by_msgfmt(self):
|
|
|
with self.assertRaises(CommandError):
|
|
|
call_command('compilemessages', locale=[self.LOCALE], stdout=StringIO())
|
|
|
+
|
|
|
+
|
|
|
+class FuzzyTranslationTest(MessageCompilationTests):
|
|
|
+
|
|
|
+ LOCALE = 'ru'
|
|
|
+ MO_FILE = 'locale/%s/LC_MESSAGES/django.mo' % LOCALE
|
|
|
+
|
|
|
+ def setUp(self):
|
|
|
+ super(FuzzyTranslationTest, self).setUp()
|
|
|
+ self.addCleanup(self.rmfile, os.path.join(self.test_dir, self.MO_FILE))
|
|
|
+ gettext_module._translations = {} # flush cache or test will be useless
|
|
|
+
|
|
|
+ def test_nofuzzy_compiling(self):
|
|
|
+ with override_settings(LOCALE_PATHS=(os.path.join(self.test_dir, 'locale'),)):
|
|
|
+ call_command('compilemessages', locale=[self.LOCALE], stdout=StringIO())
|
|
|
+ with translation.override(self.LOCALE):
|
|
|
+ self.assertEqual(ugettext('Lenin'), force_text('Ленин'))
|
|
|
+ self.assertEqual(ugettext('Vodka'), force_text('Vodka'))
|
|
|
+
|
|
|
+ def test_fuzzy_compiling(self):
|
|
|
+ with override_settings(LOCALE_PATHS=(os.path.join(self.test_dir, 'locale'),)):
|
|
|
+ call_command('compilemessages', locale=[self.LOCALE], fuzzy=True, stdout=StringIO())
|
|
|
+ with translation.override(self.LOCALE):
|
|
|
+ self.assertEqual(ugettext('Lenin'), force_text('Ленин'))
|
|
|
+ self.assertEqual(ugettext('Vodka'), force_text('Водка'))
|