Class: MissingTranslation::TranslationFile
- Inherits:
-
Object
- Object
- MissingTranslation::TranslationFile
- Defined in:
- lib/missing_translation/translation_file.rb
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
-
#group ⇒ Object
Returns the value of attribute group.
-
#language ⇒ Object
Returns the value of attribute language.
-
#locale_prefix ⇒ Object
Returns the value of attribute locale_prefix.
-
#pathname ⇒ Object
Returns the value of attribute pathname.
-
#translations ⇒ Object
Returns the value of attribute translations.
Instance Method Summary collapse
-
#initialize(pathname = nil) ⇒ TranslationFile
constructor
A new instance of TranslationFile.
- #to_json ⇒ Object
- #write(directory) ⇒ Object
Constructor Details
#initialize(pathname = nil) ⇒ TranslationFile
9 10 11 12 13 14 15 16 17 |
# File 'lib/missing_translation/translation_file.rb', line 9 def initialize(pathname = nil) return unless pathname @pathname = pathname @file = File.open(pathname) if @file @content = (YAML.load(@file.read) || {}) end end |
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content.
7 8 9 |
# File 'lib/missing_translation/translation_file.rb', line 7 def content @content end |
#group ⇒ Object
Returns the value of attribute group.
7 8 9 |
# File 'lib/missing_translation/translation_file.rb', line 7 def group @group end |
#language ⇒ Object
Returns the value of attribute language.
7 8 9 |
# File 'lib/missing_translation/translation_file.rb', line 7 def language @language end |
#locale_prefix ⇒ Object
Returns the value of attribute locale_prefix.
7 8 9 |
# File 'lib/missing_translation/translation_file.rb', line 7 def locale_prefix @locale_prefix end |
#pathname ⇒ Object
Returns the value of attribute pathname.
7 8 9 |
# File 'lib/missing_translation/translation_file.rb', line 7 def pathname @pathname end |
#translations ⇒ Object
Returns the value of attribute translations.
7 8 9 |
# File 'lib/missing_translation/translation_file.rb', line 7 def translations @translations end |
Instance Method Details
#to_json ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/missing_translation/translation_file.rb', line 19 def to_json return nil unless @content hash_content = @content.to_hash return hash_content[language] if hash_content.has_key?(language) hash_content end |
#write(directory) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/missing_translation/translation_file.rb', line 43 def write(directory) return nil unless translations filename = [group, language, "yml"].compact.reject{|s| s.size <= 0}.join('.') filepath = "#{directory}/#{filename}" p "Writing file #{filepath}..." if locale_prefix && translations.keys.length >= 1 && translations.keys.first != language File.write(filepath, {language => translations}.to_yaml) else File.write(filepath, translations.to_yaml) end MissingTranslation::Util.sort_file(filepath) end |