Exemplo n.º 1
0
    def test_lazy_with_require_activate(self):
        bundle = Bundle(['tests/main.ftl'],
                        default_locale='en',
                        require_activate=True)
        self.assertRaises(NoLocaleSet, bundle.format, 'simple')
        msg = bundle.format_lazy('simple')

        self.assertRaises(NoLocaleSet, force_text, msg)

        activate('en')
        self.assertEqual(force_text(msg), 'Simple')
        activate('fr-FR')
        self.assertEqual(force_text(msg), 'Facile')
Exemplo n.º 2
0
    def test_number_formatting_for_fallback(self):
        # When we fall back to a default, number formatting
        # should be consistent with the language.
        # German locale: 1.234.567
        # System locale  (would probably be 'en',): 1,234,567
        # French locale: 1 234 567⁩

        bundle = Bundle(['tests/main.ftl'], default_locale='fr-FR')
        activate('de')
        # Should get French words and formatting
        self.assertEqual(
            bundle.format('with-number-argument', {'points': 1234567}),
            'Points: \u20681\xa0234\xa0567\u2069')
Exemplo n.º 3
0
 def test_number_formatting(self):
     bundle = Bundle(['tests/main.ftl'], default_locale='en')
     self.assertEqual(
         bundle.format('with-number-argument', {'points': 1234567}),
         'Score: \u20681,234,567\u2069')
     activate('fr-FR')
     self.assertEqual(
         bundle.format('with-number-argument', {'points': 1234567}),
         'Points: \u20681\xa0234\xa0567\u2069')
     deactivate()
     self.assertEqual(
         bundle.format('with-number-argument', {'points': 1234567}),
         'Score: \u20681,234,567\u2069')
Exemplo n.º 4
0
 def test_no_locale_set_with_good_default_from_settings(self):
     bundle = Bundle(['tests/main.ftl'])
     self.assertEqual(bundle.format('simple'), 'Simple')
Exemplo n.º 5
0
 def test_no_locale_set_with_good_default(self):
     bundle = Bundle(['tests/main.ftl'],
                     default_locale='en')
     self.assertEqual(bundle.format('simple'), 'Simple')
Exemplo n.º 6
0
 def test_no_locale_set_with_default_set(self):
     bundle = Bundle(['tests/main.ftl'],
                     require_activate=True,
                     default_locale='en')
     self.assertRaises(NoLocaleSet, bundle.format, 'simple')
Exemplo n.º 7
0
 def test_missing_ftl_file(self):
     activate('en')
     bundle = Bundle(['tests/non-existant.ftl'], default_locale='en')
     self.assertRaises(FileNotFoundError, bundle.format, 'simple')
Exemplo n.º 8
0
# -*- coding: utf-8 -*-

from __future__ import absolute_import, print_function, unicode_literals

from django_ftl import activate
from django_ftl.bundles import Bundle

from .base import TestBase

ftl_bundle = Bundle(['tests/docs.ftl'])


class TestDocs(TestBase):
    def test_usage_docs(self):
        # These tests parallel the code in the usage.rst docs
        activate('en')
        title = ftl_bundle.format('events-title')
        self.assertEqual(title, 'MyApp Events!')

        greeting = ftl_bundle.format('events-greeting',
                                     {'username': '******'})
        self.assertEqual(greeting, 'Hello, \u2068boaty mcboatface\u2069')
Exemplo n.º 9
0
 def test_fallback(self):
     activate('tr')
     bundle = Bundle(['tests/main.ftl'], default_locale='en')
     self.assertEqual(bundle.format('missing-from-others'), "Missing from others")
Exemplo n.º 10
0
 def test_find_messages(self):
     bundle = Bundle(['tests/main.ftl'])
     activate('en')
     self.assertEqual(bundle.format('simple'), "Simple")
Exemplo n.º 11
0
 def test_missing(self):
     activate('en')
     bundle = Bundle(['tests/main.ftl'], default_locale='en')
     self.assertEqual(bundle.format('missing-from-all'), "???")
Exemplo n.º 12
0
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function, unicode_literals

import six
from django.utils.html import SafeText, mark_safe

from django_ftl.bundles import Bundle

from .base import TestBase

text_type = six.text_type

bundle = Bundle(['tests/escaping.ftl'], default_locale='en')


class TestBundles(TestBase):
    maxDiff = None

    def test_html(self):
        val = bundle.format('my-test-item-html', {'name': 'Me & My Friends'})
        self.assertEqual(
            val,
            'Welcome to \u2068Jack &amp; Jill\u2069. \u2068Jack &amp; Jill <i>ROCK</i> - <b>Yeah!</b>\u2069. Your name is \u2068Me &amp; My Friends\u2069.'
        )
        self.assertEqual(type(val), SafeText)

    def test_html_mark_safe(self):
        val = bundle.format('my-test-item-html',
                            {'name': mark_safe('<b>Me</b>')})
        self.assertEqual(
            val,
Exemplo n.º 13
0
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function, unicode_literals

from django_ftl.bundles import Bundle

# This module should raise an exception if you try to import it


main = Bundle(['tests/main.ftl'],
              default_locale='en',
              require_activate=True)


class MyThing(object):
    my_label = main.format('simple')
Exemplo n.º 14
0
from django_ftl.bundles import Bundle

main = Bundle(['app.ftl'])
Exemplo n.º 15
0
 def test_no_locale_set_with_missing_default(self):
     bundle = Bundle(['tests/main.ftl'])
     self.assertRaises(FileNotFoundError, bundle.format, 'simple')
Exemplo n.º 16
0
 def test_handle_underscores_in_locale_name(self):
     activate('fr_FR')
     bundle = Bundle(['tests/main.ftl'], default_locale='en')
     self.assertEqual(bundle.format('simple'), 'Facile')
Exemplo n.º 17
0
 def test_default_locale_lazy(self):
     # Ensure that bundle is retrieving LANGUAGE_CODE lazily. (The only real
     # reason for this at the moment is to make testing easier).
     bundle = Bundle(['tests/main.ftl'])
     with override_settings(LANGUAGE_CODE='fr-FR'):
         self.assertEqual(bundle.format('simple'), 'Facile')
Exemplo n.º 18
0
 def test_locale_matching_for_default_locale(self):
     activate('zh')
     bundle = Bundle(['tests/main.ftl'], default_locale='EN')  # 'EN' not 'en'
     self.assertEqual(bundle.format('simple'), 'Simple')
Exemplo n.º 19
0
 def test_load_multiple_with_some_missing(self):
     bundle = Bundle(['tests/only_in_en.ftl',
                      'tests/main.ftl'],
                     default_locale='en')
     activate('fr-FR')
     self.assertEqual(bundle.format('simple'), "Facile")
Exemplo n.º 20
0
 def test_locale_range_lookup(self):
     # en-US does not exist, but 'en' does and should be found
     activate('en-US')
     bundle = Bundle(['tests/main.ftl'], default_locale='en')
     self.assertEqual(bundle.format('simple'), 'Simple')
Exemplo n.º 21
0
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function, unicode_literals

from django_ftl.bundles import Bundle

simple_view = Bundle(['tests/simple_view.ftl'],
                     default_locale='en',
                     use_isolating=False,
                     require_activate=True)
Exemplo n.º 22
0
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function, unicode_literals

import re

from django.template import Context, Template

from django_ftl import activate
from django_ftl.bundles import Bundle

from .base import TestBase

main_bundle = Bundle(['tests/main.ftl'],
                     use_isolating=False,
                     default_locale='en')

other_bundle = Bundle(['tests/other.ftl'],
                      use_isolating=False,
                      default_locale='en')


class TestFtlConfTag(TestBase):
    def setUp(self):
        activate('en')

    def test_good(self):
        t = Template("""
        {% load ftl %}
        {% ftlconf mode='server' bundle='tests.test_templatetags.main_bundle' %}
        {% ftlmsg 'simple' %}
        """)