Name | django-translator JSON |
Version |
1.2.0
JSON |
| download |
home_page | https://www.dreipol.ch/ |
Summary | Translator is an app for collecting translations for specified keys in django admin. |
upload_time | 2024-09-03 14:30:42 |
maintainer | None |
docs_url | None |
author | dreipol GmbH |
requires_python | None |
license | MIT License |
keywords |
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
===========
Translator
===========
Translator is an app for collecting translations for specified keys in django admin.
Quick start
-----------
#. Install django-translator: ``pip install django-translator``
#. Add "translator, taggit, modeltranslation" to your INSTALLED_APPS setting. Please note that ``modeltranslation`` needs to be before ``django.contrib.admin``::
INSTALLED_APPS = (
'modeltranslation',
'django.contrib.admin',
...
'taggit',
'translator',
)
#. You have to set the migrations folder for the translator, because we have to add migrations for the set languages. Add the following to your settings file::
MIGRATION_MODULES = {
'translator': 'my_project.translator_migrations',
}
#. Create a ``translator_migrations`` python package in your project folder (where your settings.py usually is).
#. Run ``python manage.py makemigrations translator`` to create the translator models based on the languages you specified in your settings file.
#. Run ``python manage.py migrate`` to migrate the translator models to your database.
#. If you intend to use it in the templates, add 'translator.context_processors.translator' to TEMPLATE_CONTEXT_PROCESSORS ::
TEMPLATE_CONTEXT_PROCESSORS = (
...
'translator.context_processors.translator',
)
#. Create translation keys in your templates and models.
Examples:
Template::
{{ translator.a_key }}
models.py::
from translator.util import translator_lazy as _
...
class Product(models.Model):
name = models.TextField(verbose_name=_('a_key'))
#. Visit the templates. The keys get collected lazy.
#. Translate the keys in the admin.
#. You can disable the translator by setting DJANGO_TRANSLATOR_ENABLED to False.
#. Use a double underscore in your translation keys to make use of the filter in the admin (e.g. "header__title" creates a filter called "header"). If you need another separator, set it as DJANGO_TRANSLATOR_CATEGORY_SEPARATOR in your setting file.
Custom Models
-------------
If you find yourself in a situation where you need to use the features of django-translator in a second isolated model, feel free to add one:
#. Create a new model in your app::
from translator.models import TranslationBase
class MyCustomTranslation(TranslationBase):
pass
#. Create a new file `translation.py` and register your model for modeltranslation support::
from modeltranslation.translator import translator, TranslationOptions
from myapp.models import MyCustomTranslation
class MyCustomTranslationOptions(TranslationOptions):
fields = ('description',)
translator.register(MyCustomTranslation, MyCustomTranslationOptions)
#. Add a django admin in `admin.py`::
from django.contrib import admin
from translator.admin import TranslationAdministration
from myapp.models import MyCustomTranslation
@admin.register(MyCustomTranslation)
class CustomTranslationAdmin(TranslationAdministration):
pass
#. Add your model to your settings file::
DJANGO_TRANSLATOR_MODELS = {
'custom_translation': 'myapp.models.MyCustomTranslation',
}
#. Create translation keys in your templates and models.
Examples:
Template::
{{ custom_translation.a_key }}
models.py::
from myapp.util import custom_translation_lazy
...
class Product(models.Model):
name = models.TextField(verbose_name=translator_lazy('a_key', 'custom_translation'))
Settings
-------------
Customize the translator in your settings.py file with these settings::
DJANGO_TRANSLATOR_CACHE_TIMEOUT = timeout in seconds, if not set defaults to DEFAULT_TIMEOUT, which is either the CACHES['TIMEOUT'] setting or 300 (5 minutes)
Project Home
------------
https://github.com/dreipol/django-translator
PyPi
------------
https://pypi.python.org/pypi/django-translator
Raw data
{
"_id": null,
"home_page": "https://www.dreipol.ch/",
"name": "django-translator",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": null,
"author": "dreipol GmbH",
"author_email": "dev@dreipol.ch",
"download_url": "https://files.pythonhosted.org/packages/37/f0/07f40c3d228a97abd9a70056f96225c6509f0424135a3baf114af7fc7995/django_translator-1.2.0.tar.gz",
"platform": null,
"description": "===========\nTranslator\n===========\n\nTranslator is an app for collecting translations for specified keys in django admin.\n\nQuick start\n-----------\n#. Install django-translator: ``pip install django-translator``\n\n#. Add \"translator, taggit, modeltranslation\" to your INSTALLED_APPS setting. Please note that ``modeltranslation`` needs to be before ``django.contrib.admin``::\n\n\tINSTALLED_APPS = (\n\t'modeltranslation',\n\t'django.contrib.admin',\n\t...\n\t'taggit',\n\t'translator',\n\t)\n\n#. You have to set the migrations folder for the translator, because we have to add migrations for the set languages. Add the following to your settings file::\n\n\tMIGRATION_MODULES = {\n\t 'translator': 'my_project.translator_migrations',\n\t}\n\n#. Create a ``translator_migrations`` python package in your project folder (where your settings.py usually is).\n\n#. Run ``python manage.py makemigrations translator`` to create the translator models based on the languages you specified in your settings file.\n\n#. Run ``python manage.py migrate`` to migrate the translator models to your database.\n\n#. If you intend to use it in the templates, add 'translator.context_processors.translator' to TEMPLATE_CONTEXT_PROCESSORS ::\n\n\t TEMPLATE_CONTEXT_PROCESSORS = (\n\t \t...\n\t 'translator.context_processors.translator',\n\t )\n\n#. Create translation keys in your templates and models.\n\n\tExamples:\n\n\tTemplate::\n\n\t\t{{ translator.a_key }}\n\n\tmodels.py::\n\n\t\tfrom translator.util import translator_lazy as _\n\t\t...\n\n\t\tclass Product(models.Model):\n\t\t name = models.TextField(verbose_name=_('a_key'))\n\n#. Visit the templates. The keys get collected lazy.\n\n#. Translate the keys in the admin.\n\n\n#. You can disable the translator by setting DJANGO_TRANSLATOR_ENABLED to False.\n\n#. Use a double underscore in your translation keys to make use of the filter in the admin (e.g. \"header__title\" creates a filter called \"header\"). If you need another separator, set it as DJANGO_TRANSLATOR_CATEGORY_SEPARATOR in your setting file.\n\n\nCustom Models\n-------------\n\nIf you find yourself in a situation where you need to use the features of django-translator in a second isolated model, feel free to add one:\n\n#. Create a new model in your app::\n\n from translator.models import TranslationBase\n\n class MyCustomTranslation(TranslationBase):\n pass\n\n\n#. Create a new file `translation.py` and register your model for modeltranslation support::\n\n from modeltranslation.translator import translator, TranslationOptions\n from myapp.models import MyCustomTranslation\n\n class MyCustomTranslationOptions(TranslationOptions):\n fields = ('description',)\n\n translator.register(MyCustomTranslation, MyCustomTranslationOptions)\n\n\n#. Add a django admin in `admin.py`::\n\n from django.contrib import admin\n from translator.admin import TranslationAdministration\n from myapp.models import MyCustomTranslation\n\n @admin.register(MyCustomTranslation)\n class CustomTranslationAdmin(TranslationAdministration):\n pass\n\n\n#. Add your model to your settings file::\n\n DJANGO_TRANSLATOR_MODELS = {\n 'custom_translation': 'myapp.models.MyCustomTranslation',\n }\n\n\n#. Create translation keys in your templates and models.\n\n\tExamples:\n\n\tTemplate::\n\n\t\t{{ custom_translation.a_key }}\n\n\tmodels.py::\n\n\t\tfrom myapp.util import custom_translation_lazy\n\t\t...\n\n\t\tclass Product(models.Model):\n\t\t name = models.TextField(verbose_name=translator_lazy('a_key', 'custom_translation'))\n\nSettings\n-------------\nCustomize the translator in your settings.py file with these settings::\n\n\tDJANGO_TRANSLATOR_CACHE_TIMEOUT = timeout in seconds, if not set defaults to DEFAULT_TIMEOUT, which is either the CACHES['TIMEOUT'] setting or 300 (5 minutes)\n\n\nProject Home\n------------\nhttps://github.com/dreipol/django-translator\n\nPyPi\n------------\nhttps://pypi.python.org/pypi/django-translator\n",
"bugtrack_url": null,
"license": "MIT License",
"summary": "Translator is an app for collecting translations for specified keys in django admin.",
"version": "1.2.0",
"project_urls": {
"Homepage": "https://www.dreipol.ch/"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "37f007f40c3d228a97abd9a70056f96225c6509f0424135a3baf114af7fc7995",
"md5": "991f06493692d4fafac5f1169422ca22",
"sha256": "6bebfed3633defe347c5f9fb4a22e4daf985a50cd47da2fddc656bc447243dbf"
},
"downloads": -1,
"filename": "django_translator-1.2.0.tar.gz",
"has_sig": false,
"md5_digest": "991f06493692d4fafac5f1169422ca22",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 6046,
"upload_time": "2024-09-03T14:30:42",
"upload_time_iso_8601": "2024-09-03T14:30:42.419417Z",
"url": "https://files.pythonhosted.org/packages/37/f0/07f40c3d228a97abd9a70056f96225c6509f0424135a3baf114af7fc7995/django_translator-1.2.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-09-03 14:30:42",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "django-translator"
}