# Translating Flarum

TIP

The Flarum Foundation has created the "flarum-lang" organization to support translators and ensure continuous availability of language packs. You can learn more about this by visiting the GitHub repository (opens new window). If you want to support an existing language pack or start a new translation, it's best to get in touch with the flarum-lang team (opens new window).

An important starting place also used by "flarum-lang" is Weblate (opens new window) which is an online platform used to simplify the translation process.

# Declaring a Language Pack

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

The LanguagePack extender (opens new window) 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 (opens new window):

<?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 (opens new window) 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 (opens new window). This is slightly less efficient though.

Last Updated: 7/15/2021, 12:13:27 PM