I have a JS code bundle to handle basic internationalization.
var EN = {
messages: {
newButton: {
text: "New"
},
userSettings: {
language: {
selectYourLanguage: "Choose your preferred language",
fr: "French",
en: "English"
}
}
}
};
var FR = {
messages: {
newButton: {
text: "Nouveau"
},
userSettings: {
language: {
selectYourLanguage: "Choissez votre langage préféré:",
fr: "Français",
en: "Anglais"
}
}
}
};
I want to know if it is possible to compare the 2 objects by their "paths". I want to be able to ensure that there is no path of first object that is not also in second object.
I want to be sure that someone adding a translation for one language, never forget to add it to the other language too, to fail-fast.
I want to be able to add new languages in the future.
Any idea on an elegant and generic way to do achieve this?
I'm looking for something like this
haveSameKeys(objectList)
Where objectList contains objects (like FR / EN / ...). Order should not matter. That list will be keep a relatively small size.
I would tend to prefer pure solutions that return their result, not involving side effects like alerting or throwing errors.
I don't really care about runtime performances as it's to fail-fast in dev/integration and won't be run in production.