I18n補間を変更することでこの問題を解決しました。あなたの初期化子ディレクトリに以下のコードを入れてください:
create: 'Opprett %{model.downcase}'
し、それをテストします:
今
module I18n
# Implemented to support method call on translation keys
INTERPOLATION_WITH_METHOD_PATTERN = Regexp.union(
/%%/,
/%\{(\w+)\}/, # matches placeholders like "%{foo}"
/%<(\w+)>(.*?\d*\.?\d*[bBdiouxXeEfgGcps])/, # matches placeholders like "%<foo>.d"
/%\{(\w+)\.(\w+)\}/, # matches placeholders like "%{foo.upcase}"
)
class << self
def interpolate_hash(string, values)
string.gsub(INTERPOLATION_WITH_METHOD_PATTERN) do |match|
if match == '%%'
'%'
else
key = ($1 || $2 || $4).to_sym
value = values.key?(key) ? values[key] : raise(MissingInterpolationArgument.new(values, string))
value = value.call(values) if value.respond_to?(:call)
$3 ? sprintf("%#{$3}", value) : ($5 ? value.send($5) : value)
end
end
end
end
end
、これはあなたのロケールファイルに何ができるかである
require 'test_helper'
class I18nTest < ActiveSupport::TestCase
should 'interpolate as usual' do
assert_equal 'Show Customer', I18n.interpolate("Show %{model}", model: 'Customer')
end
should 'interpolate with number formatting' do
assert_equal 'Show many 100', I18n.interpolate("Show many %<kr>2d", kr: 100)
assert_equal 'Show many abc', I18n.interpolate("Show many %<str>3.3s", str: 'abcde')
end
should 'support method execution' do
assert_equal 'Show customer', I18n.interpolate("Show %{model.downcase}", model: 'Customer')
end
end