django-translate-gettext


Namedjango-translate-gettext JSON
Version 0.3.6 PyPI version JSON
download
home_pagehttps://github.com/alpden550/django-translate-gettext
SummaryDjango app to wrap app files class fields to gettext calling for the given apps
upload_time2024-05-06 08:32:58
maintainerNone
docs_urlNone
authorDenis Novikov
requires_python<4.0,>=3.11
licenseMIT
keywords django django-orm django app ast orm
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Django-translate-getetxt

This is a django app that allows you to wrap django applications files fields with a gettext translation field (not for Pycharm and docker-compose python interpretator).

And translate the `.po` files fields with the help of the Google Translator (use --makemessages flag).

It uses gettext package to achieve this and wrapping fields.

v.0.3.0—Added creating po files for the given lang code and filling the po files with the translation fields
(Use Google Translator)

v.0.2.2—Added support for clean models methods and ValidationError messages

v0.2.0-Added support for admin files

v0.1.0—Initial release with models files support


## Installation

```bash
poetry add django-translate-gettext

# or
poetry add git+https://github.com/alpden550/django-translate-gettext.git
```

## Usage

Add `django_translate` to your `INSTALLED_APPS` setting like this:

```python
INSTALLED_APPS = [
    ...,
    'django_translate_gettext',
    ...
]
```

Call django commands to create the translation fields for your apps. 

Use `--format` or `-f` flag to call ruff format tool after files changed.

Use `--makemessages` or `-mm` flag and pass locales to create translated `.po` files

Example:

```bash
python manage.py translate app1 app2 app3 app4 --format --makemessages ru fr it de ar def
```

[![asciicast](https://asciinema.org/a/3ALfQ9tpAzML4RZQXbYAeJxCE.svg)](https://asciinema.org/a/3ALfQ9tpAzML4RZQXbYAeJxCE)

Models files before:

`demo/models/base.py`
```python
from django.db import models


class Base(models.Model):
    created_at = models.DateTimeField("Date Created", auto_now_add=True)
    updated_at = models.DateTimeField(verbose_name="Date Updated", auto_now=True)
    items = models.JSONField(default=dict, blank=True, null=True)

    class Meta:
        abstract = True
```

`demo/models/user.py`
```python
import csv
from pathlib import Path
from django.db import models

from demo.models import Base


class CustomQuerySet(models.QuerySet):
    def filter(self, *args, **kwargs):
        return super().filter(*args, **kwargs).order_by("id")


class UserTypes(models.TextChoices):
    ADMIN = "admin", "Admin"
    USER = "user", "User"
    STAFF = "staff", "Staff"


class CustomUser(Base):
    class _InnerTypes(models.TextChoices):
        NEW = "new", "New"
        OLD = "old", "Old"

    username = models.CharField("User Name", max_length=100, help_text="This is the help text")
    email = models.EmailField()
    password = models.CharField(max_length=100)
    created_at = models.DateTimeField("Date Created", auto_now_add=True)
    updated_at = models.DateTimeField(verbose_name="Date Updated", auto_now=True)
    first_name = models.CharField(verbose_name="First_Name", max_length=25)
    last_name = models.CharField("Last_Name", max_length=25)
    is_active = models.BooleanField(default=True)
    choices = models.CharField(max_length=5, choices=UserTypes.choices, default=UserTypes.USER)
    groups = models.ManyToManyField("auth.Group", verbose_name="Custom Groups", blank=True)
    owner = models.ForeignKey("auth.User", related_name="users", on_delete=models.CASCADE, blank=True, null=True)

    objects = CustomQuerySet.as_manager()

    class Meta:
        verbose_name = "Own Custom User"
        verbose_name_plural = "Own Custom Users"
        ordering = ("-created_at",)
        get_latest_by = ("-created_at", "is_active")
```

Models files after:

`demo/models/base.py`
```python
from django.db import models
from django.utils.translation import gettext_lazy as _


class Base(models.Model):
    created_at = models.DateTimeField(_("Date Created"), auto_now_add=True)
    updated_at = models.DateTimeField(verbose_name=_("Date Updated"), auto_now=True)
    items = models.JSONField(verbose_name=_("Items"), default=dict, blank=True, null=True)

    class Meta:
        abstract = True
```

`demo/models/user.py`
```python
import csv
from pathlib import Path
from django.db import models
from demo.models import Base
from django.utils.translation import gettext_lazy as _


class CustomQuerySet(models.QuerySet):
    def filter(self, *args, **kwargs):
        return super().filter(*args, **kwargs).order_by("id")


class UserTypes(models.TextChoices):
    ADMIN = ("admin", _("Admin"))
    USER = ("user", _("User"))
    STAFF = ("staff", _("Staff"))


class CustomUser(Base):
    class _InnerTypes(models.TextChoices):
        NEW = ("new", _("New"))
        OLD = ("old", _("Old"))

    username = models.CharField(_("User Name"), max_length=100, help_text=_("This is the help text"))
    email = models.EmailField(_("Email"))
    password = models.CharField(verbose_name=_("Password"), max_length=100)
    created_at = models.DateTimeField(_("Date Created"), auto_now_add=True)
    updated_at = models.DateTimeField(verbose_name=_("Date Updated"), auto_now=True)
    first_name = models.CharField(verbose_name=_("First_Name"), max_length=25)
    last_name = models.CharField(_("Last_Name"), max_length=25)
    is_active = models.BooleanField(verbose_name=_("Is_Active"), default=True)
    choices = models.CharField(
        verbose_name=_("Choices"), max_length=5, choices=UserTypes.choices, default=UserTypes.USER
    )
    groups = models.ManyToManyField("auth.Group", verbose_name=_("Custom Groups"), blank=True)
    owner = models.ForeignKey(
        "auth.User", verbose_name=_("Owner"), related_name="users", on_delete=models.CASCADE, blank=True, null=True
    )
    objects = CustomQuerySet.as_manager()

    class Meta:
        verbose_name = _("Own Custom User")
        verbose_name_plural = _("Own Custom Users")
        ordering = ("-created_at",)
        get_latest_by = ("-created_at", "is_active")
```

Don't forget to check the changes before call `makemigrations` and `migrate` commands.

Don't forget to fill the settings.py like example file with the recommended Django settings before calling the `makemessaging` command.

```python
# settings.py
LANGUAGE_CODE = "en"
USE_I18N = True
USE_L10N = True
USE_TZ = True
LOCALE_PATHS = [Path(BASE_DIR, "locale")]
LANGUAGES = [
    ("en", "English"),
    ("ru", "Russian"),
]
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/alpden550/django-translate-gettext",
    "name": "django-translate-gettext",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.11",
    "maintainer_email": null,
    "keywords": "django, django-orm, django app, ast, orm",
    "author": "Denis Novikov",
    "author_email": "alpden550@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/db/d3/5dbdf775b3b9eed6e72a3c44c1bebaa69197ed0b43f535b542ec5cc42b05/django_translate_gettext-0.3.6.tar.gz",
    "platform": null,
    "description": "# Django-translate-getetxt\n\nThis is a django app that allows you to wrap django applications files fields with a gettext translation field (not for Pycharm and docker-compose python interpretator).\n\nAnd translate the `.po` files fields with the help of the Google Translator (use --makemessages flag).\n\nIt uses gettext package to achieve this and wrapping fields.\n\nv.0.3.0\u2014Added creating po files for the given lang code and filling the po files with the translation fields\n(Use Google Translator)\n\nv.0.2.2\u2014Added support for clean models methods and ValidationError messages\n\nv0.2.0-Added support for admin files\n\nv0.1.0\u2014Initial release with models files support\n\n\n## Installation\n\n```bash\npoetry add django-translate-gettext\n\n# or\npoetry add git+https://github.com/alpden550/django-translate-gettext.git\n```\n\n## Usage\n\nAdd `django_translate` to your `INSTALLED_APPS` setting like this:\n\n```python\nINSTALLED_APPS = [\n    ...,\n    'django_translate_gettext',\n    ...\n]\n```\n\nCall django commands to create the translation fields for your apps. \n\nUse `--format` or `-f` flag to call ruff format tool after files changed.\n\nUse `--makemessages` or `-mm` flag and pass locales to create translated `.po` files\n\nExample:\n\n```bash\npython manage.py translate app1 app2 app3 app4 --format --makemessages ru fr it de ar def\n```\n\n[![asciicast](https://asciinema.org/a/3ALfQ9tpAzML4RZQXbYAeJxCE.svg)](https://asciinema.org/a/3ALfQ9tpAzML4RZQXbYAeJxCE)\n\nModels files before:\n\n`demo/models/base.py`\n```python\nfrom django.db import models\n\n\nclass Base(models.Model):\n    created_at = models.DateTimeField(\"Date Created\", auto_now_add=True)\n    updated_at = models.DateTimeField(verbose_name=\"Date Updated\", auto_now=True)\n    items = models.JSONField(default=dict, blank=True, null=True)\n\n    class Meta:\n        abstract = True\n```\n\n`demo/models/user.py`\n```python\nimport csv\nfrom pathlib import Path\nfrom django.db import models\n\nfrom demo.models import Base\n\n\nclass CustomQuerySet(models.QuerySet):\n    def filter(self, *args, **kwargs):\n        return super().filter(*args, **kwargs).order_by(\"id\")\n\n\nclass UserTypes(models.TextChoices):\n    ADMIN = \"admin\", \"Admin\"\n    USER = \"user\", \"User\"\n    STAFF = \"staff\", \"Staff\"\n\n\nclass CustomUser(Base):\n    class _InnerTypes(models.TextChoices):\n        NEW = \"new\", \"New\"\n        OLD = \"old\", \"Old\"\n\n    username = models.CharField(\"User Name\", max_length=100, help_text=\"This is the help text\")\n    email = models.EmailField()\n    password = models.CharField(max_length=100)\n    created_at = models.DateTimeField(\"Date Created\", auto_now_add=True)\n    updated_at = models.DateTimeField(verbose_name=\"Date Updated\", auto_now=True)\n    first_name = models.CharField(verbose_name=\"First_Name\", max_length=25)\n    last_name = models.CharField(\"Last_Name\", max_length=25)\n    is_active = models.BooleanField(default=True)\n    choices = models.CharField(max_length=5, choices=UserTypes.choices, default=UserTypes.USER)\n    groups = models.ManyToManyField(\"auth.Group\", verbose_name=\"Custom Groups\", blank=True)\n    owner = models.ForeignKey(\"auth.User\", related_name=\"users\", on_delete=models.CASCADE, blank=True, null=True)\n\n    objects = CustomQuerySet.as_manager()\n\n    class Meta:\n        verbose_name = \"Own Custom User\"\n        verbose_name_plural = \"Own Custom Users\"\n        ordering = (\"-created_at\",)\n        get_latest_by = (\"-created_at\", \"is_active\")\n```\n\nModels files after:\n\n`demo/models/base.py`\n```python\nfrom django.db import models\nfrom django.utils.translation import gettext_lazy as _\n\n\nclass Base(models.Model):\n    created_at = models.DateTimeField(_(\"Date Created\"), auto_now_add=True)\n    updated_at = models.DateTimeField(verbose_name=_(\"Date Updated\"), auto_now=True)\n    items = models.JSONField(verbose_name=_(\"Items\"), default=dict, blank=True, null=True)\n\n    class Meta:\n        abstract = True\n```\n\n`demo/models/user.py`\n```python\nimport csv\nfrom pathlib import Path\nfrom django.db import models\nfrom demo.models import Base\nfrom django.utils.translation import gettext_lazy as _\n\n\nclass CustomQuerySet(models.QuerySet):\n    def filter(self, *args, **kwargs):\n        return super().filter(*args, **kwargs).order_by(\"id\")\n\n\nclass UserTypes(models.TextChoices):\n    ADMIN = (\"admin\", _(\"Admin\"))\n    USER = (\"user\", _(\"User\"))\n    STAFF = (\"staff\", _(\"Staff\"))\n\n\nclass CustomUser(Base):\n    class _InnerTypes(models.TextChoices):\n        NEW = (\"new\", _(\"New\"))\n        OLD = (\"old\", _(\"Old\"))\n\n    username = models.CharField(_(\"User Name\"), max_length=100, help_text=_(\"This is the help text\"))\n    email = models.EmailField(_(\"Email\"))\n    password = models.CharField(verbose_name=_(\"Password\"), max_length=100)\n    created_at = models.DateTimeField(_(\"Date Created\"), auto_now_add=True)\n    updated_at = models.DateTimeField(verbose_name=_(\"Date Updated\"), auto_now=True)\n    first_name = models.CharField(verbose_name=_(\"First_Name\"), max_length=25)\n    last_name = models.CharField(_(\"Last_Name\"), max_length=25)\n    is_active = models.BooleanField(verbose_name=_(\"Is_Active\"), default=True)\n    choices = models.CharField(\n        verbose_name=_(\"Choices\"), max_length=5, choices=UserTypes.choices, default=UserTypes.USER\n    )\n    groups = models.ManyToManyField(\"auth.Group\", verbose_name=_(\"Custom Groups\"), blank=True)\n    owner = models.ForeignKey(\n        \"auth.User\", verbose_name=_(\"Owner\"), related_name=\"users\", on_delete=models.CASCADE, blank=True, null=True\n    )\n    objects = CustomQuerySet.as_manager()\n\n    class Meta:\n        verbose_name = _(\"Own Custom User\")\n        verbose_name_plural = _(\"Own Custom Users\")\n        ordering = (\"-created_at\",)\n        get_latest_by = (\"-created_at\", \"is_active\")\n```\n\nDon't forget to check the changes before call `makemigrations` and `migrate` commands.\n\nDon't forget to fill the settings.py like example file with the recommended Django settings before calling the `makemessaging` command.\n\n```python\n# settings.py\nLANGUAGE_CODE = \"en\"\nUSE_I18N = True\nUSE_L10N = True\nUSE_TZ = True\nLOCALE_PATHS = [Path(BASE_DIR, \"locale\")]\nLANGUAGES = [\n    (\"en\", \"English\"),\n    (\"ru\", \"Russian\"),\n]\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Django app to wrap app files class fields to gettext calling for the given apps",
    "version": "0.3.6",
    "project_urls": {
        "Homepage": "https://github.com/alpden550/django-translate-gettext",
        "Repository": "https://github.com/alpden550/django-translate-gettext"
    },
    "split_keywords": [
        "django",
        " django-orm",
        " django app",
        " ast",
        " orm"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "15a025cc01c64957502bf43be5f91862dd6a17ccc10890488dd98a7b6f8ffc07",
                "md5": "ce37b0e44c4e2d66134e2cbe91fffb65",
                "sha256": "e99c8afbf1d9dcc595b2434775bee3ff074c98519356d5763c8ab8a995175e62"
            },
            "downloads": -1,
            "filename": "django_translate_gettext-0.3.6-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "ce37b0e44c4e2d66134e2cbe91fffb65",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.11",
            "size": 11937,
            "upload_time": "2024-05-06T08:32:57",
            "upload_time_iso_8601": "2024-05-06T08:32:57.581026Z",
            "url": "https://files.pythonhosted.org/packages/15/a0/25cc01c64957502bf43be5f91862dd6a17ccc10890488dd98a7b6f8ffc07/django_translate_gettext-0.3.6-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "dbd35dbdf775b3b9eed6e72a3c44c1bebaa69197ed0b43f535b542ec5cc42b05",
                "md5": "ee0db6705c60504ea6afc580ce3a6fc7",
                "sha256": "3b804697cfcaca11477bb88c2de52c95d9231fd2d42c7154f31fcda1764589f8"
            },
            "downloads": -1,
            "filename": "django_translate_gettext-0.3.6.tar.gz",
            "has_sig": false,
            "md5_digest": "ee0db6705c60504ea6afc580ce3a6fc7",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.11",
            "size": 10915,
            "upload_time": "2024-05-06T08:32:58",
            "upload_time_iso_8601": "2024-05-06T08:32:58.843340Z",
            "url": "https://files.pythonhosted.org/packages/db/d3/5dbdf775b3b9eed6e72a3c44c1bebaa69197ed0b43f535b542ec5cc42b05/django_translate_gettext-0.3.6.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-06 08:32:58",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "alpden550",
    "github_project": "django-translate-gettext",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "django-translate-gettext"
}
        
Elapsed time: 0.21096s