plots2
plots2 copied to clipboard
Adding new strings for Translation
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
- Find a string that is hard-coded in the views files but is not there in the YAML file.
- 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
- I will add it to the YAML file as:
Note:
- Check if a string already exists in the YAML file before adding it.
- 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 - 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
- Find an occurrence of a string that is already stored in the YAML file but is directly added as a string in the view.
- 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
- Find a string that is hard-coded in the views files but is not there in the YAML file.
- Create an FTO to add the string to the YAML file and then call the translation function in the original string location.
- 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
I can create a fto for this
@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!
surely
if this issue is open can I please work @TildaDares can u please assign me
Hey @TildaDares please can i work on this?
can i create a FTO on this?
Hi @codeamic, @Hydriah, yes you can create issues from this.
@TildaDares ok thanks
@TildaDares Can I create FTO on this?