12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/tolk/sync.rb', line 12
def load_translations
if Tolk.config.exclude_gems_token
I18n.backend.reload! if I18n.backend.initialized?
I18n.backend.instance_variable_set(:@initialized, true)
translations_files = Dir[Rails.root.join('config', 'locales', "*.{rb,yml}")]
if Tolk.config.block_xxx_en_yml_locale_files
locale_block_filter = Proc.new {
|l| ['.', '..'].include?(l) ||
!l.ends_with?('.yml') ||
l.split("/").last.match(/(.*\.){2,}/) }
translations_files = translations_files.reject(&locale_block_filter)
end
if Tolk.config.ignore_locale_files.present?
locale_block_filter = Proc.new do |file_name|
directory_path = Rails.root.join('config', 'locales', 'final_separator').to_s.gsub("final_separator", "")
normalized_file_name = file_name.gsub(directory_path, "").split('.').first
Tolk.config.ignore_locale_files.include?(normalized_file_name)
end
translations_files = translations_files.reject(&locale_block_filter)
end
I18n.backend.load_translations(translations_files)
else
I18n.backend.send :init_translations unless I18n.backend.initialized? end
translations = flat_hash(I18n.backend.send(:translations)[primary_locale.name.to_sym])
filtered = filter_out_i18n_keys(translations.merge(read_primary_locale_file))
filter_out_ignored_keys(filtered)
end
|