forked from dbcli/mssql-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added localization framework to mssql-cli (dbcli#272)
- Loading branch information
Gene Lee
authored
Aug 30, 2019
1 parent
dfbb45d
commit 1cfcf5f
Showing
8 changed files
with
83 additions
and
7 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 |
---|---|---|
|
@@ -54,7 +54,6 @@ junit/ | |
.DS_Store | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
|
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
Binary file not shown.
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,19 @@ | ||
import gettext | ||
import os | ||
from importlib import import_module | ||
|
||
PATH = '{0}.py'.format(os.path.splitext(__file__)[0]) | ||
DOMAIN = 'mssql-cli' | ||
LOCALE_DIR = os.path.join(os.path.dirname(__file__), 'locale') | ||
LANGUAGES = None | ||
|
||
def translation(domain=DOMAIN, localedir=LOCALE_DIR, languages=None): | ||
languages = languages if (not languages is None) else LANGUAGES | ||
return gettext.translation(domain, localedir, languages, fallback=True) | ||
|
||
translation().install() | ||
|
||
|
||
## Localized Strings | ||
def goodbye(): | ||
return _(u'Goodbye!') |
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 |
---|---|---|
|
@@ -25,3 +25,5 @@ configobj >= 5.0.6 | |
humanize >= 0.5.1 | ||
cli_helpers >= 0.2.3, < 1.0.0 | ||
mock>=1.0.1 | ||
babel>=2.7.0 | ||
polib>=1.1.0 |
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,18 @@ | ||
# -*- coding: utf-8 -*- | ||
import unittest | ||
import sys | ||
import mssqlcli.localized_strings as localized | ||
|
||
|
||
class LocalizationTests(unittest.TestCase): | ||
|
||
def test_product(self): | ||
original = self.unicode(localized.goodbye()) | ||
localized.translation(languages=['ko']).install() | ||
translated = self.unicode(localized.goodbye()) | ||
assert original != translated | ||
|
||
def unicode(self, s): | ||
if (sys.version_info.major < 3 and isinstance(s, str)): | ||
return s.decode('utf-8') | ||
return s |