Import Upstream version 0.11.2
Håvard Flaget Aasen
4 years ago
0 | 0 | Metadata-Version: 1.1 |
1 | 1 | Name: Flask-Babel |
2 | Version: 0.11.1 | |
2 | Version: 0.11.2 | |
3 | 3 | Summary: Adds i18n/l10n support to Flask applications |
4 | 4 | Home-page: http://github.com/python-babel/flask-babel |
5 | 5 | Author: Armin Ronacher |
23 | 23 | tests/renamed_translations/de/LC_MESSAGES/messages.po |
24 | 24 | tests/translations/messages.pot |
25 | 25 | 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⏎ |
0 | 0 | Metadata-Version: 1.1 |
1 | 1 | Name: Flask-Babel |
2 | Version: 0.11.1 | |
2 | Version: 0.11.2 | |
3 | 3 | Summary: Adds i18n/l10n support to Flask applications |
4 | 4 | Home-page: http://github.com/python-babel/flask-babel |
5 | 5 | Author: Armin Ronacher |
48 | 48 | # built documents. |
49 | 49 | # |
50 | 50 | # The short X.Y version. |
51 | version = '0.11.1' | |
51 | version = '0.11.2' | |
52 | 52 | # The full version, including alpha/beta/rc tags. |
53 | release = '0.11.1' | |
53 | release = '0.11.2' | |
54 | 54 | |
55 | 55 | # The language for content autogenerated by Sphinx. Refer to documentation |
56 | 56 | # for a list of supported languages. |
37 | 37 | babel = Babel(app) |
38 | 38 | |
39 | 39 | 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 | =============================== ============================================= | |
51 | 57 | |
52 | 58 | For more complex applications you might want to have multiple applications |
53 | 59 | for different users which is where selector functions come in handy. The |
54 | 54 | }) |
55 | 55 | |
56 | 56 | 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): | |
58 | 59 | self._default_locale = default_locale |
59 | 60 | self._default_timezone = default_timezone |
61 | self._default_domain = default_domain | |
60 | 62 | self._date_formats = date_formats |
61 | 63 | self._configure_jinja = configure_jinja |
62 | 64 | self.app = app |
78 | 80 | |
79 | 81 | app.config.setdefault('BABEL_DEFAULT_LOCALE', self._default_locale) |
80 | 82 | app.config.setdefault('BABEL_DEFAULT_TIMEZONE', self._default_timezone) |
83 | app.config.setdefault('BABEL_DOMAIN', self._default_domain) | |
81 | 84 | if self._date_formats is None: |
82 | 85 | self._date_formats = self.default_date_formats.copy() |
83 | 86 | |
120 | 123 | time. If `None` is returned, the locale falls back to the one from |
121 | 124 | the configuration. |
122 | 125 | |
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'``) | |
124 | 127 | """ |
125 | 128 | assert self.locale_selector_func is None, \ |
126 | 129 | 'a localeselector function is already registered' |
182 | 185 | return timezone(self.app.config['BABEL_DEFAULT_TIMEZONE']) |
183 | 186 | |
184 | 187 | @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 | |
185 | 194 | def translation_directories(self): |
186 | 195 | directories = self.app.config.get( |
187 | 196 | 'BABEL_TRANSLATION_DIRECTORIES', |
212 | 221 | |
213 | 222 | babel = current_app.extensions['babel'] |
214 | 223 | 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 | ) | |
216 | 229 | translations.merge(catalog) |
217 | 230 | # FIXME: Workaround for merge() being really, really stupid. It |
218 | 231 | # does not copy _info, plural(), or any other instance variables |
427 | 440 | |
428 | 441 | |
429 | 442 | def format_timedelta(datetime_or_timedelta, granularity='second', |
430 | add_direction=False): | |
443 | add_direction=False, threshold=0.85): | |
431 | 444 | """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. | |
434 | 446 | |
435 | 447 | This function is also available in the template context as filter |
436 | 448 | named `timedeltaformat`. |
440 | 452 | return dates.format_timedelta( |
441 | 453 | datetime_or_timedelta, |
442 | 454 | granularity, |
455 | threshold=threshold, | |
443 | 456 | add_direction=add_direction, |
444 | 457 | locale=get_locale() |
445 | 458 | ) |
8 | 8 | self._kwargs = kwargs |
9 | 9 | |
10 | 10 | def __getattr__(self, attr): |
11 | if attr == "__setstate__": | |
12 | raise AttributeError(attr) | |
11 | 13 | string = text_type(self) |
12 | 14 | if hasattr(string, attr): |
13 | 15 | return getattr(string, attr) |
14 | 16 | raise AttributeError(attr) |
17 | ||
18 | def __repr__(self): | |
19 | return "l'{0}'".format(text_type(self)) | |
15 | 20 | |
16 | 21 | def __str__(self): |
17 | 22 | return text_type(self._func(*self._args, **self._kwargs)) |
0 | 0 | [upload_docs] |
1 | 1 | upload-dir = docs/_build/html |
2 | ||
3 | [metadata] | |
4 | description-file = README.md | |
2 | 5 | |
3 | 6 | [egg_info] |
4 | 7 | tag_build = |
5 | 8 | tag_date = 0 |
6 | tag_svn_revision = 0 | |
7 | 9 |
19 | 19 | |
20 | 20 | setup( |
21 | 21 | name='Flask-Babel', |
22 | version='0.11.1', | |
22 | version='0.11.2', | |
23 | 23 | url='http://github.com/python-babel/flask-babel', |
24 | 24 | license='BSD', |
25 | 25 | author='Armin Ronacher', |
4 | 4 | import os |
5 | 5 | sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..')) |
6 | 6 | |
7 | import pickle | |
8 | ||
7 | 9 | import unittest |
8 | 10 | from decimal import Decimal |
9 | 11 | import flask |
10 | from datetime import datetime | |
12 | from datetime import datetime, timedelta | |
11 | 13 | import flask_babel as babel |
12 | 14 | from flask_babel import gettext, ngettext, lazy_gettext, get_translations |
13 | 15 | from babel.support import NullTranslations |
52 | 54 | name='Peter' |
53 | 55 | ) == 'Hallo Peter!' |
54 | 56 | |
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 | ||
55 | 80 | def test_lazy_old_style_formatting(self): |
56 | 81 | lazy_string = lazy_gettext(u'Hello %(name)s') |
57 | 82 | assert lazy_string % {u'name': u'test'} == u'Hello test' |
59 | 84 | lazy_string = lazy_gettext(u'test') |
60 | 85 | assert u'Hello %s' % lazy_string == u'Hello test' |
61 | 86 | |
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 | ||
62 | 94 | |
63 | 95 | class DateFormattingTestCase(unittest.TestCase): |
64 | 96 | |
66 | 98 | app = flask.Flask(__name__) |
67 | 99 | babel.Babel(app) |
68 | 100 | d = datetime(2010, 4, 12, 13, 46) |
101 | delta = timedelta(days=6) | |
69 | 102 | |
70 | 103 | with app.test_request_context(): |
71 | 104 | assert babel.format_datetime(d) == 'Apr 12, 2010, 1:46:00 PM' |
72 | 105 | assert babel.format_date(d) == 'Apr 12, 2010' |
73 | 106 | 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' | |
74 | 109 | |
75 | 110 | with app.test_request_context(): |
76 | 111 | app.config['BABEL_DEFAULT_TIMEZONE'] = 'Europe/Vienna' |
Binary diff not shown
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 "" |