comparison libervia/backend/core/i18n.py @ 4071:4b842c1fb686

refactoring: renamed `sat` package to `libervia.backend`
author Goffi <goffi@goffi.org>
date Fri, 02 Jun 2023 11:49:51 +0200
parents sat/core/i18n.py@524856bd7b19
children 0d7bb4df2343
comparison
equal deleted inserted replaced
4070:d10748475025 4071:4b842c1fb686
1 #!/usr/bin/env python3
2
3
4 # SAT: a jabber client
5 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org)
6
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
16
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20 from typing import Callable, cast
21
22 from libervia.backend.core.log import getLogger
23
24 log = getLogger(__name__)
25
26 try:
27
28 import gettext
29
30 _ = gettext.translation("libervia_backend", "i18n", fallback=True).gettext
31 _translators = {None: gettext.NullTranslations()}
32
33 def language_switch(lang=None):
34 if not lang in _translators:
35 _translators[lang] = gettext.translation(
36 "libervia_backendt", languages=[lang], fallback=True
37 )
38 _translators[lang].install()
39
40
41 except ImportError:
42
43 log.warning("gettext support disabled")
44 _ = cast(Callable[[str], str], lambda msg: msg) # Libervia doesn't support gettext
45
46 def language_switch(lang=None):
47 pass
48
49
50 D_ = cast(Callable[[str], str], lambda msg: msg) # used for deferred translations