Skip to content

Commit 4e03eec

Browse files
authored
Merge pull request #25 from gtt-project/test/locale-parity
Pin EN/JA locale parity with a test
2 parents c505e50 + 28efc74 commit 4e03eec

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

test/unit/locales_test.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
require File.expand_path('../test_helper', __dir__)
2+
3+
class LocalesTest < ActiveSupport::TestCase
4+
LOCALE_DIR = File.expand_path('../../config/locales', __dir__)
5+
6+
# All leaf key paths of a locale file, e.g. "activerecord.attributes.
7+
# issue_datetime.start_time". The files nest, so comparing top-level keys
8+
# would miss a string missing deeper down.
9+
def leaf_keys(locale)
10+
tree = YAML.safe_load_file(File.join(LOCALE_DIR, "#{locale}.yml")).fetch(locale)
11+
collect_leaves(tree).sort
12+
end
13+
14+
def collect_leaves(node, prefix = [])
15+
node.flat_map do |key, value|
16+
path = prefix + [key]
17+
value.is_a?(Hash) ? collect_leaves(value, path) : [path.join('.')]
18+
end
19+
end
20+
21+
test 'en and ja define the same keys' do
22+
# Every string ships in both languages; a key added to one file only
23+
# fails here instead of falling back silently in production.
24+
assert_equal leaf_keys('en'), leaf_keys('ja')
25+
end
26+
end

0 commit comments

Comments
 (0)