File tree 1 file changed +28
-0
lines changed
1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change
1
+ import { describe , it , expect } from 'vitest'
2
+ import { resolve } from 'node:path'
3
+ import { readdirSync } from 'node:fs'
4
+ import en from '../locales/en-US.json'
5
+
6
+ function getKeys ( obj : any , path = '' , result : string [ ] = [ ] ) {
7
+ for ( let key in obj ) {
8
+ if ( typeof obj [ key ] === 'object' ) {
9
+ getKeys ( obj [ key ] , path ? `${ path } .${ key } ` : key , result ) ;
10
+ } else {
11
+ result . push ( path ? `${ path } .${ key } ` : key ) ;
12
+ }
13
+ }
14
+ return result ;
15
+ }
16
+
17
+ const localesOtherThanEnglish = readdirSync ( resolve ( __dirname , '../locales' ) ) . filter ( ( file ) => {
18
+ return file . endsWith ( '.json' ) && ! file . startsWith ( 'en-US' )
19
+ } )
20
+ const defaultKeys = getKeys ( en ) ;
21
+
22
+ describe ( "locale files should include all keys" , ( ) => {
23
+ localesOtherThanEnglish . forEach ( ( locale ) => {
24
+ it ( `for ${ locale } ` , ( ) => {
25
+ expect ( getKeys ( require ( `../locales/${ locale } ` ) ) ) . toEqual ( defaultKeys )
26
+ } )
27
+ } )
28
+ } )
You can’t perform that action at this time.
0 commit comments