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

config/locales could use some cleanup and organization #2125

Open
GBH opened this issue Dec 5, 2017 · 1 comment
Open

config/locales could use some cleanup and organization #2125

GBH opened this issue Dec 5, 2017 · 1 comment

Comments

@GBH
Copy link
Contributor

GBH commented Dec 5, 2017

Managing locale files is a pain. It's not obvious how to structure those files and how to keep them consistent. Right now, locale files are a mess. Inconsistent number of lines, inconsistent structure and too many global translation strings.

I did a big cleanup for rubygems.org a while back as they had similar issue: rubygems/rubygems.org#1522 Honestly, I don't want to do it again as it's just tedious. Maybe somebody wants to tackle this easy, but time consuming task.

So, about structure. Putting everything on the root level is bad. You can't see where that translation string is being used. This is how it can be improved:

en:
  # ActiveRecord translations used for things like forms
  activerecord:
    models:
      shoe: Shoe
    attributes:
      shoe:
        name: Name
        color: Color

  # Controller and View translations
  shoes:
    
    # translations inside the controller. You can use them via `t("shoes.not_found")`
    not_found: Shoe not found!

    # Now for strings used in view templates. You can use shorcut like `t(".title")`
    index:
      title: List of Shoes
      new_link: New Shoe 
    
    new:
      title: New Shoe

    # this is for _form.html.erb partial
    form:
      create: Create a Shoe 

If you get all locale files structured the same, and add a test like this: https://github.com/comfy/comfortable-mexican-sofa/blob/master/test/integration/i18n_test.rb You're golden. It will be very difficult to mess up locales going forward. You'll only need I18n-tasks to detect unused strings, but with care, you don't even need it.

So, if somebody wants to tackle this, feel free to ask questions.

If you never had to deal with translations, this is a must-read: http://guides.rubyonrails.org/i18n.html Specifically this section ("Lazy" Lookup bit)

Cheers.

This will close: #980 #861

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants