-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add localization functions and russian localization
- Loading branch information
Showing
8 changed files
with
379 additions
and
82 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,3 +17,5 @@ tests/.cache/* | |
.coverage | ||
*,cover | ||
*htmlcov | ||
*.po.new | ||
*.pot |
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,17 @@ | ||
.PRECIOUS: plumbum/cli/i18n/%.po.new | ||
# scrape sources for messages | ||
all: plumbum/cli/i18n/*/LC_MESSAGES/plumbum.cli.mo | ||
plumbum/cli/i18n/messages.pot: plumbum/cli/*.py | ||
xgettext --from-code utf-8 -L python --keyword=T_ -o $@ $^ | ||
|
||
# merge changes with previous translations | ||
plumbum/cli/i18n/%.po.new: plumbum/cli/i18n/messages.pot plumbum/cli/i18n/%.po | ||
$(foreach f,$(filter-out $<,$^),msgmerge $f plumbum/cli/i18n/messages.pot > $(f).new;) | ||
|
||
# compile runtime-usable messages | ||
plumbum/cli/i18n/%/LC_MESSAGES/plumbum.cli.mo: plumbum/cli/i18n/%.po.new | ||
$(foreach f,$^,mkdir -p $(f:.po.new=)/LC_MESSAGES;) | ||
$(foreach f,$^,msgfmt -o $(f:.po.new=)/LC_MESSAGES/plumbum.cli.mo $(f);) | ||
|
||
update_cli_ru: | ||
mv plumbum/cli/i18n/ru.po.new plumbum/cli/i18n/ru.po |
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,22 @@ | ||
import gettext | ||
from typing import Tuple | ||
import pkg_resources | ||
|
||
def get_translation_for(package_name: str) -> gettext.NullTranslations: | ||
'find and return gettext translation for package' | ||
if '.' in package_name: | ||
package_name = '.'.join(package_name.split('.')[:-1]) | ||
localedir = None | ||
for localedir in pkg_resources.resource_filename(package_name, 'i18n'), None: | ||
localefile = gettext.find(package_name, localedir) | ||
if localefile: | ||
break | ||
else: | ||
pass | ||
return gettext.translation(package_name, localedir=localedir, fallback=True) | ||
|
||
|
||
def get_translation_functions(package_name: str, names: Tuple[str, ...]=('gettext',)): | ||
'finds and installs translation functions for package' | ||
translation = get_translation_for(package_name) | ||
return [getattr(translation, x) for x in names] |
Oops, something went wrong.