File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments