{"id":15019292,"url":"https://github.com/bbmokhtari/django-translations","last_synced_at":"2025-05-16T06:08:15.720Z","repository":{"id":33436472,"uuid":"139559953","full_name":"bbmokhtari/django-translations","owner":"bbmokhtari","description":"Django model translation for perfectionists with deadlines.","archived":false,"fork":false,"pushed_at":"2025-04-19T15:41:44.000Z","size":2629,"stargazers_count":144,"open_issues_count":4,"forks_count":23,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-05-09T12:51:25.303Z","etag":null,"topics":["django","internationalization","localization","model","model-translations","translation","translations"],"latest_commit_sha":null,"homepage":"http://bbmokhtari.github.io/django-translations","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bbmokhtari.png","metadata":{"files":{"readme":".github/README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-07-03T09:27:51.000Z","updated_at":"2025-04-19T15:41:47.000Z","dependencies_parsed_at":"2024-06-19T00:24:46.109Z","dependency_job_id":"00937543-f708-4671-ad65-b9c9cef98055","html_url":"https://github.com/bbmokhtari/django-translations","commit_stats":{"total_commits":1479,"total_committers":6,"mean_commits":246.5,"dds":0.08789722785665988,"last_synced_commit":"50b6fa3cd2e7552d7c5265dd8b795f53a2191375"},"previous_names":[],"tags_count":35,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bbmokhtari%2Fdjango-translations","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bbmokhtari%2Fdjango-translations/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bbmokhtari%2Fdjango-translations/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bbmokhtari%2Fdjango-translations/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bbmokhtari","download_url":"https://codeload.github.com/bbmokhtari/django-translations/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254478193,"owners_count":22077676,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["django","internationalization","localization","model","model-translations","translation","translations"],"created_at":"2024-09-24T19:53:17.051Z","updated_at":"2025-05-16T06:08:10.705Z","avatar_url":"https://github.com/bbmokhtari.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Django Translations\n\n[![django](https://img.shields.io/badge/django-%3E%3D2.2%2C%20%3C6.0-0C4B33)](https://pypi.org/project/django-translations/)\n[![python](https://img.shields.io/badge/python-%3E%3D3.7%2C%20%3C4.0-0073b7)](https://pypi.org/project/django-translations/)\n\nDjango model translation for perfectionists with deadlines.\n\n## Goal\n\nThere are two types of content, each of which has its own challenges for translation:\n\n- Static content: This is the content which is defined in the code.\n  _e.g. \"Please enter a valid email address.\"_\n\n  Django already provides a\n  [solution](https://docs.djangoproject.com/en/2.2/topics/i18n/translation/)\n  for translating static content.\n\n- Dynamic content: This is the content which is stored in the database.\n  _(We can't know it beforehand!)_\n\n  Django Translations provides a solution\n  for translating dynamic content.\n\n## Compatibility\n\nCurrently, this project is incompatible with PostgreSQL.\n\n## Requirements\n\n- Python (\\\u003e=3.7, \\\u003c4)\n- Django (\\\u003e=2.2, \\\u003c6)\n\n## Installation\n\n1.  Install Django Translations using pip:\n\n    ```bash\n    $ pip install django-translations\n    ```\n\n2.  Add `translations` to the `INSTALLED_APPS` in the settings of your\n    project:\n\n    ```python\n    INSTALLED_APPS += [\n        'translations',\n    ]\n    ```\n\n3.  Run `migrate`:\n\n    ```bash\n    $ python manage.py migrate\n    ```\n\n4.  Configure Django internationalization and localization settings:\n\n    ```python\n    USE_I18N = True          # use internationalization\n    USE_L10N = True          # use localization\n\n    MIDDLEWARE += [          # locale middleware\n        'django.middleware.locale.LocaleMiddleware',\n    ]\n\n    LANGUAGE_CODE = 'en-us'  # default (fallback) language\n    LANGUAGES = (            # supported languages\n        ('en', 'English'),\n        ('en-gb', 'English (Great Britain)'),\n        ('de', 'German'),\n        ('tr', 'Turkish'),\n    )\n    ```\n\n    Please note that these settings are for Django itself.\n\n## Basic Usage\n\n### Model\n\nInherit `Translatable` in any model you want translated:\n\n```python\nfrom translations.models import Translatable\n\nclass Continent(Translatable):\n    code = models.Charfield(...)\n    name = models.Charfield(...)\n    denonym = models.Charfield(...)\n\n    class TranslatableMeta:\n        fields = ['name', 'denonym']\n```\n\nNo migrations needed afterwards.\n\n### Admin\n\nUse the admin extensions:\n\n```python\nfrom translations.admin import TranslatableAdmin, TranslationInline\n\nclass ContinentAdmin(TranslatableAdmin):\n    inlines = [TranslationInline,]\n```\n\nThis provides specialized translation inlines for the model.\n\n![image](https://raw.githubusercontent.com/bbmokhtari/django-translations/master/docs/_static/admin.png)\n\n## QuerySet\n\nUse the queryset extensions:\n\n```python\n\u003e\u003e\u003e from sample.models import Continent\n\u003e\u003e\u003e continents = Continent.objects.all(\n... ).distinct(           # familiar distinct\n... ).probe(['en', 'de']  # probe (filter, exclude, etc.) in English and German\n... ).filter(             # familiar filtering\n...     countries__cities__name__startswith='Köln'\n... ).translate('de'      # translate the results in German\n... ).translate_related(  # translate these relations as well\n...     'countries', 'countries__cities',\n... )\n\u003e\u003e\u003e print(continents)\n\u003cTranslatableQuerySet [\n    \u003cContinent: Europa\u003e,\n]\u003e\n\u003e\u003e\u003e print(continents[0].countries.all())\n\u003cTranslatableQuerySet [\n    \u003cCountry: Deutschland\u003e,\n]\u003e\n\u003e\u003e\u003e print(continents[0].countries.all()[0].cities.all())\n\u003cTranslatableQuerySet [\n    \u003cCity: Köln\u003e,\n]\u003e\n```\n\nThis provides a powerful yet familiar interface to work with the querysets.\n\n## Context\n\nUse the translation context:\n\n```python\n\u003e\u003e\u003e from translations.context import Context\n\u003e\u003e\u003e from sample.models import Continent\n\u003e\u003e\u003e continents = Continent.objects.all()\n\u003e\u003e\u003e relations = ('countries', 'countries__cities',)\n\u003e\u003e\u003e with Context(continents, *relations) as context:\n...     context.read('de')    # read the translations onto the context\n...     print(':')            # use the objects like before\n...     print(continents)\n...     print(continents[0].countries.all())\n...     print(continents[0].countries.all()[0].cities.all())\n...\n...     continents[0].countries.all()[0].name = 'Change the name'\n...     context.update('de')  # update the translations from the context\n...\n...     context.delete('de')  # delete the translations of the context\n...\n...     context.reset()       # reset the translations of the context\n...     print(':')            # use the objects like before\n...     print(continents)\n...     print(continents[0].countries.all())\n...     print(continents[0].countries.all()[0].cities.all())\n:\n\u003cTranslatableQuerySet [\n    \u003cContinent: Asien\u003e,\n    \u003cContinent: Europa\u003e,\n]\u003e\n\u003cTranslatableQuerySet [\n    \u003cCountry: Deutschland\u003e,\n]\u003e\n\u003cTranslatableQuerySet [\n    \u003cCity: Köln\u003e,\n]\u003e\n:\n\u003cTranslatableQuerySet [\n    \u003cContinent: Asia\u003e,\n    \u003cContinent: Europe\u003e,\n]\u003e\n\u003cTranslatableQuerySet [\n    \u003cCountry: Germany\u003e,\n]\u003e\n\u003cTranslatableQuerySet [\n    \u003cCity: Cologne\u003e,\n]\u003e\n```\n\nThis can CRUD the translations of any objects (instance, queryset, list) and their relations.\n\n## Documentation\n\nFor more interesting capabilities browse through the\n[documentation](http://bbmokhtari.github.io/django-translations).\n\n## Still Stuck?\n\nEmail [bbmokhtari.global@gmail.com](mailto:bbmokhtari.global@gmail.com) if you're really stuck.\n\n## Support the project\n\nTo support the project you can:\n\n- ⭐️: [Star](http://github.com/bbmokhtari/django-translations/) it on GitHub.\n- 💻: [Contribute](https://bbmokhtari.github.io/django-translations/contribution.html) to the code base.\n- ☕️: [Buy](https://bbmokhtari.github.io/django-translations/donation.html) the maintainers coffee.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbbmokhtari%2Fdjango-translations","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbbmokhtari%2Fdjango-translations","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbbmokhtari%2Fdjango-translations/lists"}