Skip to main content

Translating Flarum

info

This documentation covers the technical structure of language packs. Read this article for information on how to start / contribute to a Flarum language pack.

Declaring a Language Pack

Language packs should be their own extensions, with no other code / logic included.

The LanguagePack extender allows you to define that your extension is a language pack.

This extender has no setters. All you have to do is instantiate it, make sure you language pack is in the locale folder, and you're done!

Here's a quick example from Flarum English:

<?php

return new Flarum\Extend\LanguagePack();

The composer.json will also need some special values. It now needs a flarum-locale info object in extra, like flarum-extension. You can simply insert the following underneath the value of flarum-extension while remaining inside extra:

"flarum-locale": {
"code": "en",
"title": "English"
}

And that's it! It should work out of the box.

Translation Files

Translation files should go in the locale directory. Each file should be named EXTENSION_ID.yml, where EXTENSION_ID is the extension's ID.

The contents of the file should correspond to the extension's english translations, with the values translated in your language. See our internationalization docs for more information.

DayJS Translations

Flarum use the DayJS library to format and internationalize dates.

You can create a config.js file in the locale directory to configure date internationalization for your language.

The file should look like:

dayjs.locale('xx');

where the xx can be copied from https://unpkg.com/browse/[email protected]/locale/ for your language.

Alternatively, instead of using a compiled locale object, you can directly create one as per the dayjs documentation. This is slightly less efficient though.