Class: WcaI18n::Translation
- Inherits:
-
Object
- Object
- WcaI18n::Translation
- Defined in:
- lib/wca_i18n/translation.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#locale ⇒ Object
Returns the value of attribute locale.
Class Method Summary collapse
Instance Method Summary collapse
- #compare_to(base) ⇒ Object
-
#initialize(locale, file_content) ⇒ Translation
constructor
A new instance of Translation.
Constructor Details
#initialize(locale, file_content) ⇒ Translation
Returns a new instance of Translation.
10 11 12 13 |
# File 'lib/wca_i18n/translation.rb', line 10 def initialize(locale, file_content) self.locale = locale.to_s self.data = YAMLToEnrichedRubyHash.parse(file_content) end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
8 9 10 |
# File 'lib/wca_i18n/translation.rb', line 8 def data @data end |
#locale ⇒ Object
Returns the value of attribute locale.
8 9 10 |
# File 'lib/wca_i18n/translation.rb', line 8 def locale @locale end |
Class Method Details
.hash_translation(value) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/wca_i18n/translation.rb', line 19 def self.hash_translation(value) # If the key is a pluralization, we use all the subkeys to compute the hash # Please see this wiki page explaining why we do this: https://github.com/thewca/worldcubeassociation.org/wikigTranslating-the-website#translations-status-internals to_digest = pluralization?(value) ? JSON.generate(value) : value original_str = Digest::SHA1.hexdigest(to_digest)[0..6] end |
.pluralization?(node) ⇒ Boolean
80 81 82 |
# File 'lib/wca_i18n/translation.rb', line 80 def self.pluralization?(node) node.is_a?(Hash) && (node.keys & PLURALIZATION_KEYS).any? end |
Instance Method Details
#compare_to(base) ⇒ Object
15 16 17 |
# File 'lib/wca_i18n/translation.rb', line 15 def compare_to(base) return diff_recursive(base.data[base.locale], self.data[self.locale], []) end |