def test_default_locale(os_environ): for name in ['LANGUAGE', 'LC_ALL', 'LC_CTYPE', 'LC_MESSAGES']: os_environ[name] = '' os_environ['LANG'] = 'fr_FR.UTF-8' assert default_locale('LC_MESSAGES') == 'fr_FR' os_environ['LC_MESSAGES'] = 'POSIX' assert default_locale('LC_MESSAGES') == 'en_US_POSIX'
def test_default_locale(os_environ): for name in ["LANGUAGE", "LC_ALL", "LC_CTYPE", "LC_MESSAGES"]: os_environ[name] = "" os_environ["LANG"] = "fr_FR.UTF-8" assert default_locale("LC_MESSAGES") == "fr_FR" os_environ["LC_MESSAGES"] = "POSIX" assert default_locale("LC_MESSAGES") == "en_US_POSIX"
def get_local_date_filter(date_locale): if date_locale is None: date_locale = default_locale("LC_TIME") def local_date(value, date_format="dd MMMM yyyy"): return format_date(date=value, format=date_format, locale=date_locale) return local_date
def get_locale(locale=None, default='en_US_POSIX'): """Return default locale to use if one is not provided.""" if not locale: locale = default_locale('LC_TIME') if not locale: locale = default return locale
def get_locale(locale=None, default="en_US_POSIX"): """Return default locale to use if one is not provided.""" if not locale: locale = default_locale("LC_TIME") if not locale: locale = default return locale
# # This software is licensed as described in the file COPYING, which # you should have received as part of this distribution. The terms # are also available at http://babel.edgewall.org/wiki/License. # # This software consists of voluntary contributions made by many # individuals. For the exact contribution history, see the revision # history and logs, available at http://babel.edgewall.org/log/. """Plural form definitions.""" from babel.core import default_locale, Locale from operator import itemgetter LC_CTYPE = default_locale('LC_CTYPE') PLURALS = { # Afar # 'aa': (), # Abkhazian # 'ab': (), # Avestan # 'ae': (), # Afrikaans - From Pootle's PO's 'af': (2, '(n != 1)'), # Akan # 'ak': (), # Amharic # 'am': (),
import re from babel import Locale from babel.core import get_global, default_locale from .constants import ( OBSELETE_CURRENCIES, COMMON_ISO_CODES, OBSELETE_ISO_CODES, XCOMMON_ISO_CODES, ) from .money import add_currency DEFAULT_LOCALE = default_locale('LC_ALL') # This regex is used to find obselete currencies not in list CONTAINS_YEAR_REGEX = re.compile('.*([1-3][0-9]{3})') def _find_country_names_by_code( country_codes, locale, fallback_locale=None, force_upper=False ): if fallback_locale is None: fallback_locale = Locale.parse('en_US') countries = [] for country_code in country_codes: try: country = locale.territories[country_code] except KeyError: country = fallback_locale.territories.get(country_code, None)
def get_locale(): # TODO - G.M - 27-03-2018 - [i18n] Reconnect true internationalization return default_locale('LC_TIME')
""" from __future__ import division import re from pytz.gae import pytz as _pytz from datetime import date, datetime, time, timedelta from bisect import bisect_right from babel.core import default_locale, get_global, Locale from babel.util import UTC, LOCALTZ from babel._compat import string_types, integer_types, number_types LC_TIME = default_locale('LC_TIME') # Aliases for use in scopes where the modules are shadowed by local variables date_ = date datetime_ = datetime time_ = time def get_timezone(zone=None): """Looks up a timezone by name and returns it. The timezone object returned comes from ``pytz`` and corresponds to the `tzinfo` interface and can be used with all of the functions of Babel that operate with dates. If a timezone is not known a :exc:`LookupError` is raised. If `zone` is ``None`` a local zone object is returned.
# Copyright (C) 2007-2008 Edgewall Software # All rights reserved. # # This software is licensed as described in the file COPYING, which # you should have received as part of this distribution. The terms # are also available at http://babel.edgewall.org/wiki/License. # # This software consists of voluntary contributions made by many # individuals. For the exact contribution history, see the revision # history and logs, available at http://babel.edgewall.org/log/. """Plural form definitions.""" from babel.core import default_locale, Locale from babel.util import itemgetter LC_CTYPE = default_locale('LC_CTYPE') PLURALS = { # Afar # 'aa': (), # Abkhazian # 'ab': (), # Avestan # 'ae': (), # Afrikaans - From Pootle's PO's 'af': (2, '(n != 1)'), # Akan # 'ak': (), # Amharic # 'am': (), # Aragonese
def test_ignore_invalid_locales_in_lc_ctype(os_environ): # This is a regression test specifically for a bad LC_CTYPE setting on # MacOS X 10.6 (#200) os_environ['LC_CTYPE'] = 'UTF-8' # must not throw an exception default_locale('LC_CTYPE')
from babel.core import default_locale, get_global, Locale from babel.util import UTC __all__ = [ "format_date", "format_datetime", "format_time", "format_timedelta", "get_timezone_name", "parse_date", "parse_datetime", "parse_time", ] __docformat__ = "restructuredtext en" LC_TIME = default_locale("LC_TIME") # Aliases for use in scopes where the modules are shadowed by local variables date_ = date datetime_ = datetime time_ = time def get_period_names(locale=LC_TIME): """Return the names for day periods (AM/PM) used by the locale. >>> get_period_names(locale='en_US')['am'] u'AM' :param locale: the `Locale` object, or a locale string :return: the dictionary of period names
# # This software is licensed as described in the file COPYING, which # you should have received as part of this distribution. The terms # are also available at http://babel.edgewall.org/wiki/License. # # This software consists of voluntary contributions made by many # individuals. For the exact contribution history, see the revision # history and logs, available at http://babel.edgewall.org/log/. """Plural form definitions.""" from babel.core import default_locale, Locale from babel.util import itemgetter LC_CTYPE = default_locale("LC_CTYPE") PLURALS = { # Afar # 'aa': (), # Abkhazian # 'ab': (), # Avestan # 'ae': (), # Afrikaans - From Pootle's PO's "af": (2, "(n != 1)"), # Akan # 'ak': (), # Amharic # 'am': (),
#: Character to render for zero line units ZERO_MARK = u'▓' #: Printable character to render for zero line units PRINTABLE_ZERO_MARK = u'|' #: Character to render for axis ticks TICK_MARK = u'+' #: Characters to render for ellipsis ELLIPSIS = u'...' # Get the default locale for number formatting # (Falls back to English to work around a Windows bug) LC_NUMERIC = default_locale('LC_NUMERIC') or 'en_US' def print_table(table, max_rows=None, max_columns=None, output=sys.stdout, max_column_width=None, locale=None): """ See :meth:`.Table.print_table` for documentation. """ if max_rows is None: max_rows = len(table.rows) if max_columns is None:
# - http://www.unicode.org/reports/tr35/ (Appendix G.6) import re from datetime import date as date_, datetime as datetime_ import warnings from babel.core import default_locale, Locale, get_global from babel._compat import decimal, string_types try: # Python 2 long except NameError: # Python 3 long = int LC_NUMERIC = default_locale("LC_NUMERIC") class UnknownCurrencyError(Exception): """Exception thrown when a currency is requested for which no data is available. """ def __init__(self, identifier): """Create the exception. :param identifier: the identifier string of the unsupported currency """ Exception.__init__(self, "Unknown currency %r." % identifier) #: The identifier of the locale that could not be found. self.identifier = identifier
Locale dependent formatting of lists. The default locale for the functions in this module is determined by the following environment variables, in that order: * ``LC_ALL``, and * ``LANG`` :copyright: (c) 2015-2019 by the Babel Team. :license: BSD, see LICENSE for more details. """ from babel.core import Locale, default_locale DEFAULT_LOCALE = default_locale() def format_list(lst, style='standard', locale=DEFAULT_LOCALE): """ Format the items in `lst` as a list. >>> format_list(['apples', 'oranges', 'pears'], locale='en') u'apples, oranges, and pears' >>> format_list(['apples', 'oranges', 'pears'], locale='zh') u'apples\u3001oranges\u548cpears' >>> format_list(['omena', 'peruna', 'aplari'], style='or', locale='fi') u'omena, peruna tai aplari' These styles are defined, but not all are necessarily available in all locales. The following text is verbatim from the Unicode TR35-49 spec [1].
Locale dependent formatting of lists. The default locale for the functions in this module is determined by the following environment variables, in that order: * ``LC_ALL``, and * ``LANG`` :copyright: (c) 2015-2020 by the Babel Team. :license: BSD, see LICENSE for more details. """ from babel.core import Locale, default_locale DEFAULT_LOCALE = default_locale() def format_list(lst, style='standard', locale=DEFAULT_LOCALE): """ Format the items in `lst` as a list. >>> format_list(['apples', 'oranges', 'pears'], locale='en') u'apples, oranges, and pears' >>> format_list(['apples', 'oranges', 'pears'], locale='zh') u'apples\u3001oranges\u548cpears' >>> format_list(['omena', 'peruna', 'aplari'], style='or', locale='fi') u'omena, peruna tai aplari' These styles are defined, but not all are necessarily available in all locales. The following text is verbatim from the Unicode TR35-49 spec [1].
""" babel.messages.plurals ~~~~~~~~~~~~~~~~~~~~~~ Plural form definitions. :copyright: (c) 2013-2018 by the Babel Team. :license: BSD, see LICENSE for more details. """ from babel.core import default_locale, Locale from operator import itemgetter # XXX: remove this file, duplication with babel.plural LC_CTYPE = default_locale("LC_CTYPE") PLURALS = { # Afar # 'aa': (), # Abkhazian # 'ab': (), # Avestan # 'ae': (), # Afrikaans - From Pootle's PO's "af": (2, "(n != 1)"), # Akan # 'ak': (), # Amharic # 'am': (), # Aragonese
def get_locale(): # TODO - G.M - 27-03-2018 - [i18n] Reconnect true internationalization return default_locale("LC_TIME")
from babel.core import default_locale, Locale from babel.util import rsplit __all__ = [ "format_number", "format_decimal", "format_currency", "format_percent", "format_scientific", "parse_number", "parse_decimal", "NumberFormatError", ] __docformat__ = "restructuredtext en" LC_NUMERIC = default_locale("LC_NUMERIC") def get_currency_name(currency, locale=LC_NUMERIC): """Return the name used by the locale for the specified currency. >>> get_currency_name('USD', 'en_US') u'US Dollar' :param currency: the currency code :param locale: the `Locale` object or locale identifier :return: the currency symbol :rtype: `unicode` :since: version 0.9.4 """ return Locale.parse(locale).currencies.get(currency, currency)
import re from datetime import date as date_, datetime as datetime_ import warnings from babel.core import default_locale, Locale, get_global from babel._compat import decimal, string_types try: # Python 2 long except NameError: # Python 3 long = int LC_NUMERIC = default_locale('LC_NUMERIC') class UnknownCurrencyError(Exception): """Exception thrown when a currency is requested for which no data is available. """ def __init__(self, identifier): """Create the exception. :param identifier: the identifier string of the unsupported currency """ Exception.__init__(self, 'Unknown currency %r.' % identifier) #: The identifier of the locale that could not be found. self.identifier = identifier
| zero_line_char | Character to render for zero line units | u'▓' | +-------------------------+------------------------------------------+-----------------------------------------+ | printable_zero_line_char| Printable character for zero line units | u'|' | +-------------------------+------------------------------------------+-----------------------------------------+ | tick_char | Character to render for axis ticks | u'+' | +-------------------------+------------------------------------------+-----------------------------------------+ | ellipsis_chars | Characters to render for ellipsis | u'...' | +-------------------------+------------------------------------------+-----------------------------------------+ """ from babel.core import default_locale _options = { #: Default locale for number formatting 'default_locale': default_locale('LC_NUMERIC') or 'en_US', #: Character to render for horizontal lines 'horizontal_line_char': u'-', #: Character to render for vertical lines 'vertical_line_char': u'|', #: Character to render for bar chart units 'bar_char': u'░', #: Printable character to render for bar chart units 'printable_bar_char': u':', #: Character to render for zero line units 'zero_line_char': u'▓', #: Printable character to render for zero line units 'printable_zero_line_char': u'|', #: Character to render for axis ticks 'tick_char': u'+', #: Characters to render for ellipsis
* ``LANG`` :copyright: (c) 2013 by the Babel Team. :license: BSD, see LICENSE for more details. """ # TODO: # Padding and rounding increments in pattern: # - http://www.unicode.org/reports/tr35/ (Appendix G.6) import re from datetime import date as date_, datetime as datetime_ from babel.core import default_locale, Locale, get_global from babel._compat import Decimal, InvalidOperation, ROUND_HALF_EVEN LC_NUMERIC = default_locale('LC_NUMERIC') def get_currency_name(currency, count=None, locale=LC_NUMERIC): """Return the name used by the locale for the specified currency. >>> get_currency_name('USD', locale='en_US') u'US Dollar' .. versionadded:: 0.9.4 :param currency: the currency code :param count: the optional count. If provided the currency name will be pluralized to that number if possible. :param locale: the `Locale` object or locale identifier """
PRINTABLE_BAR_MARK = u':' #: Character to render for zero line units ZERO_MARK = u'▓' #: Printable character to render for zero line units PRINTABLE_ZERO_MARK = u'|' #: Character to render for axis ticks TICK_MARK = u'+' #: Characters to render for ellipsis ELLIPSIS = u'...' #: Default locale for number formatting LC_NUMERIC = default_locale('LC_NUMERIC') or 'en_US' #: Sentinal for use when `None` is an valid argument value default = object() def memoize(func): """ Dead-simple memoize decorator for instance methods that take no arguments. This is especially useful since so many of our classes are immutable. """ memo = None @wraps(func) def wrapper(self):
""" from datetime import date, datetime, time, timedelta, tzinfo import re from babel.core import default_locale, get_global, Locale from babel.numbers import get_decimal_symbol from babel.util import UTC __all__ = [ 'format_date', 'format_datetime', 'format_time', 'get_timezone_name', 'parse_date', 'parse_datetime', 'parse_time' ] __docformat__ = 'restructuredtext en' LC_TIME = default_locale('LC_TIME') # Aliases for use in scopes where the modules are shadowed by local variables date_ = date datetime_ = datetime time_ = time def get_period_names(locale=LC_TIME): """Return the names for day periods (AM/PM) used by the locale. >>> get_period_names(locale='en_US')['am'] u'AM' :param locale: the `Locale` object, or a locale string :return: the dictionary of period names
+-------------------------+------------------------------------------+-----------------------------------------+ | printable_zero_line_char| Printable character for zero line units | u'|' | +-------------------------+------------------------------------------+-----------------------------------------+ | tick_char | Character to render for axis ticks | u'+' | +-------------------------+------------------------------------------+-----------------------------------------+ | ellipsis_chars | Characters to render for ellipsis | u'...' | +-------------------------+------------------------------------------+-----------------------------------------+ """ from babel.core import default_locale _options = { #: Default locale for number formatting 'default_locale': default_locale('LC_NUMERIC') or 'en_US', #: Character to render for horizontal lines 'horizontal_line_char': u'-', #: Character to render for vertical lines 'vertical_line_char': u'|', #: Character to render for bar chart units 'bar_char': u'░', #: Printable character to render for bar chart units 'printable_bar_char': u':', #: Character to render for zero line units 'zero_line_char': u'▓', #: Printable character to render for zero line units 'printable_zero_line_char': u'|', #: Character to render for axis ticks 'tick_char': u'+', #: Characters to render for ellipsis