Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[multiple-use issue!] Move a translation text into a centralized file #3515

Closed
jywarren opened this issue Sep 27, 2018 · 8 comments
Closed
Labels
fto-candidate issues which are meant to be solved by first timers but aren't well-formatted yet gci-candidate Translation System issues which involve adding new translations, improving the translation system

Comments

@jywarren
Copy link
Member

jywarren commented Sep 27, 2018

This has been marked as a good candidate for becoming a first-timers-only issue like these, meaning that it's simple, self-contained, and with some extra formatting, could be a great entry point for a new contributor. If you're familiar enough with this code, please consider reformatting or reposting it as a first-timers-only issue, and then ping @publiclab/reviewers to get it labelled. Or, if this is not your first time, try to solve it yourself!


We're starting a big project to (#3262) revamp and refresh our internationalization systems, and one basic task we'd LOVE help with is to start moving translations around the site into a more centralized location t help make them easier to manage.

It's pretty easy! Try this:

Find a single translation

First, look through files in this set of folders: https://github.com/publiclab/plots2/blob/master/config/locales/

Dig into the subfolders and find an en.yml - full of English text

We want to move all the lines in these files into the main en.yml file at the root of these folders; this file:

https://github.com/publiclab/plots2/blob/master/config/locales/en.yml

So take one translation, like this line:

must_be_logged_in: "You must be logged in to do that."

How do we move it?

Move the single line of text

Cut it from the original file and paste it into the top of the base file just below en: -- so between lines 3 and 4 in this example:

en:
language: English
date:

Keep the indentation the same! 👀

See how it was indented under application_controller:? Copy that line in too, above your first one, but don't delete it from the original file.

en:
application_controller:
must_be_logged_in: "You must be logged in to do that."
must_be_logged_in_to_access: "You must be logged in to access this page"

In this case, you should end up with your root en.yml looking like:

...
en:
  application_controller:
    must_be_logged_in: "You must be logged in to do that."
  language: English
...

Be sure to get all the "nested" lines

Many translations are nested a few levels deep, which means we have to copy each "level". Take this for example:

en:
dashboard:
_activity:
activity: "Activity"
share_work: "Share your work"

In this case, we want to copy those over when we move the translation, so it's still accessible by the string (in this example) t('dashboard._activity.share_work'). See this for an example of how these translations are used in code:

<h3 id="activity-header"><i><%= t('dashboard._activity.activity') %></i></h3>

Don't worry, if you get this step wrong we can help you troubleshoot once you open a pull request! 🙌

See an example

The changes we've done in this guide have been compiled into a pull request so you can see them all together. Read through this for guidance!

https://github.com/publiclab/plots2/pull/3514/files

Good luck, and we're here to help! 👍

Many thanks! ⚡️ ⚡️

@jywarren jywarren added fto-candidate issues which are meant to be solved by first timers but aren't well-formatted yet gci-candidate labels Sep 27, 2018
@jywarren jywarren changed the title [multiple-use issue!] Move a translation into a centralized file and update matching code [multiple-use issue!] Move a translation text into a centralized file Sep 27, 2018
@sunilsj99
Copy link
Contributor

sunilsj99 commented Sep 28, 2018

Can i took this issue @jywarren ??
I want to work on this issue for GCI candidate !!

@jywarren
Copy link
Member Author

jywarren commented Sep 29, 2018 via email

@SidharthBansal
Copy link
Member

This task is published on GCI dashboard. Thanks all.

@PhorelliDev
Copy link

May I have this task please and thanks? I'm here from GCI.

@SidharthBansal
Copy link
Member

Yeah go ahead

@samyuravikumar
Copy link
Contributor

Hi may I have this task? I'm also from GCI

@SidharthBansal
Copy link
Member

SidharthBansal commented Nov 5, 2018 via email

@jywarren jywarren reopened this Jan 7, 2019
@grvsachdeva grvsachdeva added Translation System issues which involve adding new translations, improving the translation system and removed Translation System issues which involve adding new translations, improving the translation system labels Jan 9, 2019
@grvsachdeva
Copy link
Member

Closing this as we have achieved this a little back and the centralized file is at https://github.com/publiclab/plots2/blob/master/config/locales/en.yml

Thanks all!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fto-candidate issues which are meant to be solved by first timers but aren't well-formatted yet gci-candidate Translation System issues which involve adding new translations, improving the translation system
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants