-
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.
Merge branch 'master' of github.com:anthropedia/tci-i18n
- Loading branch information
Showing
2 changed files
with
30 additions
and
1 deletion.
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 |
---|---|---|
@@ -1,3 +1,26 @@ | ||
# TCI Translation Library | ||
|
||
Translate the TCI interface from CSV translation files. | ||
|
||
## Example | ||
|
||
TCI-i18n provides translation from CSV files. | ||
|
||
### CSV files format | ||
|
||
CSV files can have this format and should be UTF-8 encoded | ||
|
||
``` | ||
TCI title,Titre ITC | ||
"yes, or no","oui, ou non" | ||
Welcome %(user)s!,Bienvenue %(user)s ! | ||
``` | ||
|
||
### Usage | ||
|
||
``` | ||
from tcii18n import Translator | ||
translator = Translator('my_file.csv') | ||
translator.translate('My string') | ||
``` |
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 |
---|---|---|
@@ -1,9 +1,15 @@ | ||
from .translator import Translator | ||
|
||
_cached_translators = {} | ||
|
||
|
||
def flask_methods(app, get_translations_file): | ||
@app.context_processor | ||
def utility_processor(): | ||
def trans(sentence): | ||
return Translator(get_translations_file).translate(sentence) | ||
filename = get_translations_file() | ||
if filename not in _cached_translators: | ||
_cached_translators[filename] = Translator( | ||
get_translations_file()) | ||
return _cached_translators[filename].translate(sentence) | ||
return dict(trans=trans) |