Localizing DiscourseJeff Atwood March 5, 2013
Discourse was always intended to be a discussion platform supporting every human language. We launched one month ago supporting only English, but since we used the default Ruby on Rails i18n gem, Discourse can be (relatively) easily translated into the language of your choice.
As of last week, you can now change the
default_locale setting in the
/admin settings to determine the default language of your Discourse install.
If you browse the Discourse codebase in the /config/locales folder, you’ll see YAML files for each currently supported language, in client and server flavors. Every language is identified by its standard ISO 639-1 two character code.
Within each file, there are tokens on the left and translations on the right:
fr: js: share: topic: 'partager un lien vers cette discussion' post: 'partager un lien vers ce message' edit: 'Ã©diter le titre et la catÃ©gorie de cette discussion' not_implemented: "Cette fonctionnalitÃ© n'a pas encore Ã©tÃ© implÃ©mentÃ©e, dÃ©solÃ©." no_value: "Non" yes_value: "Oui"
cs: js: share: topic: 'sdÃlet odkaz na toto tÃ©ma' post: 'sdÃlet odkaz na tento pÅ™ÃspÄ›vek' edit: 'upravit nÃ¡zev a kategorii pÅ™ÃspÄ›vku' not_implemented: "Tato fiÄura jeÅ¡tÄ› nenÃ implementovanÃ¡" no_value: "Ne" yes_value: "Ano"
We tried to be meticulous about calling the i18n functions when displaying strings, but we didn’t always succeed.
With the help of a number of contributors, especially kubabrecka and ZogStriP, we’ve been cleaning up the Discourse codebase since launch and ensuring that all string output goes through the proper i18n functions. It’s not difficult – wherever you see a hard-coded string, you change it into a function that references a token instead:
<div class='alert alert-error'>
Something went wrong processing your log in, please try again.<% t 'login.omniauth_error_unknown' %> </div>
Of course, Internationalization and Localization are complex topics, and we haven’t even touched on date and time formats, number formats, differences in pluralization, right-to-left languages, or dozens of other subtleties.. but ensuring that we’ve at least sent all our strings through i18n is a big step in the right direction.
We’d love your help localizing Discourse!
If you have time to contribute, just start a YML file with the appropriate language code and structure in /config/locales, and translate from the master
client.en.yml files as you can. That’s the main bit, but there’s a bit more work required to get client-side translations and date formatting in place as well.
The more people that can use Discourse, in any language, the more conversations we can have, and the more inviting Discourse becomes to contributions from all over the world!