Skip to content

Layout

Templates

The frontend of didmos2-auth is based upon Django Framework. The Django templates are stored in the customer repository, at the location: customer-auth/didmos2-auth-fe/templates. These templates use the static resources, for example, css, fonts, and images all placed at the location: customer-auth/didmos2-auth-fe/assets.

Please refer to microservices/client-based-templates.md for the documentation of the client-based-templates microservice.

Translations

The Django i18n feature is used for providing multi language support on these sites. See: https://docs.djangoproject.com/en/2.1/topics/i18n/

didmos2-auth-fe/src/didmos2_auth_fe/settings.py defines LANGUAGES, which contains the full set of active languages in a particular deployment, e.g.:

LANGUAGES = [
    ('en', _(u'English')),
    ('de', _(u'Deutsch')),
]

The default configuration in didmos2-auth (the general project) enables English and German. It's possible to extend this list by including a customer module in customer-auth, which overrides LANGUAGES to contain a customized list of languages.

For each language used, a translation file (both clear text and compiled) must be present in customer-auth/didmos2-auth-fe/locale. The po file contains the translations in clear-text, e.g.

msgid "didmos2 auth - Discovery"
msgstr "didmos2 auth - Auswahl"

msgid is the id of the string, which is also used in templates. msgstr is the translated version for that particular language.

The mo contains the compiled version of that file (see below) and must also be updated with any changes

Each template includes the language switcher, which displays a drop down menu on the top right, see: didmos2-auth/files/satosa/templates/layout.html

The language switcher automatically parses all enabled languages, see: customer-auth/didmos2-auth-fe/templates/inc/language-switcher.html

All the translations are required to be inside the customer project. If a new language is required to be added, this needs to be added in the LANGUAGES list in didmos2-auth-fe/src/didmos2_auth_fe/settings.py.

In a customer project this could look like this:

# The following files are present in the customer project:
# customer-auth/didmos2-auth-fe/locale/de/LC_MESSAGES/django.mo
# customer-auth/didmos2-auth-fe/locale/de/LC_MESSAGES/django.po

Compiling translation files

When the po file was created (for a new language) or changed, the following command must be performed in order to compile the mo files:

single file

msgfmt django.po -o django.mo

all files in the directory

cd customer-auth/didmos2-auth-fe/locale/ && for d in */ ; do msgfmt "$d"LC_MESSAGES/django.po -o "$d"LC_MESSAGES/django.mo; done && cd ../../../

Encoding

For languages, that require UTF-8 encoding, the po file must contain the following header:

msgid ""
msgstr ""
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"

How to add new languages

Adding a new language consists of the following steps:

  • Create the file structure and po file in customer-auth/didmos2-auth-fe/locale
  • Compile the mo file
  • Adding the language code in settings.py in didmos2-auth