def test_synced_files_have_no_Language_Name_header(self):
        package = (self.tempdir, 'foo/foo')
        locales = (package, 'locales')
        locales_de = (locales, 'de/LC_MESSAGES')
        fshelpers.create_structure({
            (package, '__init__.py'):
            '_("Foo")',
            (locales, 'foo.pot'):
            fshelpers.asset('empty.pot'),
            (locales_de, 'foo.po'):
            fshelpers.asset('empty.po')
        })

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

        self.assertNotIn(
            'Language-Name', pohelpers.headers(locales_de, 'foo.po'),
            'The "Language-Code" header is not necessary for Plone, since the'
            ' filename contains the domain and it  is often not set'
            ' correctly, therefore we remove  it.')

        self.assertNotIn(
            'Language-Name', pohelpers.headers(locales, 'foo.pot'),
            'The "Language-Code" header is not necessary for Plone, since the'
            ' filename contains the domain and it  is often not set'
            ' correctly, therefore we remove  it.')
    def test_synced_files_have_no_Language_Name_header(self):
        package = (self.tempdir, 'foo/foo')
        locales = (package, 'locales')
        locales_de = (locales, 'de/LC_MESSAGES')
        fshelpers.create_structure({
                (package, '__init__.py'): '_("Foo")',
                (locales, 'foo.pot'): fshelpers.asset('empty.pot'),
                (locales_de, 'foo.po'): fshelpers.asset('empty.po')})

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

        self.assertNotIn(
            'Language-Name',
            pohelpers.headers(locales_de, 'foo.po'),

            'The "Language-Code" header is not necessary for Plone, since the'
            ' filename contains the domain and it  is often not set'
            ' correctly, therefore we remove  it.')

        self.assertNotIn(
            'Language-Name',
            pohelpers.headers(locales, 'foo.pot'),

            'The "Language-Code" header is not necessary for Plone, since the'
            ' filename contains the domain and it  is often not set'
            ' correctly, therefore we remove  it.')
    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_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')
        synchronize(self.tempdir, output=None)
        self.assertEquals({'Foo': ['./foo/__init__.py:1']},
                          pohelpers.message_references(*pofile))
예제 #5
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))
    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_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_loading_package_translations(self):
        fshelpers.create_structure(self.tempdir, {
                'pyfoo/foo/locales/foo.pot': fshelpers.asset('foo.pot'),
                'pyfoo/foo/locales/de/LC_MESSAGES/foo.po': fshelpers.asset(
                    'foo-de.po')})

        catalog = loader.load_translation_catalog(self.layer[u'tempdir'])
        self.assertEquals(1, len(catalog.messages),
                          'Expected catalog to have one message')

        message, = catalog.messages
        self.assertEquals('pyfoo', message.package)
        self.assertEquals('foo', message.domain)
        self.assertEquals('Login', message.msgid)
        self.assertEquals(None, message.default)
        self.assertEquals({'de': 'Anmelden'}, message.translations)
예제 #11
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))
예제 #12
0
    def test_no_potfile_with_missing_translations(self):
        fshelpers.create_structure(self.tempdir, {
                'foo/foo/profiles/default/content_creation/content.json':
                        fshelpers.asset('untranslated_content.json'),
                    })

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

        self.assertFalse(os.path.exists(self.potfile))
    def test_no_potfile_with_missing_translations(self):
        fshelpers.create_structure(
            self.tempdir,
            {"foo/foo/profiles/default/content_creation/content.json": fshelpers.asset("untranslated_content.json")},
        )

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

        self.assertFalse(os.path.exists(self.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_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_removes_domain(self):
        # In Plone, the domain is defined through the basename of the
        # pofile. The "Domain:" header is not necessary, so we remove it.

        fshelpers.create_structure(self.tempdir, {
                'pyfoo/foo/locales/foo.pot': fshelpers.asset('foo.pot'),
                'pyfoo/foo/locales/de/LC_MESSAGES/foo.po': fshelpers.asset(
                    'foo-de.po')})

        catalog = loader.load_translation_catalog(self.tempdir)
        writer.write_catalog(self.tempdir, catalog)
        pofile = fshelpers.cat(self.tempdir,
                               'pyfoo/foo/locales/de/LC_MESSAGES/foo.po')

        lines = pofile.split('\n')
        self.assertEquals([],
                          filter(lambda line: line.startswith('"Domain'),
                                 lines))
    def test_does_not_sync_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(
                    'empty.pot'),
                'foo/foo/locales/de/LC_MESSAGES/foo.po': fshelpers.asset(
                    'foo-de.po'),
                })

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

        self.assertItemsEqual(
            ['foo/foo/__init__.py',
             'foo/foo/locales/foo.pot',
             'foo/foo/locales/foo-manual.pot',
             'foo/foo/locales/de/LC_MESSAGES/foo.po'],
            fshelpers.files(self.tempdir))
    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_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))
        build_translations(self.tempdir, self.tempdir, 'foo', output=None)
        self.assertEquals({'Foo': ['./foo/foo/__init__.py:1']},
                          pohelpers.message_references(*potfile))
    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_updating_existing_messages(self):
        fshelpers.create_structure(self.tempdir, {
                'pyfoo/foo/locales/foo.pot': fshelpers.asset('foo.pot'),
                'pyfoo/foo/locales/de/LC_MESSAGES/foo.po': fshelpers.asset(
                    'foo-de.po')})

        catalog = loader.load_translation_catalog(self.tempdir)
        message = catalog.get_message('pyfoo', 'foo', 'Login')
        message.translate('de', 'Einloggen')

        writer.write_catalog(self.tempdir, catalog)

        pofile = fshelpers.cat(self.tempdir,
                               'pyfoo/foo/locales/de/LC_MESSAGES/foo.po')

        self.assertIn(
            '\n'.join(('msgid "Login"',
                       'msgstr "Einloggen"')),
            pofile)
예제 #23
0
    def test_loading_package_translations(self):
        fshelpers.create_structure(
            self.tempdir, {
                'pyfoo/foo/locales/foo.pot':
                fshelpers.asset('foo.pot'),
                'pyfoo/foo/locales/de/LC_MESSAGES/foo.po':
                fshelpers.asset('foo-de.po')
            })

        catalog = loader.load_translation_catalog(self.layer[u'tempdir'])
        self.assertEquals(1, len(catalog.messages),
                          'Expected catalog to have one message')

        message, = catalog.messages
        self.assertEquals('pyfoo', message.package)
        self.assertEquals('foo', message.domain)
        self.assertEquals('Login', message.msgid)
        self.assertEquals(None, message.default)
        self.assertEquals({'de': 'Anmelden'}, message.translations)
    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))
예제 #25
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))
    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')
    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))
예제 #28
0
    def test_updating_existing_messages(self):
        fshelpers.create_structure(
            self.tempdir, {
                'pyfoo/foo/locales/foo.pot':
                fshelpers.asset('foo.pot'),
                'pyfoo/foo/locales/de/LC_MESSAGES/foo.po':
                fshelpers.asset('foo-de.po')
            })

        catalog = loader.load_translation_catalog(self.tempdir)
        message = catalog.get_message('pyfoo', 'foo', 'Login')
        message.translate('de', 'Einloggen')

        writer.write_catalog(self.tempdir, catalog)

        pofile = fshelpers.cat(self.tempdir,
                               'pyfoo/foo/locales/de/LC_MESSAGES/foo.po')

        self.assertIn('\n'.join(('msgid "Login"', 'msgstr "Einloggen"')),
                      pofile)
    def test_does_not_sync_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('empty.pot'),
                'foo/foo/locales/de/LC_MESSAGES/foo.po':
                fshelpers.asset('foo-de.po'),
            })

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

        self.assertItemsEqual([
            'foo/foo/__init__.py', 'foo/foo/locales/foo.pot',
            'foo/foo/locales/foo-manual.pot',
            'foo/foo/locales/de/LC_MESSAGES/foo.po'
        ], fshelpers.files(self.tempdir))
    def test_caches_pofiles(self):
        fshelpers.create_structure(self.tempdir, {
                'pyfoo/foo/locales/de/LC_MESSAGES/foo.po': fshelpers.asset(
                    'foo-de.po')})
        catalog = loader.load_translation_catalog(self.tempdir)
        message, = catalog.messages
        registry = writer.PofileRegistry(self.tempdir)

        self.assertIs(registry.find_pofile_for(message, 'de'),
                      registry.find_pofile_for(message, 'de'),
                      'Pofiles should be cached')
    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))
예제 #32
0
    def test_removes_domain(self):
        # In Plone, the domain is defined through the basename of the
        # pofile. The "Domain:" header is not necessary, so we remove it.

        fshelpers.create_structure(
            self.tempdir, {
                'pyfoo/foo/locales/foo.pot':
                fshelpers.asset('foo.pot'),
                'pyfoo/foo/locales/de/LC_MESSAGES/foo.po':
                fshelpers.asset('foo-de.po')
            })

        catalog = loader.load_translation_catalog(self.tempdir)
        writer.write_catalog(self.tempdir, catalog)
        pofile = fshelpers.cat(self.tempdir,
                               'pyfoo/foo/locales/de/LC_MESSAGES/foo.po')

        lines = pofile.split('\n')
        self.assertEquals([],
                          filter(lambda line: line.startswith('"Domain'),
                                 lines))
    def test_finds_pofile_paths(self):
        fshelpers.create_structure(self.tempdir, {
                'pyfoo/foo/locales/de/LC_MESSAGES/foo.po': fshelpers.asset(
                    'foo-de.po')})
        catalog = loader.load_translation_catalog(self.tempdir)
        message, = catalog.messages
        registry = writer.PofileRegistry(self.tempdir)

        expected = os.path.join(self.tempdir,
                                'pyfoo/foo/locales/de/LC_MESSAGES/foo.po')
        self.assertEquals(expected,
                          registry.find_pofile_path_for(message, 'de'))
예제 #34
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_i18ndude_SystemExit_is_handled(self):
     # This is quite a "stupid" test:
     # Rebuilding a domain without having any translations makes the internal
     # i18ndude command to perform a system exit.
     # This is really bad, since we are possibly building multiple pot-files
     # and are doing more stuff and should be in control of such things.
     fshelpers.create_structure(self.tempdir, {"foo/locales/foo.pot": fshelpers.asset("empty.pot")})
     try:
         with capture_streams(stderr=StringIO()):
             rebuild_package_potfiles(self.tempdir, self.tempdir, "foo")
     except SystemExit:
         assert False, "SystemExit leaked from i18ndude while rebuilding pot-files!"
    def test_removes_language_code_and_name(self):
        # In Plone, the language is defined through the location of the
        # pofile, e.g. it is obvious that locales/de/LC_MESSAGES/foo.po is
        # a German translation.
        # We therefore do not include the language-code and language-name
        # headers in the po file and remove them when i18ndude adds them,
        # so that they are no longer wrong..

        fshelpers.create_structure(self.tempdir, {
                'pyfoo/foo/locales/foo.pot': fshelpers.asset('foo.pot'),
                'pyfoo/foo/locales/de/LC_MESSAGES/foo.po': fshelpers.asset(
                    'foo-de.po')})

        catalog = loader.load_translation_catalog(self.tempdir)
        writer.write_catalog(self.tempdir, catalog)
        pofile = fshelpers.cat(self.tempdir,
                               'pyfoo/foo/locales/de/LC_MESSAGES/foo.po')

        lines = pofile.split('\n')
        self.assertEquals(['"Language-Team: LANGUAGE <*****@*****.**>\\n"'],
                          filter(lambda line: line.startswith('"Lang'),
                                 lines))
예제 #37
0
    def test_caches_pofiles(self):
        fshelpers.create_structure(
            self.tempdir, {
                'pyfoo/foo/locales/de/LC_MESSAGES/foo.po':
                fshelpers.asset('foo-de.po')
            })
        catalog = loader.load_translation_catalog(self.tempdir)
        message, = catalog.messages
        registry = writer.PofileRegistry(self.tempdir)

        self.assertIs(registry.find_pofile_for(message, 'de'),
                      registry.find_pofile_for(message, 'de'),
                      'Pofiles should be cached')
    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)
예제 #39
0
 def test_i18ndude_SystemExit_is_handled(self):
     # This is quite a "stupid" test:
     # Rebuilding a domain without having any translations makes the internal
     # i18ndude command to perform a system exit.
     # This is really bad, since we are possibly building multiple pot-files
     # and are doing more stuff and should be in control of such things.
     fshelpers.create_structure(
         self.tempdir,
         {'foo/locales/foo.pot': fshelpers.asset('empty.pot')})
     try:
         with capture_streams(stderr=StringIO()):
             rebuild_package_potfiles(self.tempdir, self.tempdir, 'foo')
     except SystemExit:
         assert False, 'SystemExit leaked from i18ndude while rebuilding pot-files!'
예제 #40
0
    def test_finds_pofile_paths(self):
        fshelpers.create_structure(
            self.tempdir, {
                'pyfoo/foo/locales/de/LC_MESSAGES/foo.po':
                fshelpers.asset('foo-de.po')
            })
        catalog = loader.load_translation_catalog(self.tempdir)
        message, = catalog.messages
        registry = writer.PofileRegistry(self.tempdir)

        expected = os.path.join(self.tempdir,
                                'pyfoo/foo/locales/de/LC_MESSAGES/foo.po')
        self.assertEquals(expected,
                          registry.find_pofile_path_for(message, 'de'))
    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)
예제 #42
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)
예제 #43
0
    def test_removes_language_code_and_name(self):
        # In Plone, the language is defined through the location of the
        # pofile, e.g. it is obvious that locales/de/LC_MESSAGES/foo.po is
        # a German translation.
        # We therefore do not include the language-code and language-name
        # headers in the po file and remove them when i18ndude adds them,
        # so that they are no longer wrong..

        fshelpers.create_structure(
            self.tempdir, {
                'pyfoo/foo/locales/foo.pot':
                fshelpers.asset('foo.pot'),
                'pyfoo/foo/locales/de/LC_MESSAGES/foo.po':
                fshelpers.asset('foo-de.po')
            })

        catalog = loader.load_translation_catalog(self.tempdir)
        writer.write_catalog(self.tempdir, catalog)
        pofile = fshelpers.cat(self.tempdir,
                               'pyfoo/foo/locales/de/LC_MESSAGES/foo.po')

        lines = pofile.split('\n')
        self.assertEquals(['"Language-Team: LANGUAGE <*****@*****.**>\\n"'],
                          filter(lambda line: line.startswith('"Lang'), lines))
예제 #44
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."
        )
예제 #46
0
def makepo(messages):
    data = StringIO()
    data.write(fshelpers.asset('empty.po'))

    for msgid, value in sorted(messages.items()):
        if isinstance(value, tuple):
            default, msgstr = value
        else:
            default, msgstr = None, value

        data.write('\n\n')
        if default:
            data.write('#. Default: "%s"\n' % default)
        data.write('msgid "%s"\n' % msgid)
        data.write('msgstr "%s"\n' % msgstr)

    return data.getvalue().strip()
    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_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)
    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))
예제 #50
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
예제 #52
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
    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_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))