lib/i18n-spec/models/locale_file.rb in i18n-spec-0.0.9 vs lib/i18n-spec/models/locale_file.rb in i18n-spec-0.0.10
- old
+ new
@@ -11,33 +11,42 @@
def content
@content ||= IO.read(@filepath)
end
def translations
- @translations ||= Psych.load_file(@filepath)
+ @translations ||= Psych.load(content)
end
def flattened_translations
@flattened_translations ||= flatten_tree(translations.values.first)
end
+ def pluralizations
+ flatten_tree(translations).select do |key, value|
+ value.is_a?(Hash)
+ end
+ end
+
+ def invalid_pluralization_keys
+ invalid = []
+ pluralizations.each do |parent, pluralization|
+ pluralization.keys.select do |key, value|
+ invalid << [parent, key].join('.') unless PLURALIZATION_KEYS.include?(key)
+ end
+ end
+ invalid
+ end
+
def is_parseable?
begin
Psych.load_file(@filepath)
true
rescue Psych::SyntaxError => e
false
end
end
- def has_valid_pluralization_keys?
- pluralizations.each do |key, pluralization|
- return false unless pluralization.keys.all? {|k| PLURALIZATION_KEYS.include?(k)}
- end
- true
- end
-
def has_one_top_level_namespace?
translations.keys.size == 1
end
def is_named_like_top_level_namespace?
@@ -61,12 +70,7 @@
def pluralization_data?(data)
keys = data.keys.map(&:to_s)
keys.any? {|k| PLURALIZATION_KEYS.include?(k) }
end
- def pluralizations
- flatten_tree(translations).select do |key, value|
- value.is_a?(Hash)
- end
- end
end
end