๐Ÿšฉ Translations for open-event-frontend

Shubham UpretiShubham Upreti
2 min read

๐Ÿง‘โ€๐Ÿซ Why is translation needed?

The frontend-repo and server-repo powers FOSSASIA's eventyay, which is an event management system.

A major portion of our customers resides in non-English speaking countries. So, it's important for us as part of UX that users are able to understand what's on the site.


๐Ÿ‘€ ember-1l0n

We use ember-l10n to extract the strings we need to translate from *.js/*.hbs/*.ts files. You can mark strings for translation like this:

Usage in templates (*.hbs files)

  {{t 'This is the English string.'}}

Usage in *.js files

 export default Component.extend({
  l10n: service(),

  text: computed(function() {
    this.l10n.t('Translate this');
  })
});

You can read more about usage in this package's repo.


๐Ÿงฐ Basic rules of translation

Some of the points below are taken from this article.

  • Follow a decent English style

    Make sure every sentence is grammatically and punctuation wise correct.

  • Make entire sentences translatable

    Do this

    {{t 'After {{time}} minutes, the reservation we\'re holding will be released to others.' time=this.settings.orderExpiryTime}}
    

    Not this

    {{t 'After' }} {{this.settings.orderExpiryTime}} {{t 'minutes, the reservation we\'re holding will be released to others.' }}
    
  • Give useful, contextual names to variables between the sentences

    If the sentence has variables in it, give useful names to the variable placeholder which explain the context of the variable to the translator.

    Like:

    {{t 'Please complete registration within {{time}} minutes.' time=this.settings.orderExpiryTime}}
    

    The placeholder time here explains that the value that will be here, represents time. So, the translator can guess the context here, which makes it easy for them to translate.


โ“ How to extract strings from files??

The strings present in *.js/*.ts/*.hbs has to be extracted in a **message.pot** file, which is then used to generate **.po** files. These .po files should be uploaded to a service like weblate. The strings gets translated to different languages by translators on the site.

  • How to generate the messages.pot file?

    Just type this command on your command line in the root of the project

    yarn l10n:extract
    
  • Next step: Update the different translation files with new strings

    yarn l10n:update
    

โœ”๏ธ And, you are done with translations, just commit and push your changes.


2
Subscribe to my newsletter

Read articles from Shubham Upreti directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Shubham Upreti
Shubham Upreti

Open Source Contributor @FOSSASIA