lib/i18n-spec/models/locale_file.rb in i18n-spec-0.2.4 vs lib/i18n-spec/models/locale_file.rb in i18n-spec-0.3.0
- old
+ new
@@ -20,10 +20,18 @@
def flattened_translations
@flattened_translations ||= flatten_tree(translations.values.first)
end
+ def locale
+ @locale ||= ISO::Tag.new(locale_code)
+ end
+
+ def locale_code
+ translations.keys.first
+ end
+
def pluralizations
result = flatten_tree(translations).select do |key, value|
value.is_a?(Hash)
end
@@ -43,10 +51,21 @@
end
@errors[:invalid_pluralization_keys] = invalid unless invalid.empty?
invalid
end
+ def missing_pluralization_keys
+ return_data = {}
+ rule_names = locale.language.plural_rule_names
+ pluralizations.each do |parent, pluralization|
+ missing_keys = rule_names - pluralization.keys
+ return_data[parent] = missing_keys if missing_keys.any?
+ end
+ @errors[:missing_pluralization_keys] = return_data if return_data.any?
+ return_data
+ end
+
def is_parseable?
begin
yaml_load_content
true
rescue YAML::ParseError => e
@@ -61,14 +80,10 @@
def has_one_top_level_namespace?
translations.keys.size == 1
end
def is_named_like_top_level_namespace?
- translations.keys.first == File.basename(@filepath, File.extname(@filepath))
- end
-
- def has_a_valid_locale?
- ISO::Tag.new(translations.keys.first).valid?
+ locale_code == File.basename(@filepath, File.extname(@filepath))
end
protected
def flatten_tree(data, prefix = '', result = {})