Metadata-Version: 2.1
Name: wagtail-pagetranslation
Version: 0.0.1
Summary: Allows to translate specific pages without replicating all wagtail pages tree structure.
Author-email: Ihor Marhitych <dest81@gmail.com>, Jura Zakarija <jzakarija@ripe.net>
Requires-Python: >=3.8
Description-Content-Type: text/markdown
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Framework :: Django
Classifier: Framework :: Django :: 4.2
Classifier: Framework :: Django :: 5.0
Classifier: Framework :: Wagtail
Classifier: Framework :: Wagtail :: 5
Classifier: Framework :: Wagtail :: 6
Requires-Dist: Django>=4.2
Requires-Dist: Wagtail>=5.2
Requires-Dist: tox==4.11.3 ; extra == "ci"
Requires-Dist: tox-gh-actions==3.1.3 ; extra == "ci"
Requires-Dist: dj-database-url==2.1.0 ; extra == "testing"
Requires-Dist: pre-commit==3.4.0 ; extra == "testing"
Requires-Dist: pytest==8.1.1 ; extra == "testing"
Requires-Dist: pytest-cov==5.0.0 ; extra == "testing"
Requires-Dist: pytest-django==4.8.0 ; extra == "testing"
Project-URL: Home, https://github.com/dest81/wagtail-pagetranslation
Provides-Extra: ci
Provides-Extra: testing

# Wagtail pagetranslation

Allows to translate specific pages without replicating all wagtail pages tree structure.

[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
[![PyPI version](https://badge.fury.io/py/wagtail-pagetranslation.svg)](https://badge.fury.io/py/wagtail-pagetranslation)
[![pagetranslation CI](https://github.com/dest81/wagtail-pagetranslation/actions/workflows/test.yml/badge.svg)](https://github.com/dest81/wagtail-pagetranslation/actions/workflows/test.yml)

## Links

- [Documentation](https://github.com/dest81/wagtail-pagetranslation/blob/main/README.md)
- [Changelog](https://github.com/dest81/wagtail-pagetranslation/blob/main/CHANGELOG.md)
- [Contributing](https://github.com/dest81/wagtail-pagetranslation/blob/main/CONTRIBUTING.md)
- [Discussions](https://github.com/dest81/wagtail-pagetranslation/discussions)
- [Security](https://github.com/dest81/wagtail-pagetranslation/security)

## Installation

- `python -m pip install wagtail-pagetranslation`


## How to use

Add "wagtail_pagetranslation" to list of applications after all wagtail apps

```
INSTALLED_APPS = [
    "your_wagtail_app_1",
    "your_wagtail_app_2",
    ...
    "wagtail_pagetranslation",
    ...
]
```

Set default language for wagtail_pagetranslation app

```
WAGTAIL_PAGETRANSLATION_DEFAULT_LANGUAGE = "en"
```

by default settings.LANGUAGES will be used

```
LANGUAGES = [
    ("en", "English"),
    ("nl", "Dutch"),
    ("uk", "Ukrainian")
]
```

or you can specify custom list

```
WAGTAIL_PAGETRANSLATION_LANGUAGES = [
    ("en", "English"),
    ("nl", "Dutch"),
    ("uk", "Ukrainian")
]
```

To make available translation per page type add TranslationMixin to your custom Page class.
**Note:** mixin should be added before Page class.

```
from wagtail_pagetranslation.translation import TranslationMixin

class HomePage(TranslationMixin, Page):
    # list of fields that should have translation
    translatable_fields = ["title", ...]

```

By default URL for translated page is page url + `?lang=<lang_code>`
This can be change by overriding get_language method:

```
from wagtail_pagetranslation.translation import TranslationMixin as BaseTranslationMixin

class TranslationMixin(BaseTranslationMixin):
    # list of fields that should have translation
    translatable_fields = ["title", ...]

    def get_language(self, request):
        return request.GET.get("language")

```


## Contributing

### Install

To make changes to this project, first clone this repository:

```sh
git clone https://github.com/dest81/wagtail-pagetranslation.git
cd wagtail-pagetranslation
```

With your preferred virtualenv activated, install testing dependencies:

#### Using pip

```sh
python -m pip install --upgrade pip>=21.3
python -m pip install -e '.[testing]' -U
```

#### Using flit

```sh
python -m pip install flit
flit install
```

### pre-commit

Note that this project uses [pre-commit](https://github.com/pre-commit/pre-commit).
It is included in the project testing requirements. To set up locally:

```shell
# go to the project directory
$ cd wagtail-pagetranslation
# initialize pre-commit
$ pre-commit install

# Optional, run all checks once for this, then the checks will run only on the changed files
$ git ls-files --others --cached --exclude-standard | xargs pre-commit run --files
```

### How to run tests

Now you can run tests as shown below:

```sh
tox
```

or, you can run them for a specific environment `tox -e python3.11-django4.2-wagtail5.1` or specific test
`tox -e python3.11-django4.2-wagtail5.1-sqlite wagtail-pagetranslation.tests.test_file.TestClass.test_method`

To run the test app interactively, use `tox -e interactive`, visit `http://127.0.0.1:8020/admin/` and log in with `admin`/`changeme`.

