Ejemplo n.º 1
0
    def test_thread_local(self):
        translation.add_domain('foo', self._localedir('locale1'))
        self.assertEqual(translation.gettext('test'), 'test')
        self.assertEqual(translation.gettext('test4'), 'test4')
        translation.set_language(('es',))
        self.assertEqual(translation.gettext('test'), 'Español')
        self.assertEqual(translation.gettext('test4'), 'paella')
        translation.set_language_current_thread(('de',))
        self.assertEqual(translation.gettext('test'), 'groß')
        self.assertEqual(translation.gettext('test4'), 'freundleben')

        translation.reset()
        translation.add_domain('foo', self._localedir('locale1'))
        self.assertEqual(translation.gettext('test'), 'test')
        self.assertEqual(translation.gettext('test4'), 'test4')
        t = translation.gettext_lazy('test')
        self.assertEqual(t, 'test')
        current = [('es',)]
        def lang():
            return current[0]
        translation.set_language_current_thread(lang)
        self.assertEqual(t, 'Español')
        self.assertEqual(translation.gettext('test'), 'Español')
        self.assertEqual(translation.gettext('test4'), 'paella')
        current[0] = ('de',)
        self.assertEqual(t, 'groß')
        self.assertEqual(translation.gettext('test'), 'groß')
        self.assertEqual(translation.gettext('test4'), 'freundleben')
Ejemplo n.º 2
0
    def test_thread_local(self):
        translation.add_domain('foo', self._localedir('locale1'))
        self.assertEqual(translation.gettext('test'), 'test')
        self.assertEqual(translation.gettext('test4'), 'test4')
        translation.set_language(('es', ))
        self.assertEqual(translation.gettext('test'), 'Español')
        self.assertEqual(translation.gettext('test4'), 'paella')
        translation.set_language_current_thread(('de', ))
        self.assertEqual(translation.gettext('test'), 'groß')
        self.assertEqual(translation.gettext('test4'), 'freundleben')

        translation.reset()
        translation.add_domain('foo', self._localedir('locale1'))
        self.assertEqual(translation.gettext('test'), 'test')
        self.assertEqual(translation.gettext('test4'), 'test4')
        t = translation.gettext_lazy('test')
        self.assertEqual(t, 'test')
        current = [('es', )]

        def lang():
            return current[0]

        translation.set_language_current_thread(lang)
        self.assertEqual(t, 'Español')
        self.assertEqual(translation.gettext('test'), 'Español')
        self.assertEqual(translation.gettext('test4'), 'paella')
        current[0] = ('de', )
        self.assertEqual(t, 'groß')
        self.assertEqual(translation.gettext('test'), 'groß')
        self.assertEqual(translation.gettext('test4'), 'freundleben')
Ejemplo n.º 3
0
    def test_catalog_update(self):
        translation.add_domain('foo', self._localedir('locale1'))
        translation.set_language(('en', ))
        self.assertEqual(translation.gettext('test'), 'test')
        self.assertEqual(translation.gettext('test4'), 'oddball')

        translation.add_domain('foo', self._localedir('locale2'))
        self.assertEqual(translation.gettext('test'), 'test')
        self.assertEqual(translation.gettext('test1'), 'test1')
        self.assertEqual(translation.gettext('test2'), '2-test2')
        self.assertEqual(translation.gettext('test3'), 'test3')
        self.assertEqual(translation.gettext('asdf1'), '2-asdf1')
        self.assertEqual(translation.gettext('asdf2'), '2-asdf2')
        self.assertEqual(translation.gettext('test4'), 'oddball')
        self.assertEqual(translation.gettext('test5'), 'test5')

        translation.reset()
        translation.add_domain('foo', self._localedir('locale2'))
        translation.set_language(('en', ))
        self.assertEqual(translation.gettext('test'), '2-test')
        self.assertEqual(translation.gettext('test1'), '2-test1')
        self.assertEqual(translation.gettext('test2'), '2-test2')
        self.assertEqual(translation.gettext('test3'), '2-test3')
        self.assertEqual(translation.gettext('asdf1'), '2-asdf1')
        self.assertEqual(translation.gettext('asdf2'), '2-asdf2')
        self.assertEqual(translation.gettext('test4'), 'test4')
        self.assertEqual(translation.gettext('test5'), 'test5')

        translation.add_domain('foo', self._localedir('locale1'))
        self.assertEqual(translation.gettext('test'), '2-test')
        self.assertEqual(translation.gettext('test1'), '2-test1')
        self.assertEqual(translation.gettext('test2'), '2-test2')
        self.assertEqual(translation.gettext('test3'), '2-test3')
        self.assertEqual(translation.gettext('asdf1'), '2-asdf1')
        self.assertEqual(translation.gettext('asdf2'), '2-asdf2')
        self.assertEqual(translation.gettext('test4'), 'oddball')
        self.assertEqual(translation.gettext('test5'), 'test5')

        # Make something that updates.
        translation.reset()
        translation.set_language(('en', ))
        path = os.path.join(os.getcwd(), 'translation', 'locale-dynamic',
                            'en_US', 'LC_MESSAGES')
        target = os.path.join(path, 'foo.mo')
        if os.path.exists(target):
            os.unlink(target)
        os.symlink(os.path.join(path, 'foo1.mo'), target)
        translation.add_domain('foo', self._localedir('locale-dynamic'))
        self.assertEqual(translation.gettext('test'), 'test-dyn1')
        os.unlink(target)
        os.symlink(os.path.join(path, 'foo2.mo'), target)
        translation.add_domain('foo', self._localedir('locale-dynamic'))
        self.assertEqual(translation.gettext('test'), 'test-dyn2')
Ejemplo n.º 4
0
    def test_catalog_update(self):
        translation.add_domain('foo', self._localedir('locale1'))
        translation.set_language(('en',))
        self.assertEqual(translation.gettext('test'), 'test')
        self.assertEqual(translation.gettext('test4'), 'oddball')

        translation.add_domain('foo', self._localedir('locale2'))
        self.assertEqual(translation.gettext('test'), 'test')
        self.assertEqual(translation.gettext('test1'), 'test1')
        self.assertEqual(translation.gettext('test2'), '2-test2')
        self.assertEqual(translation.gettext('test3'), 'test3')
        self.assertEqual(translation.gettext('asdf1'), '2-asdf1')
        self.assertEqual(translation.gettext('asdf2'), '2-asdf2')
        self.assertEqual(translation.gettext('test4'), 'oddball')
        self.assertEqual(translation.gettext('test5'), 'test5')

        translation.reset()
        translation.add_domain('foo', self._localedir('locale2'))
        translation.set_language(('en',))
        self.assertEqual(translation.gettext('test'), '2-test')
        self.assertEqual(translation.gettext('test1'), '2-test1')
        self.assertEqual(translation.gettext('test2'), '2-test2')
        self.assertEqual(translation.gettext('test3'), '2-test3')
        self.assertEqual(translation.gettext('asdf1'), '2-asdf1')
        self.assertEqual(translation.gettext('asdf2'), '2-asdf2')
        self.assertEqual(translation.gettext('test4'), 'test4')
        self.assertEqual(translation.gettext('test5'), 'test5')

        translation.add_domain('foo', self._localedir('locale1'))
        self.assertEqual(translation.gettext('test'), '2-test')
        self.assertEqual(translation.gettext('test1'), '2-test1')
        self.assertEqual(translation.gettext('test2'), '2-test2')
        self.assertEqual(translation.gettext('test3'), '2-test3')
        self.assertEqual(translation.gettext('asdf1'), '2-asdf1')
        self.assertEqual(translation.gettext('asdf2'), '2-asdf2')
        self.assertEqual(translation.gettext('test4'), 'oddball')
        self.assertEqual(translation.gettext('test5'), 'test5')

        # Make something that updates.
        translation.reset()
        translation.set_language(('en',))
        path = os.path.join(os.getcwd(), 'translation', 'locale-dynamic', 'en_US', 'LC_MESSAGES')
        target = os.path.join(path, 'foo.mo')
        if os.path.exists(target):
            os.unlink(target)
        os.symlink(os.path.join(path, 'foo1.mo'), target)
        translation.add_domain('foo', self._localedir('locale-dynamic'))
        self.assertEqual(translation.gettext('test'), 'test-dyn1')
        os.unlink(target)
        os.symlink(os.path.join(path, 'foo2.mo'), target)
        translation.add_domain('foo', self._localedir('locale-dynamic'))
        self.assertEqual(translation.gettext('test'), 'test-dyn2')
Ejemplo n.º 5
0
    def test_refresh(self):
        for check_timestamps in (True, False):
            translation.reset()
            lazy = translation.gettext_lazy('test')
            self.assertEqual(str(lazy), 'test')
            self.assertEqual(translation.gettext('test'), 'test')

            translation.set_language(('en', ))
            path = os.path.join(os.getcwd(), 'translation', 'locale-dynamic',
                                'en_US', 'LC_MESSAGES')
            target = os.path.join(path, 'foo.mo')
            if os.path.exists(target):
                os.unlink(target)

            shutil.copyfile(os.path.join(path, 'foo1.mo'), target)
            # Make sure timestamps are different.
            t = time.time()
            os.utime(target, (t - 120, t - 120))
            translation.add_domain('foo', self._localedir('locale-dynamic'))

            self.assertEqual(str(lazy), 'test-dyn1')
            self.assertEqual(translation.gettext('test'), 'test-dyn1')

            os.unlink(target)
            # Make sure timestamps are different.
            shutil.copyfile(os.path.join(path, 'foo2.mo'), target)
            os.utime(target, (t - 60, t - 60))
            translation.get_domain('foo').refresh(check_timestamps)
            self.assertEqual(str(lazy), 'test-dyn2')
            self.assertEqual(translation.gettext('test'), 'test-dyn2')

            os.unlink(target)
            # Make sure timestamps are different.
            shutil.copyfile(os.path.join(path, 'foo1.mo'), target)
            os.utime(target, (t - 30, t - 30))
            translation.get_domain('foo').refresh(check_timestamps)
            self.assertEqual(str(lazy), 'test-dyn1')
            self.assertEqual(translation.gettext('test'), 'test-dyn1')
Ejemplo n.º 6
0
    def test_refresh(self):
        for check_timestamps in (True, False):
            translation.reset()
            lazy = translation.gettext_lazy('test')
            self.assertEqual(str(lazy), 'test')
            self.assertEqual(translation.gettext('test'), 'test')

            translation.set_language(('en',))
            path = os.path.join(os.getcwd(), 'translation', 'locale-dynamic', 'en_US', 'LC_MESSAGES')
            target = os.path.join(path, 'foo.mo')
            if os.path.exists(target):
                os.unlink(target)

            shutil.copyfile(os.path.join(path, 'foo1.mo'), target)
            # Make sure timestamps are different.
            t = time.time()
            os.utime(target, (t-120, t-120))
            translation.add_domain('foo', self._localedir('locale-dynamic'))

            self.assertEqual(str(lazy), 'test-dyn1')
            self.assertEqual(translation.gettext('test'), 'test-dyn1')

            os.unlink(target)
            # Make sure timestamps are different.
            shutil.copyfile(os.path.join(path, 'foo2.mo'), target)
            os.utime(target, (t-60, t-60))
            translation.get_domain('foo').refresh(check_timestamps)
            self.assertEqual(str(lazy), 'test-dyn2')
            self.assertEqual(translation.gettext('test'), 'test-dyn2')

            os.unlink(target)
            # Make sure timestamps are different.
            shutil.copyfile(os.path.join(path, 'foo1.mo'), target)
            os.utime(target, (t-30, t-30))
            translation.get_domain('foo').refresh(check_timestamps)
            self.assertEqual(str(lazy), 'test-dyn1')
            self.assertEqual(translation.gettext('test'), 'test-dyn1')
Ejemplo n.º 7
0
 def setUp(self):
     translation.reset()
Ejemplo n.º 8
0
 def setUp(self):
     translation.reset()