-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use custom gettext instead of modify environment variable
- Loading branch information
Showing
9 changed files
with
52 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from .i18n import init_locale | ||
from .config_data import Config | ||
|
||
|
||
__all__ = ['config', 'init_locale', "load_config"] | ||
|
||
|
||
config = None | ||
|
||
|
||
def load_config(config_path): | ||
global config | ||
config = Config(config_path) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from pathlib import Path | ||
import gettext as _gettext | ||
|
||
|
||
_DOMAIN = 'beanbot' | ||
|
||
gettext = _gettext.gettext | ||
|
||
|
||
def init_locale(): | ||
"""Initialize the locale translation.""" | ||
from . import config | ||
locale_dir = Path(__file__).parent.parent / 'locale' | ||
language = config.get('language') | ||
if language is not None: | ||
# Use custom translation | ||
translation = _gettext.translation(_DOMAIN, locale_dir, [language], fallback=True) | ||
global gettext | ||
gettext = translation.gettext | ||
else: | ||
# Use default translation, and load locale from env | ||
_gettext.bindtextdomain(_DOMAIN, locale_dir) | ||
_gettext.textdomain(_DOMAIN) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters