Module: Tolk::Import::ClassMethods
- Defined in:
- lib/tolk/import.rb
Instance Method Summary collapse
Instance Method Details
#import_locale(locale_name) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/tolk/import.rb', line 22 def import_locale(locale_name) locale = Tolk::Locale.find_or_create_by_name(locale_name) data = locale.read_locale_file phrases = Tolk::Phrase.all count = 0 data.each do |key, value| phrase = phrases.detect {|p| p.key == key} if phrase translation = locale.translations.new(:text => value, :phrase => phrase) count = count + 1 if translation.save else puts "[ERROR] Key '#{key}' was found in #{locale_name}.yml but #{Tolk::Locale.primary_language_name} translation is missing" end end puts "[INFO] Imported #{count} keys from #{locale_name}.yml" end |
#import_secondary_locales ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/tolk/import.rb', line 9 def import_secondary_locales locales = Dir.entries(self.locales_config_path) locale_block_filter = Proc.new { |l| ['.', '..'].include?(l) || !l.ends_with?('.yml') || l.match(/(.*\.){2,}/) # reject files of type xxx.en.yml } locales = locales.reject(&locale_block_filter).map {|x| x.split('.').first } locales = locales - [Tolk::Locale.primary_locale.name] locales.each {|l| import_locale(l) } end |