def test_translations_integration(self):
        template = "{% trans %}Hey!{% endtrans %}"

        jinja2_env = create_jinja2_env()
        result = jinja2_env.from_string(template).render()
        self.assertEqual("Hey!", result)

        translations = get_translations("tests/fixtures/ru.po")
        jinja2_env = create_jinja2_env(translations=translations)
        result = jinja2_env.from_string(template).render()
        self.assertEqual(u"Привет!", result)
Example #2
0
    def test_translations_integration(self):
        template = '{% trans %}Hey!{% endtrans %}'

        jinja2_env = create_jinja2_env()
        result = jinja2_env.from_string(template).render()
        self.assertEqual('Hey!', result)

        translations = get_translations('tests/fixtures/ru.po')
        jinja2_env = create_jinja2_env(translations=translations)
        result = jinja2_env.from_string(template).render()
        self.assertEqual(u'Привет!', result)
Example #3
0
def build_(source_dir, build_dir, static_dir, language=None):
    """
    1. Creates the tree from `source_dir` (:func:`create_tree`),
       sorts it (:func:`sort_tree`), paginates (:func:`paginate_tree`) and
       fills with contexts in given `language` (:func:`fill_tree`);
    2. Tries to load translation from `./translations/<language>.po`;
    3. Creates Jinja2 environment with webassets and i18n extensions and
       passes it to :func:`build_site`.
    """
    source_path = lambda *args: os.path.join(source_dir, *args)

    tree = create_tree(source_path('pages'), 'ROOT')
    tree = sort_tree(tree, settings.ORDERING)
    tree = paginate_tree(tree, settings.PAGINATION)
    tree = fill_tree(tree, language=language)

    translations = None
    if language:
        translations_path = source_path('translations/%s.po' % language)
        if os.path.exists(translations_path):
            translations = get_translations(translations_path)

    assets_env = create_assets_env(
        source_path('static'), static_dir, settings.STATIC_URL, settings.BUNDLES)
    jinja2_env = create_jinja2_env(
        url_for=partial(url_for, tree),
        assets_env=assets_env,
        translations=translations)

    build_site(jinja2_env, build_dir, tree)
Example #4
0
 def test_webassets_integration(self):
     template = '{% assets "css" %}{{ ASSET_URL }}{% endassets %}'
     assets_env = create_assets_env('./tests/fixtures/bundle', self.build_dir, {
         'css': Bundle('one.css', 'two.css', output='styles.css')
     })
     jinja2_env = create_jinja2_env(assets_env=assets_env)
     result = jinja2_env.from_string(template).render()
     self.assertTrue('styles.css' in result)
 def test_webassets_integration(self):
     template = '{% assets "css" %}{{ ASSET_URL }}{% endassets %}'
     assets_env = create_assets_env(
         source_dir="./tests/fixtures/bundle",
         build_dir=self.build_dir,
         static_url="/",
         bundles={"css": Bundle("one.css", "two.css", output="styles.css")},
     )
     jinja2_env = create_jinja2_env(assets_env=assets_env)
     result = jinja2_env.from_string(template).render()
     self.assertTrue("styles.css" in result)
Example #6
0
    def test(self):
        jinja2_env = create_jinja2_env(layouts_dir='tests/fixtures/layouts')

        with tempfile.NamedTemporaryFile() as pot_file:
            extract_translations(jinja2_env, pot_file.name)
            po_entries = polib.pofile(pot_file.name)
            
            self.assertEqual(
                str(po_entries[0]),
                '#: test.html:1\n'
                'msgid "Static"\n'
                'msgstr "Static"\n')
            
            self.assertEqual(
                str(po_entries[1]),
                '#: test.html:1 test.html:3\n'
                'msgid "sites"\n'
                'msgstr "sites"\n')
Example #7
0
def extract_messages(to='translations/messages.pot'):
    """Extracts localizable strings from the templates."""
    settings.configure('settings')
    jinja2_env = create_jinja2_env()
    extract_translations(jinja2_env, to)