예제 #1
0
    def test_only_selected_languages_are_synced(self):
        fshelpers.create_structure(self.tempdir, {
                'foo/bar/locales/bar.pot': fshelpers.asset('empty.pot'),
                'foo/bar/locales/de/LC_MESSAGES/bar.po': pohelpers.makepo({
                        'label_login': ('Login', 'de original')}),
                'foo/bar/locales/fr/LC_MESSAGES/bar.po': pohelpers.makepo({
                        'label_login': ('Login', 'fr original')})})
        de_pofile = (self.tempdir, 'foo/bar/locales/de/LC_MESSAGES/bar.po')
        fr_pofile = (self.tempdir, 'foo/bar/locales/fr/LC_MESSAGES/bar.po')

        spreadsheet = SpreadSheetMock(
            {'worksheet': [{'package': u'foo',
                            'domain': u'bar',
                            'id': u'label_login',
                            'default': u'Login',
                            'translations': {u'de': u'Anmelden',
                                             u'fr': u'Connecter'},
                            }]})
        download.download(spreadsheet, self.tempdir,
                          worksheet_name='worksheet',
                          languages=['de'])

        self.assertEquals({'label_login': '******'},
                          pohelpers.messages(*de_pofile))
        self.assertEquals({'label_login': '******'},
                          pohelpers.messages(*fr_pofile))
    def test_download(self):
        fshelpers.create_structure(self.tempdir, {
                'foo/bar/locales/bar.pot': fshelpers.asset('empty.pot'),
                'foo/bar/locales/de/LC_MESSAGES/bar.po': pohelpers.makepo({
                        'label_login': ('Login', '')})})
        pofile = (self.tempdir, 'foo/bar/locales/de/LC_MESSAGES/bar.po')

        self.assertEquals({'label_login': ''},
                          pohelpers.messages(*pofile))

        spreadsheet = SpreadSheetMock(
            {'worksheet': [{'package': u'foo',
                            'domain': u'bar',
                            'id': u'label_login',
                            'default': u'Login',
                            'translations': {u'de': u'Anmelden'},
                            },
                           {'package': u'foo',
                            'domain': u'bar',
                            'id': u'this_was_removed',
                            'default': u'Yay',
                            'translations': {u'de': u'Yay'},
                            }]})
        download.download(spreadsheet, self.tempdir,
                          worksheet_name='worksheet',
                          languages=['de'])

        self.assertEquals({'label_login': '******'},
                          pohelpers.messages(*pofile))
    def test_rebuilds_primary_domain_pot_files(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))
        build_translations(self.tempdir, self.tempdir, 'foo', output=None)
        self.assertEquals({'Foo': ''}, pohelpers.messages(*potfile))
    def test_does_not_rebuild_secondary_domain_pot_files(self):
        fshelpers.create_structure(self.tempdir, {
                'foo/foo/__init__.py': '_("Foo")',
                'foo/foo/locales/bar.pot': fshelpers.asset('empty.pot')})

        potfile = (self.tempdir, 'foo/foo/locales/bar.pot')
        self.assertEquals({}, pohelpers.messages(*potfile))
        synchronize(self.tempdir)
        self.assertEquals({}, pohelpers.messages(*potfile))
    def test_does_not_rebuild_secondary_domain_pot_files(self):
        fshelpers.create_structure(
            self.tempdir, {"foo/foo/__init__.py": '_("Foo")', "foo/foo/locales/bar.pot": fshelpers.asset("empty.pot")}
        )

        potfile = (self.tempdir, "foo/foo/locales/bar.pot")
        self.assertEquals({}, pohelpers.messages(*potfile))
        rebuild_package_potfiles(self.tempdir, self.tempdir, "foo")
        self.assertEquals({}, pohelpers.messages(*potfile))
    def test_rebuilds_primary_domain_pot_files(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))
        build_translations(self.tempdir, self.tempdir, 'foo', output=None)
        self.assertEquals({'Foo': ''}, pohelpers.messages(*potfile))
예제 #7
0
    def test_does_not_rebuild_secondary_domain_pot_files(self):
        fshelpers.create_structure(
            self.tempdir, {
                'foo/foo/__init__.py': '_("Foo")',
                'foo/foo/locales/bar.pot': fshelpers.asset('empty.pot')
            })

        potfile = (self.tempdir, 'foo/foo/locales/bar.pot')
        self.assertEquals({}, pohelpers.messages(*potfile))
        rebuild_package_potfiles(self.tempdir, self.tempdir, 'foo')
        self.assertEquals({}, pohelpers.messages(*potfile))
예제 #8
0
    def test_does_not_include_messages_outside_of_package_dir(self):
        fshelpers.create_structure(
            self.tempdir, {
                'foo/foo/__init__.py': '_("Foo")',
                'foo/foo/locales/foo.pot': fshelpers.asset('empty.pot'),
                'src/bar/__init__.py': '_("Bar")'
            })

        package_dir = os.path.join(self.tempdir, 'foo')
        potfile = (self.tempdir, 'foo/foo/locales/foo.pot')
        rebuild_package_potfiles(self.tempdir, package_dir, 'foo')
        self.assertNotIn(
            'Bar', pohelpers.messages(*potfile),
            'Messages from sub-checkouts should not be included.')
        self.assertEquals({'Foo': ''}, pohelpers.messages(*potfile),
                          'Expected translations in package to be discovered.')
    def test_does_not_include_messages_outside_of_package_dir(self):
        fshelpers.create_structure(
            self.tempdir,
            {
                "foo/foo/__init__.py": '_("Foo")',
                "foo/foo/locales/foo.pot": fshelpers.asset("empty.pot"),
                "src/bar/__init__.py": '_("Bar")',
            },
        )

        package_dir = os.path.join(self.tempdir, "foo")
        potfile = (self.tempdir, "foo/foo/locales/foo.pot")
        rebuild_package_potfiles(self.tempdir, package_dir, "foo")
        self.assertNotIn("Bar", pohelpers.messages(*potfile), "Messages from sub-checkouts should not be included.")
        self.assertEquals(
            {"Foo": ""}, pohelpers.messages(*potfile), "Expected translations in package to be discovered."
        )
    def test_syncs_only_selected_languages(self):
        fshelpers.create_structure(self.tempdir, {
                'foo/foo/locales/bar.pot': fshelpers.asset('foo.pot'),
                'foo/foo/locales/en/LC_MESSAGES/bar.po': fshelpers.asset(
                    'empty.po'),
                'foo/foo/locales/de/LC_MESSAGES/bar.po': fshelpers.asset(
                    'empty.po'),
                })

        en = (self.tempdir, 'foo/foo/locales/en/LC_MESSAGES/bar.po')
        de = (self.tempdir, 'foo/foo/locales/de/LC_MESSAGES/bar.po')
        self.assertEquals({}, pohelpers.messages(*en))
        self.assertEquals({}, pohelpers.messages(*de))

        synchronize(self.tempdir, languages=['en'], output=None)

        self.assertEquals({'Login': ''}, pohelpers.messages(*en))
        self.assertEquals({}, pohelpers.messages(*de))
    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_syncs_po_files_of_existing_languages(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')
        self.assertEquals({}, pohelpers.messages(*pofile))

        output = StringIO()
        synchronize(self.tempdir, output=output)

        self.assertEquals({'Foo': ''}, pohelpers.messages(*pofile))
        self.assertRegexpMatches(output.getvalue(),
                                 r'\/foo.po: 1 added, 0 removed')
    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))
    def test_syncs_only_selected_languages(self):
        fshelpers.create_structure(
            self.tempdir, {
                'foo/foo/locales/bar.pot':
                fshelpers.asset('foo.pot'),
                'foo/foo/locales/en/LC_MESSAGES/bar.po':
                fshelpers.asset('empty.po'),
                'foo/foo/locales/de/LC_MESSAGES/bar.po':
                fshelpers.asset('empty.po'),
            })

        en = (self.tempdir, 'foo/foo/locales/en/LC_MESSAGES/bar.po')
        de = (self.tempdir, 'foo/foo/locales/de/LC_MESSAGES/bar.po')
        self.assertEquals({}, pohelpers.messages(*en))
        self.assertEquals({}, pohelpers.messages(*de))

        synchronize(self.tempdir, languages=['en'], output=None)

        self.assertEquals({'Login': ''}, pohelpers.messages(*en))
        self.assertEquals({}, pohelpers.messages(*de))
    def test_syncs_po_files_of_existing_languages(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')
        self.assertEquals({}, pohelpers.messages(*pofile))

        output = StringIO()
        build_translations(self.tempdir, self.tempdir, 'foo', output=output)

        self.assertEquals({'Foo': ''}, pohelpers.messages(*pofile))
        self.assertRegexpMatches(output.getvalue(),
                                 r'\/foo.po: 1 added, 0 removed')
예제 #16
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_merges_content_pot_files(self):
        fshelpers.create_structure(
            self.tempdir,
            {
                "foo/foo/__init__.py": '_("Foo")',
                "foo/foo/locales/foo.pot": fshelpers.asset("empty.pot"),
                "foo/foo/locales/foo-content.pot": fshelpers.asset("foo.pot"),
            },
        )

        rebuild_package_potfiles(self.tempdir, self.tempdir, "foo")
        pofile = (self.tempdir, "foo/foo/locales/foo.pot")
        self.assertEquals({"Foo": "", "Login": ""}, pohelpers.messages(*pofile))
    def test_extract_messages(self):
        potfile = os.path.join(self.tempdir, "somedir", "inflator.pot")
        fshelpers.create_structure(
            self.tempdir,
            {"foo/foo/profiles/default/content_creation/content.json": fshelpers.asset("translated_content.json")},
        )
        self.assertFalse(os.path.exists(os.path.dirname(potfile)))

        rebuild_pot(potfile, self.profiles_dir, self.domain)

        self.assertTrue(os.path.exists(os.path.dirname(potfile)))
        messages = pohelpers.messages(potfile)
        self.assertTrue(os.path.exists(potfile))
        self.assertIn("Foo", messages)
예제 #19
0
    def test_merges_content_pot_files(self):
        fshelpers.create_structure(
            self.tempdir, {
                'foo/foo/__init__.py': '_("Foo")',
                'foo/foo/locales/foo.pot': fshelpers.asset('empty.pot'),
                'foo/foo/locales/foo-content.pot': fshelpers.asset('foo.pot'),
            })

        rebuild_package_potfiles(self.tempdir, self.tempdir, 'foo')
        pofile = (self.tempdir, 'foo/foo/locales/foo.pot')
        self.assertEquals({
            'Foo': '',
            'Login': ''
        }, pohelpers.messages(*pofile))
    def test_merges_content_pot_files(self):
        fshelpers.create_structure(self.tempdir, {
                'foo/foo/__init__.py': '_("Foo")',
                'foo/foo/locales/foo.pot': fshelpers.asset('empty.pot'),
                'foo/foo/locales/foo-content.pot': fshelpers.asset(
                    'foo.pot'),
                'foo/foo/locales/de/LC_MESSAGES/foo.po': fshelpers.asset(
                    'empty.po'),
                })

        build_translations(self.tempdir, self.tempdir, 'foo', output=None)
        pofile = (self.tempdir, 'foo/foo/locales/de/LC_MESSAGES/foo.po')
        self.assertEquals({'Foo': '',
                           'Login': ''}, pohelpers.messages(*pofile))
    def test_merges_manual_pot_files(self):
        fshelpers.create_structure(self.tempdir, {
                'foo/foo/__init__.py': '_("Foo")',
                'foo/foo/locales/foo.pot': fshelpers.asset('empty.pot'),
                'foo/foo/locales/foo-manual.pot': fshelpers.asset(
                    'foo.pot'),
                'foo/foo/locales/de/LC_MESSAGES/foo.po': fshelpers.asset(
                    'empty.po'),
                })

        synchronize(self.tempdir, output=None)
        pofile = (self.tempdir, 'foo/foo/locales/de/LC_MESSAGES/foo.po')
        self.assertEquals({'Foo': '',
                           'Login': ''}, pohelpers.messages(*pofile))
예제 #22
0
    def test_extract_messages(self):
        potfile = os.path.join(self.tempdir, 'somedir', 'inflator.pot')
        fshelpers.create_structure(self.tempdir, {
                'foo/foo/profiles/default/content_creation/content.json':
                        fshelpers.asset('translated_content.json'),
                    })
        self.assertFalse(os.path.exists(os.path.dirname(potfile)))

        rebuild_pot(potfile, self.profiles_dir, self.domain)

        self.assertTrue(os.path.exists(os.path.dirname(potfile)))
        messages = pohelpers.messages(potfile)
        self.assertTrue(os.path.exists(potfile))
        self.assertIn('Foo', messages)
    def test_creates_selected_languages_when_missing(self):
        fshelpers.create_structure(self.tempdir, {
                'foo/foo/locales/bar.pot': fshelpers.asset('foo.pot')})

        enpath = os.path.join(self.tempdir,
                              'foo/foo/locales/en/LC_MESSAGES/bar.po')

        synchronize(self.tempdir, output=None)
        self.assertFalse(os.path.exists(enpath),
                         'A sync without selecting languages should'
                         ' not create new languages.')

        synchronize(self.tempdir, languages=['en'], output=None)
        self.assertTrue(os.path.exists(enpath),
                        'A sync with selecting languages should'
                        ' create missing languages.')

        self.assertEquals({'Login': ''}, pohelpers.messages(enpath))
    def test_creates_selected_languages_when_missing(self):
        fshelpers.create_structure(
            self.tempdir,
            {'foo/foo/locales/bar.pot': fshelpers.asset('foo.pot')})

        enpath = os.path.join(self.tempdir,
                              'foo/foo/locales/en/LC_MESSAGES/bar.po')

        synchronize(self.tempdir, output=None)
        self.assertFalse(
            os.path.exists(enpath), 'A sync without selecting languages should'
            ' not create new languages.')

        synchronize(self.tempdir, languages=['en'], output=None)
        self.assertTrue(
            os.path.exists(enpath), 'A sync with selecting languages should'
            ' create missing languages.')

        self.assertEquals({'Login': ''}, pohelpers.messages(enpath))
    def test_merges_manual_pot_files(self):
        fshelpers.create_structure(
            self.tempdir, {
                'foo/foo/__init__.py':
                '_("Foo")',
                'foo/foo/locales/foo.pot':
                fshelpers.asset('empty.pot'),
                'foo/foo/locales/foo-manual.pot':
                fshelpers.asset('foo.pot'),
                'foo/foo/locales/de/LC_MESSAGES/foo.po':
                fshelpers.asset('empty.po'),
            })

        synchronize(self.tempdir, output=None)
        pofile = (self.tempdir, 'foo/foo/locales/de/LC_MESSAGES/foo.po')
        self.assertEquals({
            'Foo': '',
            'Login': ''
        }, pohelpers.messages(*pofile))
    def test_merges_content_pot_files(self):
        fshelpers.create_structure(
            self.tempdir, {
                'foo/foo/__init__.py':
                '_("Foo")',
                'foo/foo/locales/foo.pot':
                fshelpers.asset('empty.pot'),
                'foo/foo/locales/foo-content.pot':
                fshelpers.asset('foo.pot'),
                'foo/foo/locales/de/LC_MESSAGES/foo.po':
                fshelpers.asset('empty.po'),
            })

        build_translations(self.tempdir, self.tempdir, 'foo', output=None)
        pofile = (self.tempdir, 'foo/foo/locales/de/LC_MESSAGES/foo.po')
        self.assertEquals({
            'Foo': '',
            'Login': ''
        }, pohelpers.messages(*pofile))
예제 #27
0
    def test_download_does_not_empty_existing_translations(self):
        fshelpers.create_structure(self.tempdir, {
                'foo/bar/locales/bar.pot': fshelpers.asset('empty.pot'),
                'foo/bar/locales/de/LC_MESSAGES/bar.po': pohelpers.makepo({
                        'label_login': ('Login', 'Anmelden')})})
        pofile = (self.tempdir, 'foo/bar/locales/de/LC_MESSAGES/bar.po')

        spreadsheet = SpreadSheetMock(
            {'worksheet': [{'package': u'foo',
                            'domain': u'bar',
                            'id': u'label_login',
                            'default': u'Login',
                            'translations': {u'de': u''},
                            }]})
        download.download(spreadsheet, self.tempdir,
                          worksheet_name='worksheet',
                          languages=['de'])

        self.assertEquals({'label_login': '******'},
                          pohelpers.messages(*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
예제 #29
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