Created
October 21, 2009 14:20
-
-
Save diasjorge/215137 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
desc "Transform translations" | |
task :tt => :environment do | |
Translation.transaction do | |
require RAILS_ROOT + "/trans.rb" | |
end | |
end | |
def trans(st, scope_key, options={}) | |
scope_key =~ /(.*)\.(.*)\Z/ | |
scope = $1 | |
key = $2 | |
old_key = | |
if st.is_a?(String) | |
extract_key(st) | |
else | |
st.to_s | |
end | |
old_scope = options[:old_scope] || "auto" | |
translation = Translation.first(:conditions => { :key => old_key, :scope => old_scope }) | |
if translation | |
if Translation.exists?(:key => key, :scope => scope) | |
logger.debug("ALREADY EXISTS #{scope_key}") | |
else | |
translation.update_attributes(:key => key, :scope => scope) | |
end | |
else | |
logger.debug("MISSING TRANSLATION: #{old_key} #{old_scope}") | |
end | |
end | |
def logger | |
@logger ||= Logger.new("translation-trans.log") | |
end | |
def extract_key(st) | |
str = st.dup | |
str.downcase! | |
str.gsub! /\s+/, '_' | |
str.gsub! /[^a-z_]+/, '' | |
str.strip_to_word.intern | |
str | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment