plots2 icon indicating copy to clipboard operation
plots2 copied to clipboard

Adding new strings for Translation

Open imajit opened this issue 3 years ago • 9 comments

Goal of this issue is to create FTOs for Public Lab Translation Project

Part of #9686 There are many strings that are kind of hard-coded in many views files . For example https://github.com/publiclab/plots2/blob/b73594fb7d2b1a78f9f0afb074c55ac92bfd8e43/app/views/layouts/_header.html.erb#L12 here you can see Public Lab is added as a string. Ideally, we would like to have a string constant in en.yml saved as publiclab = "Public Lab" and then refer to this in all the occurrences of the string "Public Lab". There are 2 benefits of this

  • If we want to change "Public Lab" to "PUBLIC LAB" we need not find all occurrences and change it we only need to change the constant in the YAML file.
  • By adding it to the YAML file, we are also adding it to our Translation Project on Transifex. Language translators can then add translations for newly added strings and we can make Publiclab.org more genial and accessible to new and existing users and foster diversity. We have many strings that need to be added to the Transifex project for translation. We can do this by adding new FTOs.

Here I have tried to break all possible FTOs into 3 types

1. Adding a new string to Translation Project

For this type of FTOs, we need to add the missing string to the YAML file and then call the translation function where the sting was present.

Steps to create an FTO of this type

  1. Find a string that is hard-coded in the views files but is not there in the YAML file.
  2. Create an FTO to add the string to the YAML file and then call the translation function in the original string location. Let's say I want to add "Public Lab" string to the YAML file.
    • I will add it to the YAML file as:
      • publiclab: "Public Lab"
    • Now I will refer to this back in the original file using the translation function as:
      • translation('home.publiclab')
    • Done, you can check the view once to make sure the string is placed properly. Here is a sample FTO of this type #9950

Note:

  1. Check if a string already exists in the YAML file before adding it.
  2. Add the new string under suitable string sets. Universal strings can be added as a separate strings. If a string is part of a view, model, or controller whose string set already exists in the YAML file then it is preferred to add it under the existing string set. For example, if I want to add a new string hello which is in a view related to the tags controller, then I can add it under tag controller string set. https://github.com/publiclab/plots2/blob/b73594fb7d2b1a78f9f0afb074c55ac92bfd8e43/config/locales/en.yml#L1030
  3. To call a string using the translation function, you need to call it in a hierarchical fashion, say you want to call https://github.com/publiclab/plots2/blob/b73594fb7d2b1a78f9f0afb074c55ac92bfd8e43/config/locales/en.yml#L893 the string you can call it using translation('talk.show.welcome')

2. Replacing a string with a translation function

Let's say the string "Public Lab" is stored as a string in the YAML file, but there are multiple occurrences where the string is added directly as part of the view, we can change this by calling the translation function in place of the string.

Steps to create an FTO of this type

  1. Find an occurrence of a string that is already stored in the YAML file but is directly added as a string in the view.
  2. Create an FTO to replace this string with the translation function call. Here is a sample FTO of this type #9944

3. Adding strings that are part of HTML attributes

This type of FTOs can be a bit tricky and UI checks are preferred before merging PRs. Consider this line of code https://github.com/publiclab/plots2/blob/b73594fb7d2b1a78f9f0afb074c55ac92bfd8e43/app/views/layouts/_header.html.erb#L20 The translation function is called inside an HTML tag here for an HTML attribute placeholder, the difference here is that the additional parameter false is also passed here.

Steps to create an FTO of this type

  1. Find a string that is hard-coded in the views files but is not there in the YAML file.
  2. Create an FTO to add the string to the YAML file and then call the translation function in the original string location.
  3. In the PR, run the changes in Gitpod and verify there are no UI breaks in the view where the changes are made. Reviewers can check this by themselves or request contributors to do so. The second option is preferred as it makes reviewing process quick and easy and also introduces Gitpod to new contributors who might find it very useful in later complex issues. Here is a sample FTO of this type #9934

Feel free to reach out if you have any doubts regarding the creation or reviewing of FTOs

imajit avatar Jul 24 '21 21:07 imajit

I can create a fto for this

unnati914 avatar Aug 10 '21 12:08 unnati914

@unnati914 that would be super! Perhaps check with @imajit once you've created it to give it a quick look over, then we can label it? Thank you!

jywarren avatar Aug 10 '21 19:08 jywarren

surely

unnati914 avatar Aug 11 '21 02:08 unnati914

if this issue is open can I please work @TildaDares can u please assign me

subhangi2731 avatar Oct 15 '21 17:10 subhangi2731

Hey @TildaDares please can i work on this?

codeamic avatar Mar 27 '22 12:03 codeamic

can i create a FTO on this?

Hydriah avatar Mar 27 '22 16:03 Hydriah

Hi @codeamic, @Hydriah, yes you can create issues from this.

TildaDares avatar Mar 27 '22 16:03 TildaDares

@TildaDares ok thanks

Hydriah avatar Mar 27 '22 16:03 Hydriah

@TildaDares Can I create FTO on this?

Pragati1419 avatar Apr 17 '22 08:04 Pragati1419