retval += f" ({detail_string})"
return retval
- display_name = property(
- get_display_name,
- doc="""\
+ @property
+ def display_name(self) -> str | None:
+ """
The localized display name of the locale.
>>> Locale('en').display_name
'English (United States)'
>>> Locale('sv').display_name
'svenska'
-
- :type: `unicode`
- """,
- )
+ """
+ return self.get_display_name()
def get_language_name(self, locale: Locale | str | None = None) -> str | None:
"""Return the language of this locale in the given locale.
locale = Locale.parse(locale)
return locale.languages.get(self.language)
- language_name = property(
- get_language_name,
- doc="""\
+ @property
+ def language_name(self) -> str | None:
+ """
The localized language name of the locale.
>>> Locale('en', 'US').language_name
'English'
- """,
- )
+ """
+ return self.get_language_name()
def get_territory_name(self, locale: Locale | str | None = None) -> str | None:
"""Return the territory name in the given locale."""
locale = Locale.parse(locale)
return locale.territories.get(self.territory or '')
- territory_name = property(
- get_territory_name,
- doc="""\
+ @property
+ def territory_name(self) -> str | None:
+ """
The localized territory name of the locale if available.
>>> Locale('de', 'DE').territory_name
'Deutschland'
- """,
- )
+ """
+ return self.get_territory_name()
def get_script_name(self, locale: Locale | str | None = None) -> str | None:
"""Return the script name in the given locale."""
locale = Locale.parse(locale)
return locale.scripts.get(self.script or '')
- script_name = property(
- get_script_name,
- doc="""\
+ @property
+ def script_name(self) -> str | None:
+ """
The localized script name of the locale if available.
>>> Locale('sr', 'ME', script='Latn').script_name
'latinica'
- """,
- )
+ """
+ return self.get_script_name()
@property
def english_name(self) -> str | None:
'German'
>>> Locale('de', 'DE').english_name
'German (Germany)'
-
- :type: `unicode`"""
+ """
return self.get_display_name(Locale('en'))
# { General Locale Display Names
True
>>> msg
<Message 'foo' (flags: ['fuzzy'])>
-
- :type: `bool`"""
+ """
return 'fuzzy' in self.flags
@property
False
>>> Message(('foo', 'bar')).pluralizable
True
-
- :type: `bool`"""
+ """
return isinstance(self.id, (list, tuple))
@property
True
>>> Message(('foo %(name)s', 'foo %(name)s')).python_format
True
-
- :type: `bool`"""
+ """
ids = self.id
if isinstance(ids, (list, tuple)):
for id in ids: # Explicit loop for performance reasons.
True
>>> Message(('One apple', '{count} apples')).python_brace_format
True
-
- :type: `bool`"""
+ """
ids = self.id
if isinstance(ids, (list, tuple)):
for id in ids: # Explicit loop for performance reasons.
f"`locale` must be a Locale, a locale identifier string, or None; got {locale!r}",
)
- def _get_locale(self) -> Locale | None:
+ @property
+ def locale(self) -> Locale | None:
return self._locale
- def _get_locale_identifier(self) -> str | None:
- return self._locale_identifier
+ @locale.setter
+ def locale(self, locale: Locale | str | None) -> None:
+ self._set_locale(locale)
- locale = property(_get_locale, _set_locale)
- locale_identifier = property(_get_locale_identifier)
+ @property
+ def locale_identifier(self) -> str | None:
+ return self._locale_identifier
def _get_header_comment(self) -> str:
comment = self._header_comment
def _set_header_comment(self, string: str | None) -> None:
self._header_comment = string
- header_comment = property(
- _get_header_comment,
- _set_header_comment,
- doc="""\
- The header comment for the catalog.
-
- >>> catalog = Catalog(project='Foobar', version='1.0',
- ... copyright_holder='Foo Company')
- >>> print(catalog.header_comment) #doctest: +ELLIPSIS
- # Translations template for Foobar.
- # Copyright (C) ... Foo Company
- # This file is distributed under the same license as the Foobar project.
- # FIRST AUTHOR <EMAIL@ADDRESS>, ....
- #
-
- The header can also be set from a string. Any known upper-case variables
- will be replaced when the header is retrieved again:
-
- >>> catalog = Catalog(project='Foobar', version='1.0',
- ... copyright_holder='Foo Company')
- >>> catalog.header_comment = '''\\
- ... # The POT for my really cool PROJECT project.
- ... # Copyright (C) 1990-2003 ORGANIZATION
- ... # This file is distributed under the same license as the PROJECT
- ... # project.
- ... #'''
- >>> print(catalog.header_comment)
- # The POT for my really cool Foobar project.
- # Copyright (C) 1990-2003 Foo Company
- # This file is distributed under the same license as the Foobar
- # project.
- #
-
- :type: `unicode`
- """,
- )
+ @property
+ def header_comment(self) -> str:
+ """
+ The header comment for the catalog.
+
+ >>> catalog = Catalog(project='Foobar', version='1.0',
+ ... copyright_holder='Foo Company')
+ >>> print(catalog.header_comment) #doctest: +ELLIPSIS
+ # Translations template for Foobar.
+ # Copyright (C) ... Foo Company
+ # This file is distributed under the same license as the Foobar project.
+ # FIRST AUTHOR <EMAIL@ADDRESS>, ....
+ #
+
+ The header can also be set from a string. Any known upper-case variables
+ will be replaced when the header is retrieved again:
+
+ >>> catalog = Catalog(project='Foobar', version='1.0',
+ ... copyright_holder='Foo Company')
+ >>> catalog.header_comment = '''\\
+ ... # The POT for my really cool PROJECT project.
+ ... # Copyright (C) 1990-2003 ORGANIZATION
+ ... # This file is distributed under the same license as the PROJECT
+ ... # project.
+ ... #'''
+ >>> print(catalog.header_comment)
+ # The POT for my really cool Foobar project.
+ # Copyright (C) 1990-2003 Foo Company
+ # This file is distributed under the same license as the Foobar
+ # project.
+ #
+ """
+ return self._get_header_comment()
+
+ @header_comment.setter
+ def header_comment(self, value: str) -> None:
+ self._set_header_comment(value)
def _get_mime_headers(self) -> list[tuple[str, str]]:
if isinstance(self.revision_date, (datetime.datetime, datetime.time, int, float)):
if 'YEAR' not in value:
self.revision_date = _parse_datetime_header(value)
- mime_headers = property(
- _get_mime_headers,
- _set_mime_headers,
- doc="""\
- The MIME headers of the catalog, used for the special ``msgid ""`` entry.
-
- The behavior of this property changes slightly depending on whether a locale
- is set or not, the latter indicating that the catalog is actually a template
- for actual translations.
-
- Here's an example of the output for such a catalog template:
-
- >>> from babel.dates import UTC
- >>> from datetime import datetime
- >>> created = datetime(1990, 4, 1, 15, 30, tzinfo=UTC)
- >>> catalog = Catalog(project='Foobar', version='1.0',
- ... creation_date=created)
- >>> for name, value in catalog.mime_headers:
- ... print('%s: %s' % (name, value))
- Project-Id-Version: Foobar 1.0
- Report-Msgid-Bugs-To: EMAIL@ADDRESS
- POT-Creation-Date: 1990-04-01 15:30+0000
- PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE
- Last-Translator: FULL NAME <EMAIL@ADDRESS>
- Language-Team: LANGUAGE <LL@li.org>
- MIME-Version: 1.0
- Content-Type: text/plain; charset=utf-8
- Content-Transfer-Encoding: 8bit
- Generated-By: Babel ...
-
- And here's an example of the output when the locale is set:
-
- >>> revised = datetime(1990, 8, 3, 12, 0, tzinfo=UTC)
- >>> catalog = Catalog(locale='de_DE', project='Foobar', version='1.0',
- ... creation_date=created, revision_date=revised,
- ... last_translator='John Doe <jd@example.com>',
- ... language_team='de_DE <de@example.com>')
- >>> for name, value in catalog.mime_headers:
- ... print('%s: %s' % (name, value))
- Project-Id-Version: Foobar 1.0
- Report-Msgid-Bugs-To: EMAIL@ADDRESS
- POT-Creation-Date: 1990-04-01 15:30+0000
- PO-Revision-Date: 1990-08-03 12:00+0000
- Last-Translator: John Doe <jd@example.com>
- Language: de_DE
- Language-Team: de_DE <de@example.com>
- Plural-Forms: nplurals=2; plural=(n != 1);
- MIME-Version: 1.0
- Content-Type: text/plain; charset=utf-8
- Content-Transfer-Encoding: 8bit
- Generated-By: Babel ...
-
- :type: `list`
- """,
- )
+ @property
+ def mime_headers(self) -> list[tuple[str, str]]:
+ """
+ The MIME headers of the catalog, used for the special ``msgid ""`` entry.
+
+ The behavior of this property changes slightly depending on whether a locale
+ is set or not, the latter indicating that the catalog is actually a template
+ for actual translations.
+
+ Here's an example of the output for such a catalog template:
+
+ >>> from babel.dates import UTC
+ >>> from datetime import datetime
+ >>> created = datetime(1990, 4, 1, 15, 30, tzinfo=UTC)
+ >>> catalog = Catalog(project='Foobar', version='1.0',
+ ... creation_date=created)
+ >>> for name, value in catalog.mime_headers:
+ ... print('%s: %s' % (name, value))
+ Project-Id-Version: Foobar 1.0
+ Report-Msgid-Bugs-To: EMAIL@ADDRESS
+ POT-Creation-Date: 1990-04-01 15:30+0000
+ PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE
+ Last-Translator: FULL NAME <EMAIL@ADDRESS>
+ Language-Team: LANGUAGE <LL@li.org>
+ MIME-Version: 1.0
+ Content-Type: text/plain; charset=utf-8
+ Content-Transfer-Encoding: 8bit
+ Generated-By: Babel ...
+
+ And here's an example of the output when the locale is set:
+
+ >>> revised = datetime(1990, 8, 3, 12, 0, tzinfo=UTC)
+ >>> catalog = Catalog(locale='de_DE', project='Foobar', version='1.0',
+ ... creation_date=created, revision_date=revised,
+ ... last_translator='John Doe <jd@example.com>',
+ ... language_team='de_DE <de@example.com>')
+ >>> for name, value in catalog.mime_headers:
+ ... print('%s: %s' % (name, value))
+ Project-Id-Version: Foobar 1.0
+ Report-Msgid-Bugs-To: EMAIL@ADDRESS
+ POT-Creation-Date: 1990-04-01 15:30+0000
+ PO-Revision-Date: 1990-08-03 12:00+0000
+ Last-Translator: John Doe <jd@example.com>
+ Language: de_DE
+ Language-Team: de_DE <de@example.com>
+ Plural-Forms: nplurals=2; plural=(n != 1);
+ MIME-Version: 1.0
+ Content-Type: text/plain; charset=utf-8
+ Content-Transfer-Encoding: 8bit
+ Generated-By: Babel ...
+ """
+ return self._get_mime_headers()
+
+ @mime_headers.setter
+ def mime_headers(self, value: Iterable[tuple[str, str]]) -> None:
+ self._set_mime_headers(value)
@property
def num_plurals(self) -> int:
2
>>> Catalog(locale='ga').num_plurals
5
-
- :type: `int`"""
+ """
if self._num_plurals is None:
num = 2
if self.locale:
'(n == 1 ? 0 : n == 2 ? 1 : n >= 3 && n <= 6 ? 2 : n >= 7 && n <= 10 ? 3 : 4)'
>>> Catalog(locale='ding').plural_expr # unknown locale
'(n != 1)'
-
- :type: `str`"""
+ """
if self._plural_expr is None:
expr = '(n != 1)'
if self.locale:
'nplurals=2; plural=(n != 1);'
>>> Catalog(locale='pt_BR').plural_forms
'nplurals=3; plural=(n == 0 || n == 1) ? 0 : n != 0 && n % 1000000 == 0 ? 1 : 2;'
-
- :type: `str`"""
+ """
return f"nplurals={self.num_plurals}; plural={self.plural_expr};"
def __contains__(self, id: _MessageID) -> bool: