| 1 |
import io |
| 2 |
import sys |
| 3 |
from _typeshed import StrPath |
| 4 |
from collections.abc import Callable, Container, Iterable, Sequence |
| 5 |
from typing import Any, Final, Literal, Protocol, TypeVar, overload, type_check_only |
| 6 |
from typing_extensions import deprecated |
| 7 |
|
| 8 |
__all__ = [ |
| 9 |
"NullTranslations", |
| 10 |
"GNUTranslations", |
| 11 |
"Catalog", |
| 12 |
"find", |
| 13 |
"translation", |
| 14 |
"install", |
| 15 |
"textdomain", |
| 16 |
"bindtextdomain", |
| 17 |
"dgettext", |
| 18 |
"dngettext", |
| 19 |
"gettext", |
| 20 |
"ngettext", |
| 21 |
"dnpgettext", |
| 22 |
"dpgettext", |
| 23 |
"npgettext", |
| 24 |
"pgettext", |
| 25 |
] |
| 26 |
|
| 27 |
if sys.version_info < (3, 11): |
| 28 |
__all__ += ["bind_textdomain_codeset", "ldgettext", "ldngettext", "lgettext", "lngettext"] |
| 29 |
|
| 30 |
@type_check_only |
| 31 |
class _TranslationsReader(Protocol): |
| 32 |
def read(self) -> bytes: ... |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
class NullTranslations: |
| 37 |
def __init__(self, fp: _TranslationsReader | None = None) -> None: ... |
| 38 |
def _parse(self, fp: _TranslationsReader) -> None: ... |
| 39 |
def add_fallback(self, fallback: NullTranslations) -> None: ... |
| 40 |
def gettext(self, message: str) -> str: ... |
| 41 |
def ngettext(self, msgid1: str, msgid2: str, n: int) -> str: ... |
| 42 |
def pgettext(self, context: str, message: str) -> str: ... |
| 43 |
def npgettext(self, context: str, msgid1: str, msgid2: str, n: int) -> str: ... |
| 44 |
def info(self) -> dict[str, str]: ... |
| 45 |
def charset(self) -> str | None: ... |
| 46 |
if sys.version_info < (3, 11): |
| 47 |
@deprecated("Deprecated since Python 3.8; removed in Python 3.11.") |
| 48 |
def output_charset(self) -> str | None: ... |
| 49 |
@deprecated("Deprecated since Python 3.8; removed in Python 3.11.") |
| 50 |
def set_output_charset(self, charset: str) -> None: ... |
| 51 |
@deprecated("Deprecated since Python 3.8; removed in Python 3.11. Use `gettext()` instead.") |
| 52 |
def lgettext(self, message: str) -> str: ... |
| 53 |
@deprecated("Deprecated since Python 3.8; removed in Python 3.11. Use `ngettext()` instead.") |
| 54 |
def lngettext(self, msgid1: str, msgid2: str, n: int) -> str: ... |
| 55 |
|
| 56 |
def install(self, names: Container[str] | None = None) -> None: ... |
| 57 |
|
| 58 |
class GNUTranslations(NullTranslations): |
| 59 |
LE_MAGIC: Final[int] |
| 60 |
BE_MAGIC: Final[int] |
| 61 |
CONTEXT: str |
| 62 |
VERSIONS: Sequence[int] |
| 63 |
|
| 64 |
@overload |
| 65 |
def find( |
| 66 |
domain: str, localedir: StrPath | None = None, languages: Iterable[str] | None = None, all: Literal[False] = False |
| 67 |
) -> str | None: ... |
| 68 |
@overload |
| 69 |
def find( |
| 70 |
domain: str, localedir: StrPath | None = None, languages: Iterable[str] | None = None, *, all: Literal[True] |
| 71 |
) -> list[str]: ... |
| 72 |
@overload |
| 73 |
def find(domain: str, localedir: StrPath | None, languages: Iterable[str] | None, all: Literal[True]) -> list[str]: ... |
| 74 |
@overload |
| 75 |
def find(domain: str, localedir: StrPath | None = None, languages: Iterable[str] | None = None, all: bool = False) -> Any: ... |
| 76 |
|
| 77 |
_NullTranslationsT = TypeVar("_NullTranslationsT", bound=NullTranslations) |
| 78 |
|
| 79 |
if sys.version_info >= (3, 11): |
| 80 |
@overload |
| 81 |
def translation( |
| 82 |
domain: str, |
| 83 |
localedir: StrPath | None = None, |
| 84 |
languages: Iterable[str] | None = None, |
| 85 |
class_: None = None, |
| 86 |
fallback: Literal[False] = False, |
| 87 |
) -> GNUTranslations: ... |
| 88 |
@overload |
| 89 |
def translation( |
| 90 |
domain: str, |
| 91 |
localedir: StrPath | None = None, |
| 92 |
languages: Iterable[str] | None = None, |
| 93 |
*, |
| 94 |
class_: Callable[[io.BufferedReader], _NullTranslationsT], |
| 95 |
fallback: Literal[False] = False, |
| 96 |
) -> _NullTranslationsT: ... |
| 97 |
@overload |
| 98 |
def translation( |
| 99 |
domain: str, |
| 100 |
localedir: StrPath | None, |
| 101 |
languages: Iterable[str] | None, |
| 102 |
class_: Callable[[io.BufferedReader], _NullTranslationsT], |
| 103 |
fallback: Literal[False] = False, |
| 104 |
) -> _NullTranslationsT: ... |
| 105 |
@overload |
| 106 |
def translation( |
| 107 |
domain: str, |
| 108 |
localedir: StrPath | None = None, |
| 109 |
languages: Iterable[str] | None = None, |
| 110 |
class_: Callable[[io.BufferedReader], NullTranslations] | None = None, |
| 111 |
fallback: bool = False, |
| 112 |
) -> NullTranslations: ... |
| 113 |
def install(domain: str, localedir: StrPath | None = None, *, names: Container[str] | None = None) -> None: ... |
| 114 |
|
| 115 |
else: |
| 116 |
@overload |
| 117 |
def translation( |
| 118 |
domain: str, |
| 119 |
localedir: StrPath | None = None, |
| 120 |
languages: Iterable[str] | None = None, |
| 121 |
class_: None = None, |
| 122 |
fallback: Literal[False] = False, |
| 123 |
codeset: str | None = ..., |
| 124 |
) -> GNUTranslations: ... |
| 125 |
@overload |
| 126 |
def translation( |
| 127 |
domain: str, |
| 128 |
localedir: StrPath | None = None, |
| 129 |
languages: Iterable[str] | None = None, |
| 130 |
*, |
| 131 |
class_: Callable[[io.BufferedReader], _NullTranslationsT], |
| 132 |
fallback: Literal[False] = False, |
| 133 |
codeset: str | None = ..., |
| 134 |
) -> _NullTranslationsT: ... |
| 135 |
@overload |
| 136 |
def translation( |
| 137 |
domain: str, |
| 138 |
localedir: StrPath | None, |
| 139 |
languages: Iterable[str] | None, |
| 140 |
class_: Callable[[io.BufferedReader], _NullTranslationsT], |
| 141 |
fallback: Literal[False] = False, |
| 142 |
codeset: str | None = ..., |
| 143 |
) -> _NullTranslationsT: ... |
| 144 |
@overload |
| 145 |
def translation( |
| 146 |
domain: str, |
| 147 |
localedir: StrPath | None = None, |
| 148 |
languages: Iterable[str] | None = None, |
| 149 |
class_: Callable[[io.BufferedReader], NullTranslations] | None = None, |
| 150 |
fallback: bool = False, |
| 151 |
codeset: str | None = ..., |
| 152 |
) -> NullTranslations: ... |
| 153 |
@overload |
| 154 |
def install(domain: str, localedir: StrPath | None = None, names: Container[str] | None = None) -> None: ... |
| 155 |
@overload |
| 156 |
@deprecated("The `codeset` parameter is deprecated since Python 3.8; removed in Python 3.11.") |
| 157 |
def install(domain: str, localedir: StrPath | None, codeset: str | None, /, names: Container[str] | None = None) -> None: ... |
| 158 |
@overload |
| 159 |
@deprecated("The `codeset` parameter is deprecated since Python 3.8; removed in Python 3.11.") |
| 160 |
def install( |
| 161 |
domain: str, localedir: StrPath | None = None, *, codeset: str | None, names: Container[str] | None = None |
| 162 |
) -> None: ... |
| 163 |
|
| 164 |
def textdomain(domain: str | None = None) -> str: ... |
| 165 |
def bindtextdomain(domain: str, localedir: StrPath | None = None) -> str: ... |
| 166 |
def dgettext(domain: str, message: str) -> str: ... |
| 167 |
def dngettext(domain: str, msgid1: str, msgid2: str, n: int) -> str: ... |
| 168 |
def gettext(message: str) -> str: ... |
| 169 |
def ngettext(msgid1: str, msgid2: str, n: int) -> str: ... |
| 170 |
def pgettext(context: str, message: str) -> str: ... |
| 171 |
def dpgettext(domain: str, context: str, message: str) -> str: ... |
| 172 |
def npgettext(context: str, msgid1: str, msgid2: str, n: int) -> str: ... |
| 173 |
def dnpgettext(domain: str, context: str, msgid1: str, msgid2: str, n: int) -> str: ... |
| 174 |
|
| 175 |
if sys.version_info < (3, 11): |
| 176 |
@deprecated("Deprecated since Python 3.8; removed in Python 3.11. Use `gettext()` instead.") |
| 177 |
def lgettext(message: str) -> str: ... |
| 178 |
@deprecated("Deprecated since Python 3.8; removed in Python 3.11. Use `dgettext()` instead.") |
| 179 |
def ldgettext(domain: str, message: str) -> str: ... |
| 180 |
@deprecated("Deprecated since Python 3.8; removed in Python 3.11. Use `ngettext()` instead.") |
| 181 |
def lngettext(msgid1: str, msgid2: str, n: int) -> str: ... |
| 182 |
@deprecated("Deprecated since Python 3.8; removed in Python 3.11. Use `dngettext()` instead.") |
| 183 |
def ldngettext(domain: str, msgid1: str, msgid2: str, n: int) -> str: ... |
| 184 |
@deprecated("Deprecated since Python 3.8; removed in Python 3.11. Use `bindtextdomain()` instead.") |
| 185 |
def bind_textdomain_codeset(domain: str, codeset: str | None = None) -> str: ... |
| 186 |
|
| 187 |
Catalog = translation |
| 188 |
|
| 189 |
def c2py(plural: str) -> Callable[[int], int]: ... |