def test_filters(self):
        sources = [
            'tests/i18n/code.py',
        ]
        kwargs = {
            'translations_dir': config.TEMP_DIR,
            'mapping': 'tests/i18n/babel.cfg',
            'source': sources,
            'extract_update': True,
            'compile': True,
            'verbose': logging.DEBUG,
            'version': version.__version__,
        }
        args = argparse.Namespace(**kwargs)
        manage.setup_verbosity(args)
        manage.translate_messages(args)

        manage.sh("""
        pybabel init -i {d}/messages.pot -d {d} -l en_US
        pybabel init -i {d}/messages.pot -d {d} -l fr_FR
        """.format(d=config.TEMP_DIR))

        fake_config = self.get_fake_config()
        fake_config.SUPPORTED_LOCALES = ['en_US', 'fr_FR']
        fake_config.TRANSLATION_DIRS = config.TEMP_DIR
        for app in (journalist_app.create_app(fake_config),
                    source_app.create_app(fake_config)):
            assert i18n.LOCALES == fake_config.SUPPORTED_LOCALES
            self.verify_filesizeformat(app)
            self.verify_rel_datetime_format(app)
Exemplo n.º 2
0
    def test_filters(self):
        sources = [
            'tests/i18n/code.py',
        ]
        kwargs = {
            'translations_dir': config.TEMP_DIR,
            'mapping': 'tests/i18n/babel.cfg',
            'source': sources,
            'extract_update': True,
            'compile': True,
            'verbose': logging.DEBUG,
            'version': version.__version__,
        }
        args = argparse.Namespace(**kwargs)
        manage.setup_verbosity(args)
        manage.translate_messages(args)

        manage.sh("""
        pybabel init -i {d}/messages.pot -d {d} -l en_US
        pybabel init -i {d}/messages.pot -d {d} -l fr_FR
        """.format(d=config.TEMP_DIR))

        fake_config = self.get_fake_config()
        fake_config.SUPPORTED_LOCALES = ['en_US', 'fr_FR']
        fake_config.TRANSLATION_DIRS = config.TEMP_DIR
        for app in (journalist_app.create_app(fake_config),
                    source_app.create_app(fake_config)):
            assert i18n.LOCALES == fake_config.SUPPORTED_LOCALES
            self.verify_filesizeformat(app)
            self.verify_rel_datetime_format(app)
    def test_filters(self):
        sources = [
            'tests/i18n/code.py',
        ]
        kwargs = {
            'translations_dir': config.TEMP_DIR,
            'mapping': 'tests/i18n/babel.cfg',
            'source': sources,
            'extract_update': True,
            'compile': True,
            'verbose': logging.DEBUG,
            'version': version.__version__,
        }
        args = argparse.Namespace(**kwargs)
        manage.setup_verbosity(args)
        manage.translate_messages(args)

        manage.sh("""
        pybabel init -i {d}/messages.pot -d {d} -l en_US
        pybabel init -i {d}/messages.pot -d {d} -l fr_FR
        """.format(d=config.TEMP_DIR))

        supported = getattr(config, 'SUPPORTED_LOCALES', None)
        try:
            if supported:
                del config.SUPPORTED_LOCALES
            for app in (journalist.app, source.app):
                config.SUPPORTED_LOCALES = ['en_US', 'fr_FR']
                app.config['BABEL_TRANSLATION_DIRECTORIES'] = config.TEMP_DIR
                i18n.setup_app(app)
                self.verify_filesizeformat(app)
                self.verify_rel_datetime_format(app)
        finally:
            if supported:
                config.SUPPORTED_LOCALES = supported
Exemplo n.º 4
0
    def test_i18n(self):
        sources = [
            'tests/i18n/code.py',
            'tests/i18n/template.html',
        ]
        kwargs = {
            'translations_dir': config.TEMP_DIR,
            'mapping': 'tests/i18n/babel.cfg',
            'source': sources,
            'extract_update': True,
            'compile': True,
            'verbose': logging.DEBUG,
            'version': version.__version__,
        }
        args = argparse.Namespace(**kwargs)
        manage.setup_verbosity(args)
        manage.translate_messages(args)

        manage.sh("""
        pybabel init -i {d}/messages.pot -d {d} -l en_US

        pybabel init -i {d}/messages.pot -d {d} -l fr_FR
        sed -i -e '/code hello i18n/,+1s/msgstr ""/msgstr "code bonjour"/' \
              {d}/fr_FR/LC_MESSAGES/messages.po

        pybabel init -i {d}/messages.pot -d {d} -l zh_Hans_CN
        sed -i -e '/code hello i18n/,+1s/msgstr ""/msgstr "code chinese"/' \
              {d}/zh_Hans_CN/LC_MESSAGES/messages.po

        pybabel init -i {d}/messages.pot -d {d} -l ar
        sed -i -e '/code hello i18n/,+1s/msgstr ""/msgstr "code arabic"/' \
              {d}/ar/LC_MESSAGES/messages.po

        pybabel init -i {d}/messages.pot -d {d} -l nb_NO
        sed -i -e '/code hello i18n/,+1s/msgstr ""/msgstr "code norwegian"/' \
              {d}/nb_NO/LC_MESSAGES/messages.po

        pybabel init -i {d}/messages.pot -d {d} -l es_ES
        sed -i -e '/code hello i18n/,+1s/msgstr ""/msgstr "code spanish"/' \
              {d}/es_ES/LC_MESSAGES/messages.po
        """.format(d=config.TEMP_DIR))

        manage.translate_messages(args)

        fake_config = self.get_fake_config()
        fake_config.SUPPORTED_LOCALES = [
            'en_US', 'fr_FR', 'zh_Hans_CN', 'ar', 'nb_NO'
        ]
        fake_config.TRANSLATION_DIRS = config.TEMP_DIR
        for app in (journalist_app.create_app(fake_config),
                    source_app.create_app(fake_config)):
            assert i18n.LOCALES == fake_config.SUPPORTED_LOCALES
            self.verify_i18n(app)
Exemplo n.º 5
0
    def test_i18n(self):
        sources = [
            'tests/i18n/code.py',
            'tests/i18n/template.html',
        ]
        kwargs = {
            'translations_dir': config.TEMP_DIR,
            'mapping': 'tests/i18n/babel.cfg',
            'source': sources,
            'extract_update': True,
            'compile': True,
            'verbose': logging.DEBUG,
            'version': version.__version__,
        }
        args = argparse.Namespace(**kwargs)
        manage.setup_verbosity(args)
        manage.translate_messages(args)

        manage.sh("""
        pybabel init -i {d}/messages.pot -d {d} -l en_US

        pybabel init -i {d}/messages.pot -d {d} -l fr_FR
        sed -i -e '/code hello i18n/,+1s/msgstr ""/msgstr "code bonjour"/' \
              {d}/fr_FR/LC_MESSAGES/messages.po

        pybabel init -i {d}/messages.pot -d {d} -l zh_Hans_CN
        sed -i -e '/code hello i18n/,+1s/msgstr ""/msgstr "code chinese"/' \
              {d}/zh_Hans_CN/LC_MESSAGES/messages.po

        pybabel init -i {d}/messages.pot -d {d} -l ar
        sed -i -e '/code hello i18n/,+1s/msgstr ""/msgstr "code arabic"/' \
              {d}/ar/LC_MESSAGES/messages.po

        pybabel init -i {d}/messages.pot -d {d} -l nb_NO
        sed -i -e '/code hello i18n/,+1s/msgstr ""/msgstr "code norwegian"/' \
              {d}/nb_NO/LC_MESSAGES/messages.po
        """.format(d=config.TEMP_DIR))

        manage.translate_messages(args)

        supported = getattr(config, 'SUPPORTED_LOCALES', None)
        try:
            if supported:
                del config.SUPPORTED_LOCALES
            for app in (journalist.app, source.app):
                config.SUPPORTED_LOCALES = [
                    'en_US', 'fr_FR', 'zh_Hans_CN', 'ar', 'nb_NO'
                ]
                i18n.setup_app(app, translation_dirs=config.TEMP_DIR)
                self.verify_i18n(app)
        finally:
            if supported:
                config.SUPPORTED_LOCALES = supported
Exemplo n.º 6
0
    def test_i18n(self):
        sources = [
            'tests/i18n/code.py',
            'tests/i18n/template.html',
        ]
        kwargs = {
            'translations_dir': config.TEMP_DIR,
            'mapping': 'tests/i18n/babel.cfg',
            'source': sources,
            'extract_update': True,
            'compile': True,
            'verbose': logging.DEBUG,
            'version': version.__version__,
        }
        args = argparse.Namespace(**kwargs)
        manage.setup_verbosity(args)
        manage.translate_messages(args)

        manage.sh("""
        pybabel init -i {d}/messages.pot -d {d} -l en_US

        pybabel init -i {d}/messages.pot -d {d} -l fr_FR
        sed -i -e '/code hello i18n/,+1s/msgstr ""/msgstr "code bonjour"/' \
              {d}/fr_FR/LC_MESSAGES/messages.po

        pybabel init -i {d}/messages.pot -d {d} -l zh_Hans_CN
        sed -i -e '/code hello i18n/,+1s/msgstr ""/msgstr "code chinese"/' \
              {d}/zh_Hans_CN/LC_MESSAGES/messages.po

        pybabel init -i {d}/messages.pot -d {d} -l ar
        sed -i -e '/code hello i18n/,+1s/msgstr ""/msgstr "code arabic"/' \
              {d}/ar/LC_MESSAGES/messages.po

        pybabel init -i {d}/messages.pot -d {d} -l nb_NO
        sed -i -e '/code hello i18n/,+1s/msgstr ""/msgstr "code norwegian"/' \
              {d}/nb_NO/LC_MESSAGES/messages.po

        pybabel init -i {d}/messages.pot -d {d} -l es_ES
        sed -i -e '/code hello i18n/,+1s/msgstr ""/msgstr "code spanish"/' \
              {d}/es_ES/LC_MESSAGES/messages.po
        """.format(d=config.TEMP_DIR))

        manage.translate_messages(args)

        fake_config = self.get_fake_config()
        fake_config.SUPPORTED_LOCALES = [
            'en_US', 'fr_FR', 'zh_Hans_CN', 'ar', 'nb_NO']
        fake_config.TRANSLATION_DIRS = config.TEMP_DIR
        for app in (journalist_app.create_app(fake_config),
                    source_app.create_app(fake_config)):
            assert i18n.LOCALES == fake_config.SUPPORTED_LOCALES
            self.verify_i18n(app)
Exemplo n.º 7
0
    def test_translate_messages_l10n(self):
        source = [
            join(self.dir, 'i18n/code.py'),
            join(self.dir, 'i18n/template.html'),
        ]
        kwargs = {
            'translations_dir': config.TEMP_DIR,
            'mapping': join(self.dir, 'i18n/babel.cfg'),
            'source': source,
            'extract_update': True,
            'compile': True,
            'verbose': logging.DEBUG,
            'version': version.__version__,
        }
        args = argparse.Namespace(**kwargs)
        manage.setup_verbosity(args)
        manage.translate_messages(args)
        messages_file = join(config.TEMP_DIR, 'messages.pot')
        assert exists(messages_file)
        pot = open(messages_file).read()
        assert 'code hello i18n' in pot
        assert 'template hello i18n' in pot

        locale = 'en_US'
        locale_dir = join(config.TEMP_DIR, locale)
        manage.sh("pybabel init -i {} -d {} -l {}".format(
            messages_file,
            config.TEMP_DIR,
            locale,
        ))
        mo_file = join(locale_dir, 'LC_MESSAGES/messages.mo')
        assert not exists(mo_file)
        manage.translate_messages(args)
        assert exists(mo_file)
        mo = open(mo_file).read()
        assert 'code hello i18n' in mo
        assert 'template hello i18n' in mo
Exemplo n.º 8
0
    def test_translate_messages_compile_arg(self):
        source = [
            join(self.dir, 'i18n/code.py'),
        ]
        kwargs = {
            'translations_dir': config.TEMP_DIR,
            'mapping': join(self.dir, 'i18n/babel.cfg'),
            'source': source,
            'extract_update': True,
            'compile': False,
            'verbose': logging.DEBUG,
            'version': version.__version__,
        }
        args = argparse.Namespace(**kwargs)
        manage.setup_verbosity(args)
        manage.translate_messages(args)
        messages_file = join(config.TEMP_DIR, 'messages.pot')
        assert exists(messages_file)
        pot = open(messages_file).read()
        assert 'code hello i18n' in pot

        locale = 'en_US'
        locale_dir = join(config.TEMP_DIR, locale)
        po_file = join(locale_dir, 'LC_MESSAGES/messages.po')
        manage.sh("pybabel init -i {} -d {} -l {}".format(
            messages_file,
            config.TEMP_DIR,
            locale,
        ))
        assert exists(po_file)
        # pretend this happened a few seconds ago
        few_seconds_ago = time.time() - 60
        os.utime(po_file, (few_seconds_ago, few_seconds_ago))

        mo_file = join(locale_dir, 'LC_MESSAGES/messages.mo')

        #
        # Extract+update but do not compile
        #
        old_po_mtime = getmtime(po_file)
        assert not exists(mo_file)
        manage.translate_messages(args)
        assert not exists(mo_file)
        current_po_mtime = getmtime(po_file)
        assert old_po_mtime < current_po_mtime

        #
        # Compile but do not extract+update
        #
        source = [
            join(self.dir, 'i18n/code.py'),
            join(self.dir, 'i18n/template.html'),
        ]
        kwargs['extract_update'] = False
        kwargs['compile'] = True
        args = argparse.Namespace(**kwargs)
        old_po_mtime = current_po_mtime
        manage.translate_messages(args)
        assert old_po_mtime == getmtime(po_file)
        mo = open(mo_file).read()
        assert 'code hello i18n' in mo
        assert 'template hello i18n' not in mo