Skip to main content

Django SDK for tranlationexchange.com API

Project description

<p align="center">
<img src="https://avatars0.githubusercontent.com/u/1316274?v=3&s=200">
</p>

TML Library for Django
====================================
[![Build Status](https://travis-ci.org/translationexchange/tml-python-django.png?branch=master)](https://travis-ci.org/translationexchange/tml-python-django)
[![Coverage Status](https://coveralls.io/repos/translationexchange/tml-python-django/badge.png?branch=master)](https://coveralls.io/r/translationexchange/tml-python-django?branch=master)


## Introduction

This document demonstrates how to use TML (Translation Markup Language) in a Django application.

### Integration

Installing using pip:

```
pip install django_tml
```

Add 'django_tml' to your INSTALLED_APPS setting:

```python
INSTALLED_APPS = (
...
'django_tml',
)
```

Add TML middleware to MIDDLEWARE_CLASSES setting:

```
MIDDLEWARE_CLASSES = (
...
'django_tml.middleware.TmlControllerMiddleware',
)
```

Then add the following TML configuraiton to setting file:

```python
TML = {
'environment': 'dev',
'application': {
'key': 'YOUR_APPLICATON_KEY', # add application key from [TranslationExchange dashboard](https://dashboard.translationexchange.com/)
},
'monkeypatch': True, # support legacy translations
'cache': {
'enabled': True,
'adapter': 'memcached',
'backend': 'pylibmc',
'namespace': 'foody'
},
'logger': {
'path': pj(BASE_DIR, 'logs', 'tml.log')
}
}
```

To start using TML tags and filters, load tag libraries in the head of your template file:

```jinja2
{­% load i18n %­}
{­% load tml tml_inline %­}
```

To activate inline translation functionality add one more line in the head section of your layout:

```jinja2
{­% tml_inline_header %­}
```

*(Optional)* You can also add a language switcher to your site. Just add the next template tag in the navigation of your site:

```jinja2
{% tml_language_selector type="sideflags" %}
```

### Demo application

The best way to learn about the SDK capabilities is to use the demo application that comes with the SDK. The demo application provides many samples of TML syntax.

Run the following scripts to setup and run the the Demo application:

```bash
$ git clone git@github.com:translationexchange/tml-python-django.git
$ cd tml-python-django/demo
$ virtualenv --no-site-packages tmldemo
$ . ./tmldemo/bin/activate
$ pip install -r requirements.txt
$ python manage.py migrate
$ python manage.py runserver localhost:8000
```

### TML Configuration

* ``environment`` - Running environment (one of ``dev|stage|prod``)
* ``application`` - Provide key for authentication, api path and cdn path to and path api path.
* ``monkeypatch`` - This option facilitates Tml to be backward compatible with django i18n engine. You can still use django native tags for translating your strings.
* ``cache`` - Define your cache configuration here. More about cache in advanced section.
* ``agent`` - Agent helps your application to download JS SDK on initial load of your page and then use TML widgets, shortcuts and SDK in client-side.
* ``data_preprocessors`` - Preprocessors applied on translateable string before actual processing. For example ``list`` preprocessors preprocess list like context variable into meaningful text token.
* ``env_generators`` - Sometimes you do not need to provide substitution token variable. For example, ``viewing_user`` env generator could be substituted by the return value of env generator. By default we return ``request.user``.
* ``logger`` - TML log that tracks interaction with SDK by http and supressed exceptions while translating string.


Links
==================

* Register on TranslationExchange.com: http://translationexchange.com

* Follow TranslationExchange on Twitter: https://twitter.com/translationx

* Connect with TranslationExchange on Facebook: https://www.facebook.com/translationexchange

* If you have any questions or suggestions, contact us: support@translationexchange.com


Copyright and license
==================

Copyright (c) 2016 Translation Exchange, Inc.

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-tml-0.1.8.tar.gz (16.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_tml-0.1.8-py2-none-any.whl (21.5 kB view details)

Uploaded Python 2

File details

Details for the file django-tml-0.1.8.tar.gz.

File metadata

  • Download URL: django-tml-0.1.8.tar.gz
  • Upload date:
  • Size: 16.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for django-tml-0.1.8.tar.gz
Algorithm Hash digest
SHA256 82358885282ffc16f719238e7a2303fc35e0fdd67089d5829b7b7039af96c84e
MD5 507ee3b97a78c4fe249918431031bc83
BLAKE2b-256 a12598d3e95f387544f4d3543901d5f709935b88f8732929e7a3a9ddfe984550

See more details on using hashes here.

File details

Details for the file django_tml-0.1.8-py2-none-any.whl.

File metadata

File hashes

Hashes for django_tml-0.1.8-py2-none-any.whl
Algorithm Hash digest
SHA256 a426c3b6e1e6df0579ce2112dcb72f029a635f0adb3511432d9dbac5ee588f7b
MD5 ea3ed687ea86f3509ac34d557a619f72
BLAKE2b-256 0c22a019f5f3f2a280736a82077b437c2bec28214e05f3e9dbd94690023b6378

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page