How to add a new language


(Neil Lalonde) #1

Contribute to the Transifex project

The first step is to do some translating in the Transifex project. Create an account at Transifex and join a team for one or more languages.

Add language to Discourse

You have two options when you think that the translation is ready to be included in Discourse:

  1. Post in this topic and ask for your language to be included in Discourse. There might be a helpful community member who will add it for you.

  2. You add it yourself. :muscle:
    If you do, please read on…


You will need a development environment (Linux, macOS or Windows) and a working Transifex client. Moreover, you need to fork and clone the discourse and translations-manager git repositories.

Find the language codes

I’ll use Welsh (cy_GB) as an example to show you the next steps. First, take not of the language code used by Transifex. It will look like this:

:bulb: In some cases, Transifex will use a language code that isn’t supported in Rails.

In order to find out, take a look at config/locales/plurals.rb in the discourse repository. For Welsh you will find a line like this:

cy: { i18n: { plural: { keys: [:one, :two, :many, :other], rule: lambda { |n| n == 1 ? :one : n == 2 ? :two : n == 8 || n == 11 ? :many : :other } } } },

So, the language code in Transifex is cy_GB and cy in Discourse.

Add language to translations-manager

Edit lib/translations_manager/locales.rb in the translations-manager repository and add the language code used by Discourse to the SUPPORTED_LOCALES array.

Add an entry to the LANGUAGE_MAP hash if the language code in Transifex differs from the one used by Discourse.

The diff for Welsh would look like this:

@@ -5,6 +5,7 @@ module TranslationsManager
+    'cy',
@@ -44,6 +45,7 @@ module TranslationsManager
   # 'language code in transifex' => 'language code in Discourse'
+    'cy_GB' => 'cy',
     'el_GR' => 'el',
     'es_ES' => 'es',
     'fr_FR' => 'fr',

Next, commit your changes and create a pull request.

Add language to Discourse

:warning: You need to wait for your pull request to be merged if you added an entry to LANGUAGE_MAP. If you didn’t, you can continue right away.

Run script/pull_translations.rb <language_code> in your discourse directory – <language_code> is the code used by Discourse. It will download all translations from Transifex and do some post-processing afterwards.

Transliteration (optional)

Discourse generates slugs from topic titles. Those are the nice looking topic titles in URLs. For example, this topic’s URL contains: /t/how-to-add-a-new-language/14970

But that only works for ASCII characters. You can add transliteration rules for your character set by creating the following file: /config/locales/transliterate.<language_code>.yml

You can take a look at the various existing files (e.g. if you need some inspiration.

:bulb: The slug generation method can be configured in the site settings. You don’t need to create transliteration rules if the users in your country are accustomed to encoded slugs or prefer to have no slugs.

Right-to-left (optional)

If the new language is a right-to-left script then you also need to add the <language_code> to the rtl? method in app/helpers/application_helper.rb.

Final checks

Now it’s time to make sure that everything is configured correctly.

Plural rules

Discourse has two files with plural rules – for Ruby and JavaScript. Please verify that the rules match the ones defined in the The Unicode Consortium’s Plural Rules.

  • config/locales/plurals.rb
  • lib/javascripts/locale/<language_code>.js

Language name

The file config/locales/names.yml should contain an entry for your language. Please make sure that the language code exists and that the nativeName is correct. For Welsh it looks like this:

  name: Welsh
  nativeName: Cymraeg

Other files

The following files also need to exist:

  • lib/javascripts/moment_locale/<language_code>.js

:bulb: The language code doesn’t have to match exactly. Only the part before the hyphen must match. So, for Welsh it doesn’t make any difference if the file is named cy-gb.js or cy.js – they are considered the same.

Integration tests

Run the following tests suite to check for known integrity issues:
bundle exec rspec spec/integrity/i18n_spec.rb

Live test

Start your Rails server and test that you can change to the new language using the default locale site setting.

Submit your Pull Request

If everything works, commit the files and send us a pull request. :tada:

Discourse in Croatian
Help me to merge old transladed file and new one
Translating Bosnian
Changing default locale after installing Persian translation does not switch forum layout to rtl
Slovak translation - after switching to sk locale Discourse home page is not loaded
Language Translation
Catalan translation
Add persian translate for discourse
Translating Bosnian
Rebuild says "no such locale exists"
Catalan translation
Translation to Azerbaijani (AZ)
Missing translation in Github
Translation to Azerbaijan language
Translation to Azerbaijan language
Discourse-narrative-bot locales
How to translate discourse into Vietnamese
How to add settings to your Discourse theme
Discourse creators can you add lithuanian language to next update?
Adding Bulgarian to dropdown
Adding Bulgarian to dropdown
Discourse creators can you add lithuanian language to next update?
Add a new locale from plugin
So how to integrate new language to discourse?
Change "Confirm your new account" email
Multiple translations for Spanish on Transifex
Discourse 1.9.0.beta17 Release Notes
Discourse 1.9.0.beta16 Release Notes
[PAID] Adding Catalan files to Discourse upstream
Translating Bosnian
(Renis) #3

Can I use a partial translated language?

(Neil Lalonde) #4

You mean a language that doesn’t show as 100% complete in Transifex? Yes you can, but there may be missing translations in some places. It won’t break the site, but it won’t look pretty.

Translating Bosnian
(foobar) #6

Is there a way to copy all translations for a language A into language B, and then work on language B?

I’m working on the Catalan translation, and what would be easiest is to leverage the already-made Spanish translation as a basis (I’m fluent in both langs).

(Gerhard Schlager) #7

This is untested, but you could try to download the Spanish translation files in Transifex and upload them as Catalan translations.

Please add me as a Spanish (Spain) translator
(foobar) #8

Oh yes that does make a lot of sense. I will try. Thanks!

Edit: it did work. The YML file transifex generated was slightly broken (couple newlines missing) and could not be uploaded verbatim, but after fixing it I can work with Spanish as a basis. Thanks!

(Gerhard Schlager) #67

I’ve completly reworked the guide in the first post because a lot has changed over the past couple of years.

Unfortunately adding a new language doesn’t work without a development environment anymore. If you feel that’s too much for you to handle, feel free to ask us to add it for you. But, if you like a challenge, adding a new language could be a great task to get accustomed to Discourse. :wink:

(Peter Borsa) #74

I’ve created a pull request to add Hungarian language. I hope it will be OK. :slight_smile:

(Peter Borsa) #75

Created another pull request to use Hungarian locale.

(Peter Borsa) #76

My PR has merged. Thanks! :metal::tada:

(Cosmin Tătaru) #81

I just started working on completing the Romanian translation over at Transifex. I am unsure about how often the language files in live existing instances of Discourse are being updated. Are they refreshed from Transifex with every launcher app rebuild?
Thank you.

(Gerhard Schlager) #82

Rebuilding the app container won’t update the translations unless they were updated in our GitHub repository. The translations are usually updated with every release of a new beta version.