Git Product home page Git Product logo

webu / wagtail-parler Goto Github PK

View Code? Open in Web Editor NEW
4.0 3.0 3.0 211 KB

Manage your translations and internationalization with "parler" inside "wagtail" for your custom models (via modeladmin or wagtail snippets) 🧀 🐦

Home Page: https://wagtail-parler.readthedocs.io/

License: BSD 3-Clause "New" or "Revised" License

Shell 0.86% Python 96.98% HTML 2.16%
cms django parler translation wagtail

wagtail-parler's Introduction

Wagtail Parler 🧀 🐦

Stable Version Code style: black Checked with mypy Imports: isort semver Documentation Status

Brings "omelette du fromage" 🧀 from parler into wagtail 🐦 for your custom models (via modeladmin or wagtail snippets)

Wagtail Parler Logo

Wagtail Parler helps you to use django-parler inside wagtail to translate your customs models. It works for wagtail-modeladmin (which is now deprectaed) and also the new official way: wagtail's snippets.

Translated and untranslated tabs

Tests, QA, consistency and compatibility

This app is tested to runs with:

  • Django 3.2, 4.2
  • Wagtail 4.1, 4.2, 5.0, 5.1
  • Parler 2.3 (probably older ones to, it's just not tested)
  • Python 3.7, 3.9, 3.11

To ensure code quality and consistency:

Why

There is already an internationalisation support in wagtail via their own language features called wagtail-localize. This app also support wagtail modeladmin. But the approach of wagtail-localize could be unconvenient as translations are stored in the same table than "main instances", resulting specific queryset and managers to manage your models.
For app's like treebeard, it can break the logic of your tree.

For those reasons, you could prefer to use django-parler as translations approach. Wagtail Parler is fit to you: it will allow you to use django-parler to translate your own models and still have a usefull wagtail interface to manage translations (via official wagtail's snippet admin but also with the old wagtail-modeladmin)

Installation

Install the package via pip. We consider you already have django-parler and wagtail installed.

pip install wagtail-parler

Then, in settings.py, add wagtail_parler to the installed apps.

# settings.py

INSTALLED_APPS = [
    # …
    "wagtail_parler",
    # …
]

Basic Usage

You just have to add ParlerSnippetAdminMixin to your SnippetViewSet (or ParlerModelAdminMixin to your ModelAdmin), et voilà, you are ready to eat omelette du fromage.

from wagtail.snippets.views.snippets import SnippetViewSet
from wagtail.snippets.models import register_snippet
from wagtail_parler.handlers import ParlerSnippetAdminMixin
from .models import Food


class FoodAdmin(ParlerSnippetAdminMixin, SnippetViewSet):
    model = Food

register_snippet(FoodAdmin)

# or for an usage with wagtail-modeladmin:

from wagtail.contrib.modeladmin.options import ModelAdmin, modeladmin_register
from wagtail_parler.handlers import ParlerModelAdminMixin
from .models import Food

class FoodAdmin(ParlerModelAdminMixin, ModelAdmin):
    model = Food

modeladmin_register(FoodAdmin)

Extra 🧀🐦

More advanced usage, tests, etc., are documented in the doc.

Maître Wagtail, sur un arbre perché,
Tenait en son bec une omelette du fromage.
Maître Webu, à l'envie de parler,
Lui tint à peu près ce langage :
Et bonjour, Monsieur Wagtail.
Que de beaux commits ! quelle merveille !
Sans mentir, si votre codage
Se rapporte à votre plumage,
Vous êtes le Phénix des hôtes de ces dépots. …

From « Le Corbeau et le Renard » by Jean de La Fontaine, 1668.

wagtail-parler's People

Contributors

dylanncordel avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

wagtail-parler's Issues

django-parler and page

django-parler define a useful templatetag get_translated_url allowing language switch. For instance:

{% for language in languages %}
    {% get_translated_url language.code as tr_url %}
    <a href="{{ tr_url }}">
        <span class="btn {% if language.code == request.LANGUAGE_CODE %}active{% endif %}">{{ language.code|upper }}</span>
    </a>
{% endfor %}

however the internal of get_translated_url try to guess the current page (using potentially some hacky stuff, that works also for wagtail), and return get_absolute_url() of the best object found.

And here is the bug: wagtail Page object does not define a get_absolute_url but a get_url. So something like

def get_absolute_url(self):
    return self.localized.get_url()

in the Page model fix it.

Question: should it be in wagtail-parler, django-parler or wagtail ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.