From Paul.Waite at digital.homeoffice.gov.uk Tue Mar 14 10:05:54 2017 Content-Type: multipart/mixed; boundary="===============5011802342479687187==" MIME-Version: 1.0 From: Paul Waite To: keycloak-dev at lists.jboss.org Subject: =?utf-8?q?=5Bkeycloak-dev=5D_Login_theme_templates=3A_getting_the_two-let?= =?utf-8?q?ter_code_for_the_page=E2=80=99s_current_language?= Date: Tue, 14 Mar 2017 14:05:49 +0000 Message-ID: <16A66CC2-1652-4977-B3F2-5D15942055CC@digital.homeoffice.gov.uk> --===============5011802342479687187== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable I=E2=80=99m a front-end web developer working on a Keycloak login theme for= the UK Home Office. The root template.ftl file in the base theme does not include a lang attrib= ute on its tag: I=E2=80=99m trying to add one, as it=E2=80=99s required by the W3C=E2=80=99= s Web Content Accessibility Guidelines (WCAG): - https://www.w3.org/TR/WCAG20/#meaning-doc-lang-id - https://www.w3.org/TR/WCAG20-TECHS/H57.html and useful for screen readers: - https://www.paciellogroup.com/blog/2016/06/using-the-html-lang-attrib= ute/ The value of the attribute should be the ISO 639 code for the main language= (e.g. English, Italian) that the page is written in. I tried getting this from the .locale template variable, but at least on th= e standalone server (2.5.4), this was always set to en_GB, even when intern= ationalization was enabled and the default language was set to a different = language (I tried with Italian). I can=E2=80=99t see anywhere else to access the language code for the page= =E2=80=99s current language. My current workaround is to loop though locale.supported (if locale is defi= ned), and if a supported locale=E2=80=99s label matches locale.current, gra= b the first two characters of the kc_locale query string parameter in the s= upported locale=E2=80=99s URL: <#assign LANG_CODE =3D "en"> <#if .locale??> <#assign LANG_CODE =3D .locale> <#if locale??> <#list locale.supported> <#items as supportedLocale> <#if supportedLocale.label =3D=3D locale.current> <#if supportedLocale.url?contains("?kc_locale=3D")> <#assign LANG_CODE =3D supportedLocale.url?keep_aft= er("?kc_locale=3D")[0..1]> <#if supportedLocale.url?contains("&kc_locale=3D")> <#assign LANG_CODE =3D supportedLocale.url?keep_aft= er("&kc_locale=3D")[0..1]> Obviously this depends on no two locales sharing the same label, and on the= first two characters of kc_locale being sufficient. It would be really useful if language code for the page=E2=80=99s current l= anguage were available in a template variable, and if this were used to pop= ulate the lang attribute on the HTML tag in the root login template. Paul Waite Associate Transform 60 Great Portland Street London W1W 7RT Mobile: +447764 752508 Email: paul.waite(a)transformuk.com Web: www.transformUK.com Follow us on Twitter @TransformUK Please ensure that any communication with Home Office Digital is via an off= icial account ending with digital.homeoffice.gov.uk or homeoffice.gsi.gov.u= k. This email and any files transmitted with it are private and intended so= lely for the use of the individual or entity to whom they are addressed. If= you have received this email in error please return it to the address it c= ame from telling them it is not for you and then delete it from your system= . Communications via the digital.homeoffice.gov.uk domain may be automatica= lly logged, monitored and/or recorded for legal purposes. This email messag= e has been swept for computer viruses. --===============5011802342479687187==--