Exemple #1
0
    def test_domain_get(self):
        translation.add_domain('foo', self._localedir('locale1'))
        translation.add_domain('bar', self._localedir('locale1'))
        translation.set_language(('es', ))

        d_foo = translation.get_domain('foo')
        self.assertEqual(d_foo.gettext('test'), 'Español')
        d_bar = translation.get_domain('bar')
        self.assertEqual(d_bar.gettext('test'), 'Español-bar')
Exemple #2
0
    def test_domain_get(self):
        translation.add_domain('foo', self._localedir('locale1'))
        translation.add_domain('bar', self._localedir('locale1'))
        translation.set_language(('es',))

        d_foo = translation.get_domain('foo')
        self.assertEqual(d_foo.gettext('test'), 'Español')
        d_bar = translation.get_domain('bar')
        self.assertEqual(d_bar.gettext('test'), 'Español-bar')
Exemple #3
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')
Exemple #4
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')