All Projects → bbmokhtari → Django Translations

bbmokhtari / Django Translations

Licence: bsd-3-clause
Django model translation for perfectionists with deadlines.

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Django Translations

Weblate
Web based localization tool with tight version control integration.
Stars: ✭ 2,719 (+2394.5%)
Mutual labels:  translation, django, localization, internationalization
Mojito
An automation platform that enables continuous localization.
Stars: ✭ 256 (+134.86%)
Mutual labels:  translation, localization, internationalization, translations
React Intl Hooks
React hooks for internationalization without the hassle ⚛️🌍
Stars: ✭ 64 (-41.28%)
Mutual labels:  translation, localization, internationalization
Easy localization
Easy and Fast internationalizing your Flutter Apps
Stars: ✭ 407 (+273.39%)
Mutual labels:  translation, localization, internationalization
Fluent.js
JavaScript implementation of Project Fluent
Stars: ✭ 622 (+470.64%)
Mutual labels:  translation, localization, internationalization
Eo Locale
🌏Internationalize js apps 👔Elegant lightweight library based on Internationalization API
Stars: ✭ 290 (+166.06%)
Mutual labels:  translation, localization, internationalization
Js Lingui
🌍📖 A readable, automated, and optimized (5 kb) internationalization for JavaScript
Stars: ✭ 3,249 (+2880.73%)
Mutual labels:  translation, localization, internationalization
Django Parler
Easily translate "cheese omelet" into "omelette au fromage".
Stars: ✭ 459 (+321.1%)
Mutual labels:  django, internationalization, translations
flutter-internationalization
Flutter Internationalization by Using JSON Files
Stars: ✭ 18 (-83.49%)
Mutual labels:  translation, internationalization, localization
Fluent
Fluent — planning, spec and documentation
Stars: ✭ 818 (+650.46%)
Mutual labels:  translation, localization, internationalization
Django Rosetta
Rosetta is a Django application that eases the translation process of your Django projects
Stars: ✭ 806 (+639.45%)
Mutual labels:  translation, django, internationalization
Pseudo Localization
Dynamic pseudo-localization in the browser and nodejs
Stars: ✭ 109 (+0%)
Mutual labels:  translation, localization, internationalization
labels
Bolt Labels extension - Translatable labels for Bolt
Stars: ✭ 18 (-83.49%)
Mutual labels:  translation, internationalization, localization
React Localize Redux
Dead simple localization for your React components
Stars: ✭ 384 (+252.29%)
Mutual labels:  translation, localization, internationalization
blazor-ui-messages
Localization messages for Telerik UI for Blazor components: https://www.telerik.com/blazor-ui
Stars: ✭ 24 (-77.98%)
Mutual labels:  translation, internationalization, localization
Stringz
A lightweight and powerful editor for localizing iOS, macOS, tvOS, and watchOS applications.
Stars: ✭ 440 (+303.67%)
Mutual labels:  translation, localization, internationalization
Eslint Plugin I18n Json
Fully extendable eslint plugin for JSON i18n translation files.
Stars: ✭ 101 (-7.34%)
Mutual labels:  translation, internationalization, translations
rosetta
A blazing fast internationalization (i18n) library for Crystal with compile-time key lookup.
Stars: ✭ 23 (-78.9%)
Mutual labels:  translation, internationalization, localization
plate
Internationalization library for Python
Stars: ✭ 31 (-71.56%)
Mutual labels:  translation, internationalization, localization
Frenchkiss.js
The blazing fast lightweight internationalization (i18n) module for javascript
Stars: ✭ 776 (+611.93%)
Mutual labels:  translation, localization, internationalization

Django Translations

build python django

Django model translation for perfectionists with deadlines.

Goal

There are two types of content, each of which has its own challenges for translation:

  • Static content: This is the content which is defined in the code. e.g. "Please enter a valid email address."

    Django already provides a solution for translating static content.

  • Dynamic content: This is the content which is stored in the database. (We can't know it beforehand!)

    Django Translations provides a solution for translating dynamic content.

Compatibility

Currently, this project is incompatible with PostgreSQL.

Requirements

  • Python (>=3.6, <4)
  • Django (>=2.0, <4)

Installation

  1. Install Django Translations using pip:

    $ pip install django-translations
    
  2. Add translations to the INSTALLED_APPS in the settings of your project:

    INSTALLED_APPS += [
        'translations',
    ]
    
  3. Run migrate:

    $ python manage.py migrate
    
  4. Configure Django internationalization and localization settings:

    USE_I18N = True          # use internationalization
    USE_L10N = True          # use localization
    
    MIDDLEWARE += [          # locale middleware
        'django.middleware.locale.LocaleMiddleware',
    ]
    
    LANGUAGE_CODE = 'en-us'  # default (fallback) language
    LANGUAGES = (            # supported languages
        ('en', 'English'),
        ('en-gb', 'English (Great Britain)'),
        ('de', 'German'),
        ('tr', 'Turkish'),
    )
    

    Please note that these settings are for Django itself.

Basic Usage

Model

Inherit Translatable in any model you want translated:

from translations.models import Translatable

class Continent(Translatable):
    code = models.Charfield(...)
    name = models.Charfield(...)
    denonym = models.Charfield(...)

    class TranslatableMeta:
        fields = ['name', 'denonym']

No migrations needed afterwards.

Admin

Use the admin extensions:

from translations.admin import TranslatableAdmin, TranslationInline

class ContinentAdmin(TranslatableAdmin):
    inlines = [TranslationInline,]

This provides specialized translation inlines for the model.

image

QuerySet

Use the queryset extensions:

>>> from sample.models import Continent
>>> continents = Continent.objects.all(
... ).distinct(           # familiar distinct
... ).probe(['en', 'de']  # probe (filter, exclude, etc.) in English and German
... ).filter(             # familiar filtering
...     countries__cities__name__startswith='Köln'
... ).translate('de'      # translate the results in German
... ).translate_related(  # translate these relations as well
...     'countries', 'countries__cities',
... )
>>> print(continents)
<TranslatableQuerySet [
    <Continent: Europa>,
]>
>>> print(continents[0].countries.all())
<TranslatableQuerySet [
    <Country: Deutschland>,
]>
>>> print(continents[0].countries.all()[0].cities.all())
<TranslatableQuerySet [
    <City: Köln>,
]>

This provides a powerful yet familiar interface to work with the querysets.

Context

Use the translation context:

>>> from translations.context import Context
>>> from sample.models import Continent
>>> continents = Continent.objects.all()
>>> relations = ('countries', 'countries__cities',)
>>> with Context(continents, *relations) as context:
...     context.read('de')    # read the translations onto the context
...     print(':')            # use the objects like before
...     print(continents)
...     print(continents[0].countries.all())
...     print(continents[0].countries.all()[0].cities.all())
... 
...     continents[0].countries.all()[0].name = 'Change the name'
...     context.update('de')  # update the translations from the context
... 
...     context.delete('de')  # delete the translations of the context
... 
...     context.reset()       # reset the translations of the context
...     print(':')            # use the objects like before
...     print(continents)
...     print(continents[0].countries.all())
...     print(continents[0].countries.all()[0].cities.all())
:
<TranslatableQuerySet [
    <Continent: Asien>,
    <Continent: Europa>,
]>
<TranslatableQuerySet [
    <Country: Deutschland>,
]>
<TranslatableQuerySet [
    <City: Köln>,
]>
:
<TranslatableQuerySet [
    <Continent: Asia>,
    <Continent: Europe>,
]>
<TranslatableQuerySet [
    <Country: Germany>,
]>
<TranslatableQuerySet [
    <City: Cologne>,
]>

This can CRUD the translations of any objects (instance, queryset, list) and their relations.

Documentation

For more interesting capabilities browse through the documentation.

Support the project

To support the project you can:

  • ⭐️: Star it on GitHub.
  • 💻: Contribute to the code base.
  • ☕️: Buy the maintainers coffee.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].