I have a translations file which is a JSON object, which may contain more JSON objects and I need to find missing translations. JSON file ex:
export const locale = {
lang: 'en',
data: {
'NAV': {
'APPLICATIONS': 'Applications',
'DASHBOARDS' : 'Dashboards',
'CALENDAR' : 'Calendar',
'ECOMMERCE' : 'E-Commerce',
'ACADEMY' : 'Academy',
'MAIL' : {
'TITLE': 'Mail',
'BADGE': '25'
},
'MAIL_NGRX' : {
'TITLE': 'Mail Ngrx',
'BADGE': '13'
},
'CHAT' : 'Chat',
'FILE_MANAGER': 'File Manager',
'CONTACTS' : 'Contacts',
'TODO' : 'To-Do',
'SCRUMBOARD' : 'Scrumboard'
}
}
};
and I need to get each translation, which is the lowest level item (ex data.NAV.MAIL.BADGE or data.NAV.APPLICATIONS)and see if it exists in the files directory for my project.
Is it inefficient to open a ton of files, or is that difference negligible as compared to going translation by translation and opening each file (for potentially thousands of files)?
I was thinking of flattening the object recursively so I get one flat object with all keys, getting each file, and checking each string if it exists. If it does, I move it to a different object of found strings so it's not checked again. Whatever is left in original object is not used. I will also add whatever is in the git ignore to be ignored here as it is not relevant.
I think recursively going in each file that is in the directory that isn't ignored and then recursively checking if the key is in the file, and then going into the next key if it exists and checking may possibly be better?
Is there anything to make this more efficient that I may be missing?