wagtail / wagtail-localize

Translation plugin for Wagtail CMS
https://wagtail-localize.org/
Other
222 stars 84 forks source link

Pages that don't have the supported language. #678

Closed bingimar closed 1 year ago

bingimar commented 1 year ago

I have a site in around 20 languages. I'm using wagtail localize to handle translation of articles.

When a user has selected Turkish and clicks the articles link the site defaults to English BUT the navbar flag changes to English as well.

What I would like to do is if article is not available in the selected language, it defaults to english but the flag in the nav is still in the selected language in this case the Turkish flag.

Help greatly appreciated.

zerolab commented 1 year ago

Hey @bingimar,

wagtail-localize does not provide any flag functionality, so that is a custom implementation. I suggest joining the Wagtail Slack (see instructions https://github.com/wagtail/wagtail/wiki/Slack) and asking in #support or #multi-language, providing additional details such a code snippet for your navbar which shows the language and flag, as well as some example URLs

The wagtail-localize docs do have an example for a language switcher (https://www.wagtail-localize.org/tutorial/4-templates/#adding-a-language-switcher), but even that doesn't do anything with the language.

Note: closing this as it is an implementation specific question

enzedonline commented 1 year ago

@zerolab The language switcher example in the tutorial is really flawed. It only offers links to translations of the currently visited page. If the page isn't translated, or it's a non-Wagtail page (such as /search) no languages would be shown.

A switcher should always show all available languages for the site regardless of the current page translation status, should be looping through Locale.objects.all() and building the links off that.

zerolab commented 1 year ago

@enzedonline a PR changing that will be more than welcome ;)

enzedonline commented 1 year ago

@zerolab it's probably a bit long for that page ... requires a template tag to determine the best translation page and handle routable pages properly (get_translation will drop the kwargs), and a routed view for django pages plus activating the language and setting the language cookie ... then there's the flag sprite sheet and the menu template ...

I'll write a blog for it one of these days ...

switcher