1 require File.dirname(__FILE__) + '/../test_helper'
3 class I18nTest < ActiveSupport::TestCase
4 I18n.available_locales.each do |locale|
5 define_method("test_#{locale.to_s.underscore}".to_sym) do
6 plural_keys = plural_keys(locale)
8 translation_keys.each do |key|
11 default_value = I18n.t(key, :locale => I18n.default_locale)
13 if default_value.is_a?(Hash)
14 variables.push("count")
16 default_value.each do |subkey,subvalue|
17 subvalue.scan(/%\{(\w+)\}/) do
22 default_value.scan(/%\{(\w+)\}/) do
27 if key =~ /^(active(model|record)\.)?errors\./
28 variables.push("attribute")
31 value = I18n.t(key, :locale => locale, :fallback => true)
34 value.each do |subkey,subvalue|
35 # assert plural_keys.include?(subkey), "#{key}.#{subkey} is not a valid plural key"
38 subvalue.scan(/%\{(\w+)\}/) do
39 assert variables.include?($1), "#{key}.#{subkey} uses unknown interpolation variable #{$1}"
44 assert value.is_a?(String), "#{key} is not a string"
46 value.scan(/%\{(\w+)\}/) do
47 assert variables.include?($1), "#{key} uses unknown interpolation variable #{$1}"
54 def translation_keys(scope = nil)
55 plural_keys = plural_keys(I18n.default_locale)
57 I18n.t(scope || ".", :locale => I18n.default_locale).map do |key,value|
58 scoped_key = scope ? "#{scope}.#{key}" : key
60 if value.kind_of?(Hash)
61 if value.keys - plural_keys == []
64 translation_keys(scoped_key)
66 elsif value.kind_of?(String)
72 def plural_keys(locale)
73 I18n.t("i18n.plural.keys", :locale => locale, :raise => true) + [ :zero ]
74 rescue I18n::MissingTranslationData
75 [ :zero, :one, :other ]