Created
June 6, 2010 18:01
-
-
Save steffen/427750 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# ABOUT: | |
# Migrates your Simple Localization (http://simple-localization.arkanis.de/) language file to | |
# Rails built-in i18n language file structure. | |
# IMPORTANT: | |
# If you want your active records model and attributes keys | |
# and your "app" keys to be sorted alphabetically, use Ruby 1.9 | |
# since it supports sorted hashes | |
# This script was tested with Ruby 1.8.7 and Ruby 1.9.1 | |
# USAGE: | |
# $ ruby sl_to_i18n path/to/simple_localization/yaml/lang/file.yml | |
# Copy console output into your new i18n language file | |
require "yaml" | |
# require "rubygems" | |
# require "ruby-debug" # Doesn't work with 1.9.1 | |
@sl = YAML.load(File.read(ARGV[0])) | |
@i18n = { | |
"de" => { | |
"activerecord" => { | |
"models" => {}, | |
"attributes" => {} | |
} | |
} | |
} | |
@sorted_models = @sl["models"].sort # returns array | |
@sorted_models.each do |model| | |
@i18n["de"]["activerecord"]["models"][model[0]] = model[1]["name"] | |
end | |
@sorted_models.each do |model| | |
@i18n["de"]["activerecord"]["attributes"][model[0]] = model[1]["attributes"] | |
end | |
@sorted_app = @sl["app"].sort | |
@sorted_app.each do |values| | |
@i18n["de"][values[0]] = values[1] | |
end | |
puts YAML.dump(@i18n) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment