Global language-switching action

In the previous recipes, we saw that the languages change on the basis of the current language preferences in the browser. However, now, we want a mechanism where we can switch the language to be used irrespective of the language in the browser. For this, we need to handle the language at the application level.

Getting ready

We start by modifying the application from the last recipe, Lazy evaluation and the gettext/ngettext functions, to accommodate the changes to enable language switching. We will add an extra URL part to all our routes to add the current language. We can just change this language in the URL to switch between languages.

How to do it…

The first change that we need to do is modify all our URL rules ...

Get Flask Framework Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.