Skip to content

Commit

Permalink
Merge branch 'master' of github.com:anthropedia/tci-i18n
Browse files Browse the repository at this point in the history
  • Loading branch information
Ydrasil committed Jun 6, 2017
2 parents 13c267b + ca5299b commit 9c4eefe
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
23 changes: 23 additions & 0 deletions readme.md
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')
```
8 changes: 7 additions & 1 deletion tcii18n/template.py
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)

0 comments on commit 9c4eefe

Please sign in to comment.