Skip to content

Commit

Permalink
Merge pull request #649 from codeforjapan/add-task-i18n_yaml-dump_all
Browse files Browse the repository at this point in the history
  • Loading branch information
ayuki-joto authored Feb 4, 2025
2 parents 440736d + de9701b commit 3bdd944
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions lib/tasks/i18n_yaml.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# frozen_string_literal: true

def deep_keys(hash, prefix = "")
hash.flat_map do |key, value|
full_key = prefix.empty? ? key.to_s : "#{prefix}.#{key}"
value.is_a?(Hash) ? deep_keys(value, full_key) : full_key
end
end

namespace :i18n_yaml do
desc "dump all locale data for some locale"
task dump_all: :environment do
locale = :ja
all_translations = I18n.t(".", locale:, default: {}).deep_merge({})
keys = deep_keys(all_translations)
buf = []
I18n.with_locale(locale) do
keys.each do |key|
# skip faker.*
next if key.start_with?("faker.")

buf << "#{key}: #{I18n.t(key)}"
rescue StandardError => e
warn "ERROR: #{key}, #{e.message}"
end
end

puts buf
end
end

0 comments on commit 3bdd944

Please sign in to comment.