- we support nested directory structure, all the yml files belonging to views should be stored in
config/locales/views
folder - Further nesting should be done following similar codebase structure.
- case1:
If there is single file in module we dont include erb name for file. here we use view_folder_name: i.e about:
as a top level namespace
For views/about/index.html.erb
for single template based modules we use only folder name as a namespace.
Right
en:
about:
all_keys present for about page
Wrong
about:
index:
all_keys present for about page
- Case 2:
If file with multiple ERB templates present (having lot of static strings). here we use View_folder_name + ERB template name as a top level name space
en:
logix:
teachers:
all keys present for teachers page
contribute:
all keys present for contribute page
- Case3:
Module with multiple erb files and most of the templates are route based like update, edit,delete (such modules usually posses less number of strings)
Best example of such case is Announcement module
For views/announcements/_announcement.html.erb
we dont introduce a separate namespace for partial. keys present in them shall be named under announcements: namespace
Right
en:
announcements:
keys for partials
Wrong
en:
announcement_partial:
keys for partial
- Keys which are being used throughout the app should be present in
general
namespace
create directory structure as config/locales/general
en:
general:
edit: "EDIT"
delete: "DELETE"
- Rails provides helpers for more automated translations for forms
for views/annnouncements/_form.html.erb
create directory structure config/locales/forms/announcements/en.yml
en:
helpers:
label:
all labels translations
submit:
translations for submit button
we dont have to use any t() function in forms rails will automatically look up for translations when translations will be put in proper namespaces.
- headings shall end with
_heading
suffix - main paragraphs shall be named as
main_description
and submain para with ```submain_description - eg of I18n in cards
teacher_card:
heading: "I am a Teacher"
item1_text: "Introduce the platform to your students"
item2_text: "Promote the platform within your circles"
item3_text: "Create exciting educational content using CircuitVerse"
- If string posses instance variables in it they shall be translated via string interpolation
t("hii_there",name: @name.name)
en:
hii_there: "hii there %{name}"
- strings containing anchor tags or any html based things can be localized via adding
_html
suffix to key name Rails will automatically escape html and html based part will be interprated as html and not static string
t("hii_there_html")
en:
hii_there_html: "some string with html"