OctoberCMS Translation Reference
October 4, 2020

OctoberCMS Translation Reference

Just a quick collections of notes regarding multilingual sites built with OctoberCMS + the Rainlab Translate plugin

To get started, make sure to install the Rainlab Translate plugin on your site and read their documentation!

Basically, first set up languages on the backend "Manage languages" tab.

Then, on any CMS page or layout etc. instead of writing a simple string, "My Great Website", write {{ 'My Great Website'|_ }}

You can then go to your backend, "Translate Messages" tab, click "Scan for messages", and add your translation.

Pluralization (None? One? Many?)

October makes use of (or at least used to make use of) the Laravel tans_choice() function. Here are examples of using 2 or more "choices":

Two choices:
{{ 'There are no apples|There are :number applies!'|__(2, { number: 'two' }) }}

Several choices:
{{ '{0} There are no apples|{1} There is one apple|]1,19] There are :number apples|[20,Inf[ There are many apples'|__( 3, {number: 'three'} ) }}

Reference: Translate plugin issue #144

Overriding translations of plugins

Not everything is available for localization from the back-end "Translate messages" page. Plugins can also define language files, which are located in the "lang" folder of the plugin. But you can override this by copying it to a root "lang" folder in your site.

So, for example, to add hungarian translation (language code "hu") to the nifty GDPR plugin, first find the original english translation file. It is in: /plugins/offline/gdpr/lang/en/lang.php

Now, create a folder and copy-and-paste the lang.php file into it: /lang/hu/offline/gdpr/

As you can see the folder structure is somewhat backwards to how it is with the plugin, but that's fine. Then, simply edit the file and add your translations!

You could also just override the original strings by creatint the file in /lang/en/offline/gdpr/

OctoberCMS Translation Reference
Share this