:tocdepth: 3 :py:mod:`gws.lib.intl` ====================== .. py:module:: gws.lib.intl .. autoapi-nested-parse:: Intl and localization tools. **Source code:** :source:`gws.lib.intl` Package Contents ---------------- .. py:class:: DateFormatter(loc: gws.Locale) Bases: :py:obj:`gws.DateFormatter` Locale-aware date formatter. .. py:attribute:: iso Returns the date in the ISO 8601 format ``2013-12-11``. .. py:attribute:: locale .. py:attribute:: long Returns the date in the medium format ``11. Dezember 2013``. .. py:attribute:: medium Returns the date in the medium format ``11.12.2013``. .. py:attribute:: short Returns the date in the short format ``11.12.13``. .. py:method:: format(fmt: gws.DateTimeFormat, date=None) Formats the date. :param fmt: Format type or a `strftime` format string :param date: Date, if none is given the current date will be used as default. :returns: A formatted date string. .. py:function:: default_locale() Returns the default locale object (``en_CA``). .. py:function:: formatters(loc: gws.Locale) -> tuple[DateFormatter, TimeFormatter, NumberFormatter] Return a tuple of locale-aware formatters. .. py:function:: locale(name: str | None, allowed: list[str] = None, fallback: bool = True) -> gws.Locale Locates a Locale object by locale name. If the name is invalid, and ``fallback`` is ``True``, return the first ``allowed`` locale, or the default locale. Otherwise, raise an exception. :param name: Language or locale name like ``de`` or ``de_DE``. :param allowed: A list of allowed locale uids. :param fallback: Fall back to the default locale. .. py:class:: NumberFormatter(loc: gws.Locale) Bases: :py:obj:`gws.NumberFormatter` Locale-aware number formatter. .. py:attribute:: fns .. py:attribute:: locale .. py:method:: currency(n, currency, *args, **kwargs) Returns formatted currency value. .. py:method:: decimal(n, *args, **kwargs) Returns formatted decimal value. .. py:method:: format(fmt, n, *args, **kwargs) Formats the number with respect to the locale. :param fmt: Format type or a python `format` string :param n: Number. :param kwargs: Passes the currency parameter forward. :returns: A formatted number. .. py:method:: grouped(n, *args, **kwargs) Returns formatted decimal value with group separators. .. py:method:: percent(n, *args, **kwargs) Returns formatted percent value. .. py:class:: TimeFormatter(loc: gws.Locale) Bases: :py:obj:`gws.TimeFormatter` Locale-aware time formatter. .. py:attribute:: iso Returns the time and date in the ISO 8601 format. .. py:attribute:: locale .. py:attribute:: long Returns the time in the medium format ``11:22:33``. .. py:attribute:: medium Returns the time in the medium format ``11:22:33``. .. py:attribute:: short Returns the time in the short format ``11:22``. .. py:method:: format(fmt: gws.DateTimeFormat, date=None) -> str Formats the time. :param fmt: Format type or a `strftime` format string :param time: Time, if none is given the current time will be used as default. :returns: A formatted time string.