- Explicitly sort instead of using sorted() and don't assume ordering
(Jython compatibility).
- Removed ValueError raising for string formatting message checkers if the
- string does not contain any string formattings (:trac:`150`).
+ string does not contain any string formatting (:trac:`150`).
- Fix Serbian plural forms (:trac:`213`).
- Small speed improvement in format_date() (:trac:`216`).
- Fix so frontend.CommandLineInterface.run does not accumulate logging
- Explicitly sort instead of using sorted() and don't assume ordering
(Python 2.3 and Jython compatibility).
- Removed ValueError raising for string formatting message checkers if the
- string does not contain any string formattings (:trac:`150`).
+ string does not contain any string formatting (:trac:`150`).
- Fix Serbian plural forms (:trac:`213`).
- Small speed improvement in format_date() (:trac:`216`).
- Fix number formatting for locales where CLDR specifies alt or draft
:license: BSD, see LICENSE for more details.
"""
-from babel.core import UnknownLocaleError, Locale, default_locale, \
- negotiate_locale, parse_locale, get_locale_identifier
-
+from babel.core import (
+ Locale,
+ UnknownLocaleError,
+ default_locale,
+ get_locale_identifier,
+ negotiate_locale,
+ parse_locale,
+)
__version__ = '2.11.0'
+
+__all__ = [
+ 'Locale',
+ 'UnknownLocaleError',
+ 'default_locale',
+ 'get_locale_identifier',
+ 'negotiate_locale',
+ 'parse_locale',
+]
>>> Locale.negotiate(['de_DE', 'de'], ['en_US'])
You can specify the character used in the locale identifiers to separate
- the differnet components. This separator is applied to both lists. Also,
+ the different components. This separator is applied to both lists. Also,
case is ignored in the comparison:
>>> Locale.negotiate(['de-DE', 'de'], ['en-us', 'de-de'], sep='-')
Locale('de', territory='DE')
- :param preferred: the list of locale identifers preferred by the user
+ :param preferred: the list of locale identifiers preferred by the user
:param available: the list of locale identifiers available
:param aliases: a dictionary of aliases for locale identifiers
"""
:param day_of_period: the number of the day in the period (usually
either the day of month or the day of year)
- :param day_of_week: the week day; if ommitted, the week day of the
+ :param day_of_week: the week day; if omitted, the week day of the
current date is assumed
"""
if day_of_week is None:
:param merge_inherited: whether the inherited data should be merged into
the data of the requested locale
:raise `IOError`: if no locale data file is found for the given locale
- identifer, or one of the locales it inherits from
+ identifier, or one of the locales it inherits from
"""
name = os.path.basename(name)
_cache_lock.acquire()
:license: BSD, see LICENSE for more details.
"""
-from babel.messages.catalog import *
+from babel.messages.catalog import (
+ Catalog,
+ Message,
+ TranslationError,
+)
+
+__all__ = [
+ "Catalog",
+ "Message",
+ "TranslationError",
+]
placeholders if `format` uses named placeholders.
The behavior of this function is undefined if the string does not use
- string formattings.
+ string formatting.
If the string formatting of `alternative` is compatible to `format` the
function returns `None`, otherwise a `TranslationError` is raised.
messages = tuple(messages)
else:
messages = messages[0]
- # Comments don't apply unless they immediately preceed the
- # message
+ # Comments don't apply unless they immediately
+ # precede the message
if translator_comments and \
translator_comments[-1][0] < message_lineno - 1:
translator_comments = []
break
elif token.type == 'multilinecomment':
- # only one multi-line comment may preceed a translation
+ # only one multi-line comment may precede a translation
translator_comments = []
value = token.value[2:-2].strip()
for comment_tag in comment_tags:
def normalize_currency(currency: str, locale: Locale | str | None = None) -> str | None:
- """Returns the normalized sting of any currency code.
+ """Returns the normalized identifier of any currency code.
Accepts a ``locale`` parameter for fined-grained validation, working as
the one defined above in ``list_currencies()`` method.
self._format_int(
str(exp), self.exp_prec[0], self.exp_prec[1], locale)])
- # Is it a siginificant digits pattern?
+ # Is it a significant digits pattern?
elif '@' in self.pattern:
text = self._format_significant(value,
self.int_prec[0],
'n in 3,5,7..15'.
- Samples are ignored.
- The translator parses the expression on instanciation into an attribute
+ The translator parses the expression on instantiation into an attribute
called `ast`.
"""
# backward compatibility with 0.9
dungettext = udngettext
- # Most of the downwards code, until it get's included in stdlib, from:
+ # Most of the downwards code, until it gets included in stdlib, from:
# https://bugs.python.org/file10036/gettext-pgettext.patch
#
# The encoding of a msgctxt and a msgid in a .mo file is
import os
import pytest
+try:
+ import zoneinfo
+except ModuleNotFoundError:
+ try:
+ from backports import zoneinfo
+ except ImportError:
+ zoneinfo = None
+
+try:
+ import pytz
+except ModuleNotFoundError:
+ pytz = None
+
@pytest.fixture
def os_environ(monkeypatch):
from babel.localedata import locale_identifiers
metafunc.parametrize("locale", list(locale_identifiers()))
break
+
+
+@pytest.fixture(params=["pytz.timezone", "zoneinfo.ZoneInfo"], scope="package")
+def timezone_getter(request):
+ if request.param == "pytz.timezone":
+ if pytz:
+ return pytz.timezone
+ else:
+ pytest.skip("pytz not available")
+ elif request.param == "zoneinfo.ZoneInfo":
+ if zoneinfo:
+ return zoneinfo.ZoneInfo
+ else:
+ pytest.skip("zoneinfo not available")
+ else:
+ raise NotImplementedError
from babel import dates
from babel.util import UTC
-from .test_dates import timezone_getter
TEST_DT = datetime.datetime(2016, 1, 8, 11, 46, 15)
TEST_TIME = TEST_DT.time()
import freezegun
import pytest
-# for tests it can be useful to have both zoneinfo and pytz available
-try:
- import zoneinfo
-except ModuleNotFoundError:
- try:
- from backports import zoneinfo
- except ImportError:
- zoneinfo = None
-
-try:
- import pytz
-except ModuleNotFoundError:
- pytz = None
-
from babel import dates, Locale
-from babel.dates import NO_INHERITANCE_MARKER, _localize, _get_tz_name, LOCALTZ
+from babel.dates import NO_INHERITANCE_MARKER, _localize
from babel.util import FixedOffsetTimezone
-@pytest.fixture(params=["pytz.timezone", "zoneinfo.ZoneInfo"], scope="package")
-def timezone_getter(request):
- if request.param == "pytz.timezone":
- if pytz:
- return pytz.timezone
- else:
- pytest.skip("pytz not available")
- elif request.param == "zoneinfo.ZoneInfo":
- if zoneinfo:
- return zoneinfo.ZoneInfo
- else:
- pytest.skip("zoneinfo not available")
- else:
- raise NotImplementedError
-
-
class DateTimeFormatTestCase:
def test_quarter_format(self):
assert numbers.format_decimal(12345, '##0', locale='en_US') == '12345'
assert numbers.format_decimal(6.5, '0.00', locale='sv') == '6,50'
assert numbers.format_decimal((10.0 ** 20), '#.00', locale='en_US') == '100000000000000000000.00'
- # regression test for #183, fraction digits were not correctly cutted
+ # regression test for #183, fraction digits were not correctly cut
# if the input was a float value and the value had more than 7
# significant digits
assert numbers.format_decimal(12345678.051, '#,##0.00', locale='en_US') == u'12,345,678.05'
from babel import support
from babel.messages import Catalog
from babel.messages.mofile import write_mo
-from babel.dates import get_timezone
-from .test_dates import timezone_getter
SKIP_LGETTEXT = sys.version_info >= (3, 8)