diff --git a/readme.md b/readme.md index 819ac63..606f46c 100644 --- a/readme.md +++ b/readme.md @@ -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') +``` diff --git a/tcii18n/template.py b/tcii18n/template.py index ff5030c..2475314 100644 --- a/tcii18n/template.py +++ b/tcii18n/template.py @@ -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)