aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--config/environment.rb2
-rw-r--r--lib/i18n_fixes.rb37
2 files changed, 38 insertions, 1 deletions
diff --git a/config/environment.rb b/config/environment.rb
index af214aded..3f649982a 100644
--- a/config/environment.rb
+++ b/config/environment.rb
@@ -119,5 +119,5 @@ require 'activerecord_errors_extensions.rb'
require 'willpaginate_hack.rb'
require 'sendmail_return_path.rb'
require 'tnef.rb'
-
+require 'i18n_fixes.rb'
diff --git a/lib/i18n_fixes.rb b/lib/i18n_fixes.rb
new file mode 100644
index 000000000..9d7a999dd
--- /dev/null
+++ b/lib/i18n_fixes.rb
@@ -0,0 +1,37 @@
+# override behaviour in fast_gettext/translation.rb
+# so that we can interpolate our translation strings nicely
+
+def _(key, options = {})
+ translation = FastGettext._(key) || key
+ gettext_interpolate(translation, options)
+end
+
+INTERPOLATION_RESERVED_KEYS = %w(scope default)
+MATCH = /(\\\\)?\{\{([^\}]+)\}\}/
+
+def gettext_interpolate(string, values)
+ return string unless string.is_a?(String)
+ if values.is_a?(Hash)
+ string.gsub(MATCH) do
+ escaped, pattern, key = $1, $2, $2.to_sym
+
+ if escaped
+ pattern
+ elsif INTERPOLATION_RESERVED_KEYS.include?(pattern)
+ raise ReservedInterpolationKey.new(pattern, string)
+ elsif !values.include?(key)
+ raise MissingInterpolationArgument.new(pattern, string)
+ else
+ values[key].to_s
+ end
+ end
+ else
+ reserved_keys = if defined?(I18n::RESERVED_KEYS) # rails 3+
+ I18n::RESERVED_KEYS
+ else
+ I18n::Backend::Base::RESERVED_KEYS
+ end
+
+ string % values.except(*reserved_keys)
+ end
+end