diff --git a/app/assets/stylesheets/copycat_engine.css b/app/assets/stylesheets/copycat_engine.css index 55a1849..e5772b2 100644 --- a/app/assets/stylesheets/copycat_engine.css +++ b/app/assets/stylesheets/copycat_engine.css @@ -400,6 +400,19 @@ div.edit h2 { text-overflow: ellipsis; } +div.edit .variables table { +width: auto; +} + + +div.edit .variables table th { + font-weight: bold; +} +div.edit .variables table td, +div.edit .variables table th { +padding: 1em; +border: 1px dotted; +} div.edit textarea { width: 99%; margin-top: 1em; @@ -461,3 +474,6 @@ body { margin-bottom: .5em; } +.variables { + clear: both; +} diff --git a/app/models/copycat_translation.rb b/app/models/copycat_translation.rb index 3c34b1e..78738f9 100644 --- a/app/models/copycat_translation.rb +++ b/app/models/copycat_translation.rb @@ -6,17 +6,24 @@ class CopycatTranslation < ActiveRecord::Base validates :key, :presence => true validates :locale, :presence => true - - attr_accessible :locale, :key, :value + + attr_accessible :locale, :key, :value, :options + serialize :options, Hash + RESERVED_KEYS = [:scope, :default, :separator, :resolve, :rescue_format] + + def user_parameters + # RESERVED_KEYS from i18n gem + self.options.dup.delete_if {|k| RESERVED_KEYS.include? k} + end module Serialize - + def import_yaml(yaml) hash = YAML.load(yaml) hash.each do |locale, data| hash_flatten(data).each do |key, value| c = where(key: key, locale: locale).first - c ||= new(key: key, locale: locale) + c ||= new(key: key, locale: locale) c.value = value c.save end @@ -31,14 +38,14 @@ def export_yaml end hash.to_yaml end - + # {"foo"=>{"a"=>"1", "b"=>"2"}} ----> {"foo.a"=>1, "foo.b"=>2} def hash_flatten(hash) - result = {} + result = {} hash.each do |key, value| - if value.is_a? Hash + if value.is_a? Hash hash_flatten(value).each { |k,v| result["#{key}.#{k}"] = v } - else + else result[key] = value end end diff --git a/app/views/copycat_translations/edit.html.erb b/app/views/copycat_translations/edit.html.erb index fc4ddd4..1aa583f 100644 --- a/app/views/copycat_translations/edit.html.erb +++ b/app/views/copycat_translations/edit.html.erb @@ -1,6 +1,30 @@
You could use the following variables in your inserted text, just using %{variable} and you will obtain its value
+| Variable | +Value | +Usage | +
|---|---|---|
| <%= key %> | +<%= value %> | +<%= "%{#{key}}" %> | +