Skip to content

Translating CircuitVerse Into Different Languages

Pavan Joshi edited this page Aug 22, 2021 · 4 revisions

Abstract

CircuitVerse Main platform is written in Ruby on Rails and requires the use of Rails i18n for internationalization. For more have a look at I18n technical Documentation.

For localization Rules to be used in the Rails platform, kindly visit I18n Localization Rules

Adding translations

Adding support for a new language is easy and can be done following below steps -

  1. Locate the translation directory of a module to be translated.
  2. Create a .yml translation file for a new language.
  3. copy and edit existing YAML templates for a new language.

Below is the detailed guide for the same.

Locate Translation Directory

For locating the translation directory and corresponding YAML template for the particular module, We advise contributors to know a little more about the design of the directory structure before adding support for the new language. Here

We follow the exact top-level directory structure for translations in the config/locale/ folder as followed by codebase.

Eg. app/views/logix/<ruby_template_files> will have translations stored at config/locale/views/logxi/<yml_files>

Locate Translation Directory of Particular Page from Front-end

In a very simple manner, you can copy a particular string present on the page and use the Search tab of your editor to reach the corresponding YAML file belonging to that page.

Or else you can locate the ERB template for the particular page in the app/views/ directory and you see the exact structure in the config/locale/ directory to reach the corresponding translation file.

Translate CircuitVerse Modules

We already possess I18n infrastructure for the languages like English and Hindi. Following the same infrastructure I18n for a new language shall be introduced.

After locating the translation directory following steps can be followed to begin with translations -

  • Find the locale of the language for which you are providing support. Here

  • If language is not in the list of supported locale

    • add locale value in the list of supported locales

      In config/application.rb

       config.i18n.available_locales = [:en, :hi]
      
  • Create template file in respective directory as locale.yml (eg. zh.yml). A restart of the server is required every time a new YAML template is created

  • Copy content of en.yml into the newly created template file.

  • Replace top-level namespace en: to the desired language locale (zh:) and replace English translation strings with the desired one.

A similar guide can be followed for other modules such as controllers, models, forms etc

Testing

After adding YAML files and feeding translations for a new language, A restart of the locale Rails Server is recommended.

We can switch language using locale field present in User's Dashboard --> Edit Details to see results in the desired language

Special Cases occurred while Feeding Translations

  • Part of a string contains Instance Variables

    Some of the strings can have instance variables included in them. Here we use Rails I18n interpolation.

     YAML
    
     hello %{user_name} 
    

    Any string inside %{} (here user_name) are interpolated variables and need not be translated but should be taken with the string as some language that flows from right to left can alter the position of instance variables.

  • Similarly, if part of a string contains links and HTML tags, they should be taken with the string as it is and care shall be taken when localizing them as in any different language their position may alter.

  • Forms attributes shall be localized according to the rules mentioned here. Form templates can also contain strings that are not the form attributes such strings shall be included in respective YAML files present views directory and in relevant namespace.

  • Links generated using _path or _url Rails helpers should be localized using interpolation techniques so that links don't get separated from the string

    Before

     You don't have any projects. Create one <%= link_to 'here', simulator_new_url, class: 'anchor-text' %>
    

    After

      <%= t("core_key_name", simulator_new_url: link_to(t("link_key_name"), simulator_new_url, class: 'anchor-text') )%>
    
Clone this wiki locally