Codebase list flask-babel / 434cb6e
Import Upstream version 0.11.2 Håvard Flaget Aasen 4 years ago
13 changed file(s) with 163 addition(s) and 25 deletion(s). Raw diff Collapse all Expand all
00 Metadata-Version: 1.1
11 Name: Flask-Babel
2 Version: 0.11.1
2 Version: 0.11.2
33 Summary: Adds i18n/l10n support to Flask applications
44 Home-page: http://github.com/python-babel/flask-babel
55 Author: Armin Ronacher
2323 tests/renamed_translations/de/LC_MESSAGES/messages.po
2424 tests/translations/messages.pot
2525 tests/translations/de/LC_MESSAGES/messages.mo
26 tests/translations/de/LC_MESSAGES/messages.po
26 tests/translations/de/LC_MESSAGES/messages.po
27 tests/translations_different_domain/myapp.pot
28 tests/translations_different_domain/de/LC_MESSAGES/myapp.mo
29 tests/translations_different_domain/de/LC_MESSAGES/myapp.po
00 Metadata-Version: 1.1
11 Name: Flask-Babel
2 Version: 0.11.1
2 Version: 0.11.2
33 Summary: Adds i18n/l10n support to Flask applications
44 Home-page: http://github.com/python-babel/flask-babel
55 Author: Armin Ronacher
4848 # built documents.
4949 #
5050 # The short X.Y version.
51 version = '0.11.1'
51 version = '0.11.2'
5252 # The full version, including alpha/beta/rc tags.
53 release = '0.11.1'
53 release = '0.11.2'
5454
5555 # The language for content autogenerated by Sphinx. Refer to documentation
5656 # for a list of supported languages.
3737 babel = Babel(app)
3838
3939 The babel object itself can be used to configure the babel support
40 further. Babel has two configuration values that can be used to change
41 some internal defaults:
42
43 =========================== =============================================
44 `BABEL_DEFAULT_LOCALE` The default locale to use if no locale
45 selector is registered. This defaults
46 to ``'en'``.
47 `BABEL_DEFAULT_TIMEZONE` The timezone to use for user facing dates.
48 This defaults to ``'UTC'`` which also is the
49 timezone your application must use internally.
50 =========================== =============================================
40 further. Babel has the following configuration values that can be used to
41 change some internal defaults:
42
43 =============================== =============================================
44 `BABEL_DEFAULT_LOCALE` The default locale to use if no locale
45 selector is registered. This defaults
46 to ``'en'``.
47 `BABEL_DEFAULT_TIMEZONE` The timezone to use for user facing dates.
48 This defaults to ``'UTC'`` which also is the
49 timezone your application must use internally.
50 `BABEL_TRANSLATION_DIRECTORIES` A semi-colon (``;``) separated string of
51 absolute and relative (to the app root) paths
52 to translation folders. Defaults to
53 ``translations``.
54 `BABEL_DOMAIN` The message domain used by the application.
55 Defaults to ``messages``.
56 =============================== =============================================
5157
5258 For more complex applications you might want to have multiple applications
5359 for different users which is where selector functions come in handy. The
5454 })
5555
5656 def __init__(self, app=None, default_locale='en', default_timezone='UTC',
57 date_formats=None, configure_jinja=True):
57 default_domain='messages', date_formats=None,
58 configure_jinja=True):
5859 self._default_locale = default_locale
5960 self._default_timezone = default_timezone
61 self._default_domain = default_domain
6062 self._date_formats = date_formats
6163 self._configure_jinja = configure_jinja
6264 self.app = app
7880
7981 app.config.setdefault('BABEL_DEFAULT_LOCALE', self._default_locale)
8082 app.config.setdefault('BABEL_DEFAULT_TIMEZONE', self._default_timezone)
83 app.config.setdefault('BABEL_DOMAIN', self._default_domain)
8184 if self._date_formats is None:
8285 self._date_formats = self.default_date_formats.copy()
8386
120123 time. If `None` is returned, the locale falls back to the one from
121124 the configuration.
122125
123 This has to return the locale as string (eg: ``'de_AT'``, ''`en_US`'')
126 This has to return the locale as string (eg: ``'de_AT'``, ``'en_US'``)
124127 """
125128 assert self.locale_selector_func is None, \
126129 'a localeselector function is already registered'
182185 return timezone(self.app.config['BABEL_DEFAULT_TIMEZONE'])
183186
184187 @property
188 def domain(self):
189 """The message domain for the translations as a string.
190 """
191 return self.app.config['BABEL_DOMAIN']
192
193 @property
185194 def translation_directories(self):
186195 directories = self.app.config.get(
187196 'BABEL_TRANSLATION_DIRECTORIES',
212221
213222 babel = current_app.extensions['babel']
214223 for dirname in babel.translation_directories:
215 catalog = support.Translations.load(dirname, [get_locale()])
224 catalog = support.Translations.load(
225 dirname,
226 [get_locale()],
227 babel.domain
228 )
216229 translations.merge(catalog)
217230 # FIXME: Workaround for merge() being really, really stupid. It
218231 # does not copy _info, plural(), or any other instance variables
427440
428441
429442 def format_timedelta(datetime_or_timedelta, granularity='second',
430 add_direction=False):
443 add_direction=False, threshold=0.85):
431444 """Format the elapsed time from the given date to now or the given
432 timedelta. This currently requires an unreleased development
433 version of Babel.
445 timedelta.
434446
435447 This function is also available in the template context as filter
436448 named `timedeltaformat`.
440452 return dates.format_timedelta(
441453 datetime_or_timedelta,
442454 granularity,
455 threshold=threshold,
443456 add_direction=add_direction,
444457 locale=get_locale()
445458 )
88 self._kwargs = kwargs
99
1010 def __getattr__(self, attr):
11 if attr == "__setstate__":
12 raise AttributeError(attr)
1113 string = text_type(self)
1214 if hasattr(string, attr):
1315 return getattr(string, attr)
1416 raise AttributeError(attr)
17
18 def __repr__(self):
19 return "l'{0}'".format(text_type(self))
1520
1621 def __str__(self):
1722 return text_type(self._func(*self._args, **self._kwargs))
00 [upload_docs]
11 upload-dir = docs/_build/html
2
3 [metadata]
4 description-file = README.md
25
36 [egg_info]
47 tag_build =
58 tag_date = 0
6 tag_svn_revision = 0
79
1919
2020 setup(
2121 name='Flask-Babel',
22 version='0.11.1',
22 version='0.11.2',
2323 url='http://github.com/python-babel/flask-babel',
2424 license='BSD',
2525 author='Armin Ronacher',
44 import os
55 sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
66
7 import pickle
8
79 import unittest
810 from decimal import Decimal
911 import flask
10 from datetime import datetime
12 from datetime import datetime, timedelta
1113 import flask_babel as babel
1214 from flask_babel import gettext, ngettext, lazy_gettext, get_translations
1315 from babel.support import NullTranslations
5254 name='Peter'
5355 ) == 'Hallo Peter!'
5456
57 def test_different_domain(self):
58 """
59 Ensure we can load translations from multiple directories.
60 """
61 b = babel.Babel()
62 app = flask.Flask(__name__)
63
64 app.config.update({
65 'BABEL_TRANSLATION_DIRECTORIES': 'translations_different_domain',
66 'BABEL_DEFAULT_LOCALE': 'de_DE',
67 'BABEL_DOMAIN': 'myapp'
68 })
69
70 b.init_app(app)
71
72 with app.test_request_context():
73 translations = b.list_translations()
74
75 assert(len(translations) == 1)
76 assert(str(translations[0]) == 'de')
77
78 assert gettext(u'Good bye') == 'Auf Wiedersehen'
79
5580 def test_lazy_old_style_formatting(self):
5681 lazy_string = lazy_gettext(u'Hello %(name)s')
5782 assert lazy_string % {u'name': u'test'} == u'Hello test'
5984 lazy_string = lazy_gettext(u'test')
6085 assert u'Hello %s' % lazy_string == u'Hello test'
6186
87 def test_lazy_pickling(self):
88 lazy_string = lazy_gettext(u'Foo')
89 pickled = pickle.dumps(lazy_string)
90 unpickled = pickle.loads(pickled)
91
92 assert unpickled == lazy_string
93
6294
6395 class DateFormattingTestCase(unittest.TestCase):
6496
6698 app = flask.Flask(__name__)
6799 babel.Babel(app)
68100 d = datetime(2010, 4, 12, 13, 46)
101 delta = timedelta(days=6)
69102
70103 with app.test_request_context():
71104 assert babel.format_datetime(d) == 'Apr 12, 2010, 1:46:00 PM'
72105 assert babel.format_date(d) == 'Apr 12, 2010'
73106 assert babel.format_time(d) == '1:46:00 PM'
107 assert babel.format_timedelta(delta) == '1 week'
108 assert babel.format_timedelta(delta, threshold=1) == '6 days'
74109
75110 with app.test_request_context():
76111 app.config['BABEL_DEFAULT_TIMEZONE'] = 'Europe/Vienna'
0 # German translations for PROJECT.
1 # Copyright (C) 2010 ORGANIZATION
2 # This file is distributed under the same license as the PROJECT project.
3 # FIRST AUTHOR <EMAIL@ADDRESS>, 2010.
4 #
5 msgid ""
6 msgstr ""
7 "Project-Id-Version: PROJECT VERSION\n"
8 "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
9 "POT-Creation-Date: 2010-05-29 17:00+0200\n"
10 "PO-Revision-Date: 2010-05-30 12:56+0200\n"
11 "Last-Translator: Armin Ronacher <armin.ronacher@active-4.com>\n"
12 "Language-Team: de <LL@li.org>\n"
13 "Plural-Forms: nplurals=2; plural=(n != 1)\n"
14 "MIME-Version: 1.0\n"
15 "Content-Type: text/plain; charset=utf-8\n"
16 "Content-Transfer-Encoding: 8bit\n"
17 "Generated-By: Babel 0.9.5\n"
18
19 #: tests.py:94
20 #, python-format
21 msgid "Hello %(name)s!"
22 msgstr "Hallo %(name)s!"
23
24 #: tests.py:95 tests.py:96
25 #, python-format
26 msgid "%(num)s Apple"
27 msgid_plural "%(num)s Apples"
28 msgstr[0] "%(num)s Apfel"
29 msgstr[1] "%(num)s Äpfel"
30
31 #: tests.py:119
32 msgid "Yes"
33 msgstr "Ja"
34
35 msgid "Good bye"
36 msgstr "Auf Wiedersehen"
0 # Translations template for PROJECT.
1 # Copyright (C) 2010 ORGANIZATION
2 # This file is distributed under the same license as the PROJECT project.
3 # FIRST AUTHOR <EMAIL@ADDRESS>, 2010.
4 #
5 #, fuzzy
6 msgid ""
7 msgstr ""
8 "Project-Id-Version: PROJECT VERSION\n"
9 "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
10 "POT-Creation-Date: 2010-05-30 12:56+0200\n"
11 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
12 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
13 "Language-Team: LANGUAGE <LL@li.org>\n"
14 "MIME-Version: 1.0\n"
15 "Content-Type: text/plain; charset=utf-8\n"
16 "Content-Transfer-Encoding: 8bit\n"
17 "Generated-By: Babel 0.9.5\n"
18
19 #: tests.py:94
20 #, python-format
21 msgid "Hello %(name)s!"
22 msgstr ""
23
24 #: tests.py:95 tests.py:96
25 #, python-format
26 msgid "%(num)s Apple"
27 msgid_plural "%(num)s Apples"
28 msgstr[0] ""
29 msgstr[1] ""
30
31 #: tests.py:119
32 msgid "Yes"
33 msgstr ""
34
35 msgid "Good bye"
36 msgstr ""