I use angular translators for a large application. Having several people making code translations +, many times the translation objects are not synchronized.
I am creating a Grunt plugin to look at the structure of both files and compare it (just keys and general structure, not values).
Basic goals:
- Look at each file and see if the structure of the entire object (or the file, in this case) exists - this is the same as the translated ones;
- On error, return a key that does not match.
Turns out it was a little harder than I expected. So I decided that I could do something like:
Sort object ;- Check the type of data that contains the value (since they are translations, it will only have strings or objects for attachments) and save them in another object, making the key equal to the original key, and the value will be string 'String' or object in case it is an object. This object contains children;
- Repeat steps 1-2 recursively until the entire object is matched and sorted;
- Do the same for all files
- String and compare everything.
A small example might be the following object:
{
key1: 'cool',
key2: 'cooler',
keyWhatever: {
anotherObject: {
key1: 'better',
keyX: 'awesome'
},
aObject: 'actually, it\ a string'
},
aKey: 'more awesomeness'
}
will be displayed:
{
aKey: 'String',
key1: 'String',
key2: 'String',
keyWhatever: {
aObject: 'String',
anotherObject: {
key1: 'String',
keyX: 'String'
}
}
}
After that, I would contract all the objects and continue a rigorous comparison.
My question is, is there a better way to accomplish this? Both in terms of simplicity and in terms of performance, since there are many translation files, and they are quite large.
, , .
: , , . - : D , , , . , , "enter" . , , . ?