Skip to content

Commit

Permalink
i18n spec file
Browse files Browse the repository at this point in the history
  • Loading branch information
HHassig committed Jun 26, 2024
1 parent 0f59ceb commit 3d7620d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
2 changes: 0 additions & 2 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
---
en:
hello: Hello world
32 changes: 32 additions & 0 deletions spec/i18n_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# frozen_string_literal: true

require "i18n/tasks"

describe "I18n sanity" do
let(:locales) do
ENV["ENFORCED_LOCALES"].presence || "ca"
end

let(:i18n) { I18n::Tasks::BaseTask.new(locales: locales.split(",")) }
let(:missing_keys) { i18n.missing_keys }
let(:unused_keys) { i18n.unused_keys }
let(:non_normalized_paths) { i18n.non_normalized_paths }

it "does not have missing keys" do
expect(missing_keys).to be_empty, "#{missing_keys.inspect} are missing"
end

it "does not have unused keys" do
expect(unused_keys).to be_empty, "#{unused_keys.inspect} are unused"
end

unless ENV["SKIP_NORMALIZATION"]
it "is normalized" do
error_message = "The following files need to be normalized:\n" \
"#{non_normalized_paths.map { |path| " #{path}" }.join("\n")}\n" \
"Please run `bundle exec i18n-tasks normalize --locales #{locales}` to fix them"

expect(non_normalized_paths).to be_empty, error_message
end
end
end

0 comments on commit 3d7620d

Please sign in to comment.