Word every tour on the site#
A tour says “Next”, “Previous” and “Done”, a set of hints says “Got it” and a checklist says
“Get started”. This page shows how to change that text once for the whole site, with the
PAGE_TOURS_TEXT setting, instead of on every tour.
Change the text of the whole site#
Add
PAGE_TOURS_TEXTto your settings. Key it by the kind of declaration,"tour","hint"or"checklist", and then by the name of the text:PAGE_TOURS_TEXT = { "tour": {"nextBtnText": "Continue", "doneBtnText": "Finish"}, "hint": {"buttonText": "Understood"}, "checklist": {"title": "Your first steps"}, }
Restart the server. The setting is read once, when the package is imported, like most Django settings.
Open a page with a tour, hints or a checklist. Each one that does not word the text itself now shows yours.
A kind or name the package does not have is ignored, so check the spelling against the table below.
The texts#
The names are the fields of the declarations, spelled as Driver.js spells them.
Kind |
Text |
What it is |
|---|---|---|
|
|
The progress text, with |
|
|
The text of the next button. |
|
|
The text of the previous button. |
|
|
The text of the button on the last step. |
|
|
The accessible name of the close button. |
|
|
The text of the button of every popover of a set of hints. |
|
|
The heading of the checklist. |
|
|
The progress in the panel, with |
|
|
The progress on the launcher. |
A tour in a checklist item takes the "tour" texts, as a tour on a page does. A tour, hints or
checklist that PAGE_TOURS_OVERRIDES replaces takes them too.
Give one tour its own text#
A text that you set on a tour, on hints or on a checklist, or as the default of a subclass of one, wins over the setting. A text that you set on a step or a hint wins over both:
Tour(
name="dashboard",
steps=[
TourStep(title="Welcome", nextBtnText="Show me"),
TourStep(title="Reports"),
],
doneBtnText="Got it",
)
Here the first step’s button says “Show me”, the last step’s button says “Got it”, and every
other text comes from PAGE_TOURS_TEXT, or else from the package.
Translate the text#
A value is a string, or a lazy translation that is converted when the page renders, in the visitor’s language:
from django.utils.translation import gettext_lazy as _
PAGE_TOURS_TEXT = {"tour": {"nextBtnText": _("Continue")}}
Driver.js writes these texts into the page as HTML, so never build one from a visitor’s input.
How the setting works#
The setting replaces the package’s own default of each text it names. A declaration that sets nothing takes that default, and one that sets a text keeps it, so a tour written for one place does not change when the site’s wording does.
Because the setting is read at import, override_settings in a test does not change it. Set it
in the settings module your tests run with.