class FractualI18n::Phrases
Public Instance Methods
joined(locale:)
click to toggle source
# File lib/fractual_i18n/phrases.rb, line 2 def joined(locale:) original_load_path = I18n.load_path I18n.load_path = fractual_files I18n.with_locale(locale) { I18n.t(".") } ensure I18n.load_path = original_load_path end
store(translations, locale:)
click to toggle source
# File lib/fractual_i18n/phrases.rb, line 11 def store(translations, locale:) fractual_files.each do |filename| content = YAML.load_file(filename) fractual_path = FractualI18n.configuration.fractual_paths.find { |path| filename.starts_with?(path) } keys = filename.delete_prefix(fractual_path).delete_prefix("/").split("/") last_key = keys.pop.delete_suffix(".yml") keys << last_key keys.map! { |key| key.delete_prefix("_") } # remove underscore from partial name if new_content = translations.dig(locale.to_s, *keys) content[locale.to_s] = content.fetch(locale.to_s, {}).merge(new_content) end File.write(filename, content.to_yaml(line_width: 200)) end end
Private Instance Methods
fractual_files()
click to toggle source
# File lib/fractual_i18n/phrases.rb, line 31 def fractual_files I18n.load_path.select do |path| FractualI18n.configuration.fractual_paths.any? { |fp| path.starts_with?(fp) } end end