def test_path_comments_are_relative_in_potfile(self):
        fshelpers.create_structure(
            self.tempdir, {"foo/foo/__init__.py": '_("Foo")', "foo/foo/locales/foo.pot": fshelpers.asset("empty.pot")}
        )

        potfile = (self.tempdir, "foo/foo/locales/foo.pot")
        self.assertEquals({}, pohelpers.messages(*potfile))
        rebuild_package_potfiles(self.tempdir, self.tempdir, "foo")
        self.assertEquals({"Foo": ["./foo/foo/__init__.py:1"]}, pohelpers.message_references(*potfile))
    def test_path_comments_are_relative_in_potfile(self):
        fshelpers.create_structure(self.tempdir, {
                'foo/foo/__init__.py': '_("Foo")',
                'foo/foo/locales/foo.pot': fshelpers.asset('empty.pot')})

        potfile = (self.tempdir, 'foo/foo/locales/foo.pot')
        self.assertEquals({}, pohelpers.messages(*potfile))
        synchronize(self.tempdir)
        self.assertEquals({'Foo': ['./foo/__init__.py:1']},
                          pohelpers.message_references(*potfile))
Exemplo n.º 3
0
    def test_path_comments_are_relative_in_potfile(self):
        fshelpers.create_structure(
            self.tempdir, {
                'foo/foo/__init__.py': '_("Foo")',
                'foo/foo/locales/foo.pot': fshelpers.asset('empty.pot')
            })

        potfile = (self.tempdir, 'foo/foo/locales/foo.pot')
        self.assertEquals({}, pohelpers.messages(*potfile))
        rebuild_package_potfiles(self.tempdir, self.tempdir, 'foo')
        self.assertEquals({'Foo': ['./foo/foo/__init__.py:1']},
                          pohelpers.message_references(*potfile))
    def test_path_comments_are_relative_in_pofile(self):
        fshelpers.create_structure(self.tempdir, {
                'foo/foo/__init__.py': '_("Foo")',
                'foo/foo/locales/foo.pot': fshelpers.asset('empty.pot'),
                'foo/foo/locales/de/LC_MESSAGES/foo.po': fshelpers.asset(
                    'empty.po'),
                })


        pofile = (self.tempdir, 'foo/foo/locales/de/LC_MESSAGES/foo.po')
        build_translations(self.tempdir, self.tempdir, 'foo', output=None)
        self.assertEquals({'Foo': ['./foo/foo/__init__.py:1']},
                          pohelpers.message_references(*pofile))
    def test_path_comments_are_relative_in_pofile(self):
        fshelpers.create_structure(
            self.tempdir, {
                'foo/foo/__init__.py':
                '_("Foo")',
                'foo/foo/locales/foo.pot':
                fshelpers.asset('empty.pot'),
                'foo/foo/locales/de/LC_MESSAGES/foo.po':
                fshelpers.asset('empty.po'),
            })

        pofile = (self.tempdir, 'foo/foo/locales/de/LC_MESSAGES/foo.po')
        build_translations(self.tempdir, self.tempdir, 'foo', output=None)
        self.assertEquals({'Foo': ['./foo/foo/__init__.py:1']},
                          pohelpers.message_references(*pofile))
    def test_updating_translations(self):
        self.write('buildout.cfg', BUILDOUT_CONFIG)
        self.system(self.buildout)

        package = 'the/package'
        locales = (package, 'locales')
        locales_de = (locales, 'de/LC_MESSAGES')
        locales_en = (locales, 'en/LC_MESSAGES')
        profile = (package, 'profiles/default')

        fshelpers.create_structure(self.sample_buildout, {
                (locales, 'package.pot'): fshelpers.asset('empty.pot'),
                (locales, 'package-manual.pot'): pohelpers.makepo({
                        'label_login': ('Login', '')}),
                (locales, 'plone.pot'): pohelpers.makepo({
                        'save': ('Save', '')}),
                (locales_de, 'package.po'): (
                    fshelpers.asset('empty.po')),
                (locales_en, 'plone.po'): (
                    fshelpers.asset('empty.po')),

                (package, '__init__.py'): '_("Foo")',
                (profile, 'content_creation/01.json'): json.dumps([
                        {'title:translate(package)': 'ContentPage'}])})

        output = self.system(self.i18n_build + ' de')

        try:
            # pot file building
            self.assertDictContainsSubset(
                {u'label_login': u''},
                pohelpers.messages(locales, 'package.pot'),
                'package-manual.pot was not merged')

            self.assertDictContainsSubset(
                {u'Foo': u''},
                pohelpers.messages(locales, 'package.pot'),
                'Package was not scanned, python file translation missing.')

            self.assertDictContainsSubset(
                {u'ContentPage': u''},
                pohelpers.messages(locales, 'package.pot'),
                'Inflater content creation was not scanned.')

            # po syncing
            self.assertEquals({u'label_login': u'',
                               u'Foo': u'',
                               u'ContentPage': u''},
                              pohelpers.messages(locales_de, 'package.po'),
                              'Default domain ("package") .po-file was not synced.')

            self.assertEquals({u'save': u''},
                              pohelpers.messages(locales_de, 'plone.po'),
                              'Alternate domain ("plone") .po-file was not synced.')

            self.assertEquals({u'save': u''},
                              pohelpers.messages(locales_en, 'plone.po'),
                              'Existing language was not synced.')

            lines = fshelpers.cat(locales_de, 'package.po').split('\n')
            self.assertEquals(
                [],
                filter(lambda line: line.startswith('"Domain'), lines),
                '.po-files should not contain Domain-headers, because'
                ' they are not relevant and often not set correctly.')

            # path comments
            self.assertDictContainsSubset(
                {u'Foo': [u'./the/package/__init__.py:1']},
                pohelpers.message_references(locales, 'package.pot'),
                'Path comments are wrong.')

        except:
            print '-' * 30
            print output
            print '-' * 30
            raise
Exemplo n.º 7
0
    def test_updating_translations(self):
        self.write('buildout.cfg', BUILDOUT_CONFIG)
        self.system(self.buildout)

        package = 'the/package'
        locales = (package, 'locales')
        locales_de = (locales, 'de/LC_MESSAGES')
        locales_en = (locales, 'en/LC_MESSAGES')
        profile = (package, 'profiles/default')

        fshelpers.create_structure(
            self.sample_buildout, {
                (locales, 'package.pot'):
                fshelpers.asset('empty.pot'),
                (locales, 'package-manual.pot'):
                pohelpers.makepo({'label_login': ('Login', '')}),
                (locales, 'plone.pot'):
                pohelpers.makepo({'save': ('Save', '')}),
                (locales_de, 'package.po'): (fshelpers.asset('empty.po')),
                (locales_en, 'plone.po'): (fshelpers.asset('empty.po')),
                (package, '__init__.py'):
                '_("Foo")',
                (profile, 'content_creation/01.json'):
                json.dumps([{
                    'title:translate(package)': 'ContentPage'
                }])
            })

        output = self.system(self.i18n_build + ' de')

        try:
            # pot file building
            self.assertDictContainsSubset({u'label_login': u''},
                                          pohelpers.messages(
                                              locales, 'package.pot'),
                                          'package-manual.pot was not merged')

            self.assertDictContainsSubset(
                {u'Foo': u''}, pohelpers.messages(locales, 'package.pot'),
                'Package was not scanned, python file translation missing.')

            self.assertDictContainsSubset(
                {u'ContentPage': u''},
                pohelpers.messages(locales, 'package.pot'),
                'Inflater content creation was not scanned.')

            # po syncing
            self.assertEquals(
                {
                    u'label_login': u'',
                    u'Foo': u'',
                    u'ContentPage': u''
                }, pohelpers.messages(locales_de, 'package.po'),
                'Default domain ("package") .po-file was not synced.')

            self.assertEquals(
                {u'save': u''}, pohelpers.messages(locales_de, 'plone.po'),
                'Alternate domain ("plone") .po-file was not synced.')

            self.assertEquals({u'save': u''},
                              pohelpers.messages(locales_en, 'plone.po'),
                              'Existing language was not synced.')

            lines = fshelpers.cat(locales_de, 'package.po').split('\n')
            self.assertEquals(
                [], filter(lambda line: line.startswith('"Domain'), lines),
                '.po-files should not contain Domain-headers, because'
                ' they are not relevant and often not set correctly.')

            # path comments
            self.assertDictContainsSubset(
                {u'Foo': [u'./the/package/__init__.py:1']},
                pohelpers.message_references(locales, 'package.pot'),
                'Path comments are wrong.')

        except:
            print '-' * 30
            print output
            print '-' * 30
            raise