Implementing the global language-switching action
In the previous recipes, we saw that the language changes based on the current language preferences in the browser. Now, however, we want a mechanism where we can switch the language being used, irrespective of the language in the browser. In this recipe, we will understand how to handle changing the language at the application level.
Getting ready
We start by modifying the application from the last recipe, Implementing 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 allow us to add the current language. We can just change this language part in the URL in order to switch between languages.
How to do it…
Observe the following steps to understand how to implement language switching globally:
- First, modify all the URL rules to accommodate an extra URL part.
@catalog.route('/')
will become...