Class: TranslationEngine::Downloader
- Inherits:
-
Object
- Object
- TranslationEngine::Downloader
- Defined in:
- app/models/translation_engine/downloader.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.cache_timeout ⇒ Object
13 14 15 |
# File 'app/models/translation_engine/downloader.rb', line 13 def self.cache_timeout @cache_timeout end |
.etag?(etag) ⇒ Boolean
5 6 7 8 9 10 11 |
# File 'app/models/translation_engine/downloader.rb', line 5 def self.etag?(etag) response = @current_etag == etag Rails.logger.info { "Translations are up to date" } if response @current_etag = etag @cache_timeout = Time.now + TranslationEngine.cache_timeout response end |
Instance Method Details
#store ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'app/models/translation_engine/downloader.rb', line 23 def store if (yml_data = receive_translations) Rails.logger.info { "Storing translations to #{locale_file}" } write(locale_file, yml_data) add_translation_file_to_i18n I18n.backend.reload! end end |
#store_release(release) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'app/models/translation_engine/downloader.rb', line 32 def store_release(release) locale = release.split('_')[0...-1].join('_') filename = releases_dir.join("#{locale.downcase}.yml") if (yml_data = connection.get_release(release).try(:body)) Rails.logger.info { "Storing release #{release} to #{filename}" } write(filename, yml_data) end end |
#update ⇒ Object
17 18 19 20 21 |
# File 'app/models/translation_engine/downloader.rb', line 17 def update return nil if self.class.cache_timeout && Time.now < self.class.cache_timeout return nil if self.class.etag?(connection.get_translations_head[:etag]) I18n.backend.reload! end |