Sha256: a8c6d51db08652dfcb97f014ce3ef2015bd9806b14ff75c4f1a13980d3c5d9a1
Contents?: true
Size: 1.1 KB
Versions: 1
Compression:
Stored size: 1.1 KB
Contents
module AwesomeTranslations::ObjectExtensions def t(key, *args, &blk) if key.is_a?(String) && key.start_with?(".") # Removed any helpful appended input to filepath from stacktrace. if match = caller[0].match(/\A(.+):(\d+):/) previous_file = match[1] else raise "Could not get previous file name from: #{caller[0]}" end # Remove any Rails root. removed_root = false AwesomeTranslations::ModelInspector.engines.each do |engine| root = engine.root.to_s if previous_file.starts_with?(root) previous_file = previous_file.gsub(/\A#{Regexp.escape(root)}\//, "") removed_root = true break end end dir = File.dirname(previous_file) file = File.basename(previous_file, File.extname(previous_file)) translation_key = dir translation_key = translation_key.gsub(/\Aapp\//, "") translation_key << "/#{file}" translation_key.gsub!("/", ".") translation_key << key # Change key to full path. key = translation_key end I18n.t(key, *args, &blk) end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
awesome_translations-0.0.5 | lib/awesome_translations/object_extensions.rb |