Module: I18nData::FileDataProvider

Extended by:
FileDataProvider
Included in:
FileDataProvider
Defined in:
lib/i18n_data/file_data_provider.rb

Constant Summary collapse

DATA_SEPARATOR =
";;"

Instance Method Summary collapse

Instance Method Details

#codes(type, language_code) ⇒ Object



9
10
11
12
13
14
# File 'lib/i18n_data/file_data_provider.rb', line 9

def codes(type, language_code)
  unless (data = read_from_file(cache_file_for(type, language_code)))
    raise NoTranslationAvailable, "#{type}-#{language_code}"
  end
  data
end

#write_cache(provider) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/i18n_data/file_data_provider.rb', line 16

def write_cache(provider)
  languages = provider.codes(
    :languages,
    'EN'
  ).keys + ['zh_CN', 'zh_TW', 'zh_HK', 'bn_IN', 'pt_BR', 'sr@latin', 'nb_NO']
  languages.map do |language_code|
    [:languages, :countries].each do |type|
      data = provider.send(:codes, type, language_code)
      write_to_file(data, cache_file_for(type, language_code))
    rescue NoTranslationAvailable
      warn "No translation available for #{type} #{language_code}" if $DEBUG
    rescue AccessDenied
      warn "Access denied for #{type} #{language_code}"
    end
  end
end