Esempio n. 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_additional_languages_are_not_filtered_when_untranslated(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')}),
                'foo/bar/locales/fr/LC_MESSAGES/bar.po': pohelpers.makepo({
                        'label_login': ('Login', 'Connecter')})})

        spreadsheet = SpreadSheetMock()
        upload.upload(spreadsheet, self.tempdir, filter_translated=True,
                      languages=['de'], additional_languages=['fr'],
                      output=None)
        self.assertEquals([],
                          spreadsheet.uploaded)
    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_only_upload_selected_languages(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')}),
                'foo/bar/locales/fr/LC_MESSAGES/bar.po': pohelpers.makepo({
                        'label_login': ('Login', 'Connecter')})})

        spreadsheet = SpreadSheetMock()
        upload.upload(spreadsheet, self.tempdir, filter_translated=False,
                      languages=['de'],
                      output=None)
        self.assertEquals([{'package': u'foo',
                            'domain': u'bar',
                            'id': u'label_login',
                            'default': u'Login',
                            'translations': {u'de': u'Anmelden'},
                            }],
                          spreadsheet.uploaded)
Esempio n. 5
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
Esempio 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