Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using third party package for multi-language #13

Open
serdargkaya opened this issue Sep 11, 2018 · 6 comments
Open

Using third party package for multi-language #13

serdargkaya opened this issue Sep 11, 2018 · 6 comments

Comments

@serdargkaya
Copy link

Hi @matthiask

What do you think about using django-parler or your repo django-translated-fields for multi-language functionality in feincms3.

And what do you think drawbacks are ?

Btw. I need to implement drag&drop functionality for client using jstree or something. Will you accept pr for this?

@matthiask
Copy link
Member

What would you use parler or translated fields for? Translating page titles etc? How would you fill in the content for different languages? Or add translated fields to all plugins?

We mostly work with one page tree per language. Sometimes, having to duplicate the same changes in the tree in different places is annoying, but the liberty gained by not having to synchronize everything is worth it (for us, maybe not for everyone). Editing content in only one language at a time seems to give a less cluttered interface.

Regarding parler vs. translated fields: If I wanted to use parler or modeltranslation I wouldn't have started developing a different package for the same thing :-) just today I lost an hour to modeltranslations' idiosyncrasies resp. to its magic behavior. More: https://406.ch/writing/django-translated-fields-localized-model-fields-without-magic/

@matthiask
Copy link
Member

Btw, https://www.dwheeler.com/sloccount/ really isn't everything, but for django-translated-fields it reports 77 lines and for django-parler 2009 lines of code (both excluding tests)

So in terms of complexity there's a big big difference.

@serdargkaya
Copy link
Author

Yes we can't use parler because it's really huge. Btw i really like your library first approach and low maintenance software designs. Thats why im here :)

I just like the idea of having connecting the pages between languages.

Right now i'm using changelist filter to separate the languages.
screenshot from 2018-09-12 11-43-39

But i like the approach that parler using like this.
image

@matthiask
Copy link
Member

matthiask commented Sep 12, 2018

Hmm maybe there is an easy way to replicate this interface using django-content-editor's tabbed fieldsets?

Completely untested:

@admin.register(models.Stuff)
class StuffAdmin(admin.ModelAdmin):
    class Media:
        css = {"all": ["content_editor/content_editor.css"]},
        js = [
            "content_editor/jquery-ui-1.11.4.custom.min.js",
            "content_editor/tabbed_fieldsets.js",
        ]

    def get_fieldsets(self, request, obj=None):
        unspecific_fields = []
        specific_fields = defaultdict(list)

        for field in self.model._meta.get_fields():
            if not field.editable:  # Maybe other criteria to skip?
                continue
            if hasattr(field, "_translated_field_language_code"):
                specific_fields[field._translated_field_language_code].append(field.name)
            else:
                unspecific_fields.append(field.name)

        fieldsets = [
            (None, {"fields": unspecific_fields}),
        ]
        for language_code, language_title in settings.LANGUAGES:
            fieldsets.append((language_title, {"fields": specific_fields[language_code], "classes": ("tabbed",)}))

        return fieldsets

Since we're collecting all fields into language-specific fieldsets I wouldn't use TranslatedFieldsAdmin -- the individual fields' labels do not have to contain the language code too.

@serdargkaya
Copy link
Author

serdargkaya commented Sep 14, 2018

I will try to come up with something later. But i don't know that you want to accept pull request that all languages are managed on one tree?

@matthiask
Copy link
Member

matthiask commented Sep 23, 2018

I was just thinking again about this (sorry for the long wait)

I don't remember which project, but I experimented with a multilingual page tree once. The page model didn't require many changes but supporting both in the official feincms3 package -- I'm not sure about that. I would prefer to do it the same way feincms3-sites does it, with an external package with its own page model. The documentation for feincms3-sites is part of the official documentation and I would certainly agree to expand the guide on multilingual sites to include a discussion of this additional option too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants