In this dev log I will talk about the improved language support that will be coming soon in the next beta version.
Language files were introduced quite a few versions back but they were incomplete and far from comprehensive. In the next version the aim is to rectify this by moving many more hard-coded texts into the language files. In the current dev build there are now 10 times more language texts that are easily editable compare to the previous version. Various other changes and improvements are being made in relation to this too.
New Text FunctionsOne significant change is that language text is now output through functions (listed below) instead of referencing the array elements directly.
//Function example / what it does / what it outputs
txtUc('My text') // all upper case / "MY TEXT"
txtLc('My Text') // all lower case / "my text"
txtLf('My Text') // lower case first letter / "my Text"
txtUw('my text') // upper case first letter of each word / "My Text"
txtUf('my Text') // upper case first letter / "My Text"
txtUfo('my Text') // upper case first letter only / "My text"
Most commonly
txtUw() is used for button text and form labels etc. and
txtUf() for sentences such as tips and warning messages. These functions handle not only case change but translation too so the outputted text will depend on the selected language. The text passed into the function is checked against the
$txt array in the language files and if a match is found it will output the corresponding text in whatever language is set. If a text match is not found in the language files it will output the text that was initially passed into the function and it wont cause any error on the page. In general though you won't have to worry about these functions unless you are modifying or creating new content template files.
Individual Language PreferencesSpeaking of selected languages it will now be possible to change language based on session. This means everyone can select their preferred language independently of each other on the same website. Language preference is stored in a session cookie so when returning to the website it will remember what language was chosen previously. This personal language selection is separate to the main language setting for the CMS which is still set in the admin config page. If no preferred language is chosen then the main language is used as before.
Providing a multi-lingual site and allowing your visitors to change language is entirely up to you but if you do want to allow your visitors to choose a language you will need to provide a form/button or some equivalent to do so. For example the buttons below could be shown on the page to allow the user to pick either English or Irish as their preferred language.
<button type="submit" name="lang" value="en">English</button>
<button type="submit" name="lang" value="ga">Irish</button>
A drop down might be better when offering many languages. In the future we will likely add a template tag that will provide a quick out-of-the-box language selection.
In the admin area you can also change your preferred language by clicking on your name at the top beside the welcome text. This slides out a new preferences menu with links to language and password change. The settings menu has also been updated to use a similar slide out menu so some bonus UI/UX improvements there too.
It's worth noting that the main focus of the next update is to allow individual language selection for the admin area as there are further considerations with custom themes and page templates when it comes to providing a fully multilingual front-end. However many of the front-end texts for login pages, shopping pages etc. will be translated and it is possible to add custom texts to the language files if needed.
Future ConsiderationsLog text remains hard-coded in English for now although I think it makes sense to change this to use whatever the main language is set to. For this we may need to introduce error codes for error identification and troubleshooting purposes without language barrier.
Currently all email notifications sent by the CMS use whatever the main language is set to. It would be possible to store a users preferred language in their user details and then send emails to them in their preferred language. However this would be a more advanced feature so it wont be part of the next update but may be considered in the future if there is an interest for it. Another consideration with this is that sending emails in different languages might not be a good idea if the website admins/support do not speak those languages, so there would probably have to be a toggle option added for such a feature. For now I am just mentioning this here as a note/reminder to something that might possibly be added it in the future.
ContributingThe next beta version should hopefully be ready in few weeks and anyone who wants to add or contribute their own language texts the language files will be welcome to do so. We've already had some assistance from one of our Norwegian community members (thanks Bob!).
Language files can be found in
includes/language where each language has it's own folder containing it's language files. To add a new language simple copy the "en" folder and edit the files within. Make sure to rename the folder to match the ISO code for your language
https://www.w3schools.com/tags/ref_language_codes.aspNote that language files should be saved in
UTF-8 character encoding so that accented characters and other special characters are displayed correctly.