Skip to content

About

Transifex Native SDK for Python

Resources

Code of conduct

Contributing

Stars

40 stars

Watchers

13 watching

Forks

Repository files navigation

Test suite codecov

Transifex Python Toolkit

Transifex Python Toolkit is a collection of tools that allow you to easily localize your Django and Python applications using Transifex. The toolkit features fetching translations over the air (OTA) to your apps.

This project adheres to the Contributor Covenant code of conduct. To contribute to Transifex Python Toolkit, please check out the contribution guidelines.

Upgrade to v2

If you are upgrading from the 1.x.x version, please read this migration guide, as there are breaking changes in place.

Quick starting guide

  1. Install toolkit in your code $ pip install transifex-python
  2. Add a provided TOKEN and SECRET in your config, connecting your application with a Transifex project
  3. Add internationalization commands in your code
  <!-- Django app template example -->

  {% load transifex %}
  <p>{% t "Hello!" %}</p>
  <p>{% t "I want to be translated." %}</p>
  # Django view sample
  from transifex.native.django import t

  output = {
      "msg1": t("Welcome aboard!"),
      "msg2": t("It's great to have you here!"),
  }
  return JsonResponse(output)
  1. Push strings to your connected Transifex project ./manage.py transifex push
  2. When translations are added in your Transifex project are automatically made available

To learn more about using Transifex Python toolkit check:

Django settings reference

The Transifex Native Django sdk is controlled via a set of configuration options defined in Django settings:

  • TRANSIFEX_TOKEN: API token that connects your application to a Transifex project. Must be set for both pushing source strings and fetching translations.

  • TRANSIFEX_SECRET: Secret used together with the token for authenticated operations against CDS (e.g. pushing source content, invalidating cache).

  • TRANSIFEX_CDS_HOST: Override the default CDS host (https://cds.svc.transifex.net).

  • TRANSIFEX_FILTER_STATUS: Optional CDS filter[status] parameter used when fetching translations (e.g. "reviewed", "proofread"). If not set, CDS returns all available statuses.

  • TRANSIFEX_FILTER_TAGS: Optional CDS filter[tags] parameter used when fetching translations. Use this to limit fetched content to specific tags.

  • TRANSIFEX_MISSING_POLICY: Custom “missing translation” policy class. Defaults to the built-in SourceStringPolicy when not provided.

  • TRANSIFEX_ERROR_POLICY: Custom error handling policy class. Defaults to SourceErrorPolicy.

  • TRANSIFEX_CACHE Custom cache implementation. Defaults to an in-memory cache (MemoryCache) if not provided. Can be used to integrate with a shared cache (e.g. Redis, memcached).

  • SKIP_TRANSLATIONS_SYNC: If True, disables automatic translation sync (OTA) for this environment.

  • TRANSIFEX_SYNC_INTERVAL: Interval in seconds for the background sync daemon that fetches translations. Default: 30 * 60 (30 minutes). Set to 0 to disable periodic sync and only fetch on startup.

  • TRANSIFEX_FETCH_ALL_LANGUAGES: When True, fetch translations for all languages configured in CDS. When False (default), only fetch translations for languages listed in Django’s LANGUAGES setting.

  • TRANSIFEX_FETCH_TIMEOUT: Approximate maximum time in seconds for one fetch of languages and translations from CDS, including retries. It can be exceeded, e.g. by DNS resolution, a host with several IP addresses, or a response that keeps sending data slowly (the read timeout applies between received bytes, not to the whole response). Languages are fetched in LANGUAGES order; those not reached in time are skipped until the next sync, or for the life of the process if TRANSIFEX_SYNC_INTERVAL is 0. 0 (default) = no global timeout: if CDS keeps answering 202, the fetch, and so startup, waits until it stops. Set it when translations are fetched at startup, e.g. under gunicorn.

  • TRANSIFEX_REQUEST_TIMEOUT: Timeout in seconds for each request made when fetching from CDS, either a number greater than 0 or a (connect, read) tuple as accepted by requests. Invalid values are logged and the default is used. Defaults to (10, 60).

License

Licensed under Apache License 2.0, see LICENSE file.

About

Transifex Native SDK for Python

Resources

Code of conduct

Contributing

Stars

40 stars

Watchers

13 watching

Forks

Releases

Packages

Used by

Contributors

Languages