Class: LocalchI18n::Translations
- Inherits:
-
Object
- Object
- LocalchI18n::Translations
- Defined in:
- lib/localch_i18n/translations.rb
Instance Attribute Summary collapse
-
#config_file ⇒ Object
Returns the value of attribute config_file.
-
#csv_files ⇒ Object
Returns the value of attribute csv_files.
-
#locales ⇒ Object
Returns the value of attribute locales.
-
#tmp_folder ⇒ Object
Returns the value of attribute tmp_folder.
Instance Method Summary collapse
- #clean_up ⇒ Object
- #download(url, destination_file) ⇒ Object
- #download_files ⇒ Object
-
#initialize(config_file = nil, tmp_folder = nil) ⇒ Translations
constructor
A new instance of Translations.
- #load_config ⇒ Object
- #load_locales ⇒ Object
- #store_translations ⇒ Object
Constructor Details
#initialize(config_file = nil, tmp_folder = nil) ⇒ Translations
Returns a new instance of Translations.
12 13 14 15 16 17 18 19 20 |
# File 'lib/localch_i18n/translations.rb', line 12 def initialize(config_file = nil, tmp_folder = nil) @config_file = config_file @tmp_folder = tmp_folder @csv_files = {} load_config load_locales end |
Instance Attribute Details
#config_file ⇒ Object
Returns the value of attribute config_file.
10 11 12 |
# File 'lib/localch_i18n/translations.rb', line 10 def config_file @config_file end |
#csv_files ⇒ Object
Returns the value of attribute csv_files.
10 11 12 |
# File 'lib/localch_i18n/translations.rb', line 10 def csv_files @csv_files end |
#locales ⇒ Object
Returns the value of attribute locales.
10 11 12 |
# File 'lib/localch_i18n/translations.rb', line 10 def locales @locales end |
#tmp_folder ⇒ Object
Returns the value of attribute tmp_folder.
10 11 12 |
# File 'lib/localch_i18n/translations.rb', line 10 def tmp_folder @tmp_folder end |
Instance Method Details
#clean_up ⇒ Object
53 54 55 56 57 58 |
# File 'lib/localch_i18n/translations.rb', line 53 def clean_up # remove all tmp files @csv_files.each do |target_file, csv_file| File.unlink(csv_file) end end |
#download(url, destination_file) ⇒ Object
60 61 62 63 64 65 |
# File 'lib/localch_i18n/translations.rb', line 60 def download(url, destination_file) puts "Download '#{url}' to '#{destination_file}'" File.open(destination_file, 'w') do |dst| dst.write(open(url).read) end end |
#download_files ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/localch_i18n/translations.rb', line 32 def download_files files = @settings['files'] files.each do |target_file, url| # download file to tmp directory tmp_file = File.basename(target_file).gsub('.yml', '.csv') tmp_file = File.join(@tmp_folder, tmp_file) download(url, tmp_file) @csv_files[target_file] = tmp_file end end |
#load_config ⇒ Object
27 28 29 30 |
# File 'lib/localch_i18n/translations.rb', line 27 def load_config @settings = {} @settings = YAML.load_file(config_file) if File.exists?(config_file) end |