class Rosetta::Repositories::Local
Public Instance Methods
build_link(keys, **_args)
click to toggle source
# File lib/rosetta/repositories/local.rb, line 13 def build_link(keys, **_args) path = I18n.load_path.flatten.find { |filename| file_has_phrase?(filename, keys) } path && Pathname.new(path).relative_path_from(Rails.root) end
id()
click to toggle source
# File lib/rosetta/repositories/local.rb, line 5 def id 'local' end
label()
click to toggle source
# File lib/rosetta/repositories/local.rb, line 9 def label 'Repository Local' end
Private Instance Methods
file_has_phrase?(filename, keys)
click to toggle source
# File lib/rosetta/repositories/local.rb, line 20 def file_has_phrase?(filename, keys) type = File.extname(filename).tr('.', '').downcase return unless type == 'yml' unless file_translations(filename).is_a?(Hash) fail I18n::InvalidLocaleData.new(filename, 'expects it to return a hash, but does not') end file_translations(filename).dig(I18n.config.locale.to_s, *keys.map(&:to_s)) end
file_translations(filename)
click to toggle source
rubocop:disable Style/Send
# File lib/rosetta/repositories/local.rb, line 33 def file_translations(filename) translations[filename] ||= I18n.backend.send(:load_yml, filename) end
translations()
click to toggle source
rubocop:enable Style/Send
# File lib/rosetta/repositories/local.rb, line 38 def translations @translations ||= {} end