Skip to content
A small tool for Ruby on Rails locales - As gem
Ruby
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
example_files
lib
test
.gitignore
LICENSE
README.md
Rakefile
autolocale.gemspec

README.md

AutoLocale

A useful gem for Ruby-on-Rails apps that use multiple languages.

It can compare YAML 'locale' files with each other and lets you...

  • find missing translation-keys
  • find mismatching value types (e.g. String vs Array)
  • automatically add missing keys (merge)
  • existing, but not translated keys

You can also find AutoLocale at rubygems.org.

Usage

Before using any of these, make sure to require 'autolocale'.

find problems

# run in irb
AutoLocale.compare "path/to/complete_locale.yml", "path/to/incomplete_locale.yml"

compare will just list missing or mismatching keys (with their path), but not affect the actual files.

add missing keys

AutoLocale.automerge "path/to/complete_locale.yml", "path/to/incomplete_locale.yml"

automerge will automatically add not existing keys (and their values) to the other file. This will not touch value type mismatches.

find not translated keys

AutoLocale.untranslated "path/to/complete_locale.yml", "path/to/incomplete_locale.yml"

Use untranslated to find untranslated (but existing) keys.
In fact, this will find each key's value and compare it with it's respective opposite. That means it will show up in the results whenever the values are the same (as they are after using the merge function).
Chances are you're finding keys that just share the same words in two languages.

Examples

AutoLocale.compare "example_files/en_complete.yml", "example_files/en_incomplete.yml"

Preview

AutoLocale.automerge "example_files/en_complete.yml", "example_files/en_incomplete.yml"

Preview
As mentioned above, it will not touch type mismatches - but it shows them to you so it can be fixed by hand.

AutoLocale.untranslated "example_files/en_complete.yml", "example_files/en_incomplete.yml"

Preview

Use more than just two files

Put this code into a file and run it with ruby filename (from your locales path):

Dir.glob('*.yml').permutation(2).to_a.each{|f|print "#{f[0]} <=> #{f[1]}: ";AutoLocale.compare(f[0].to_s, f[1].to_s)}

It will compare every file with every other file in the directory.
Change compare() to anything listed above, if you want to.

TODO

Not sure when I have the time to do this.

  1. Allow to use path/to/file instead of "path/to/file"
  2. Add built-in support to iterate over every file in folder
  3. Create shorter methodnames / aliases
  4. Make executable, so it's not needed to run with irb
Something went wrong with that request. Please try again.