Reputation: 659
I have a page using i18next on node.
In the translation files, there are translations (duh) for various things (it's like a database for little helper snippets)
now i want to build a page, where the user can view them individually.
i want to access the loaded xx-translation.json
and make a (dropdown?) menu containing all the entries in one namespace
{
"category": {
"subcategory": { // i want to get ["bla", "blu", "bli"] as result
"bla" : "ble",
"blu" : "blo",
"bli" : "bly"
}
}
}
i'm thinking about a simple loop like
var amountOfEntries = translationJSON.category.subcategory.length;
for (var i = 0; i < amountOfEntries; i++) {
$('#menu'). //append that entry somehow
}
is there a way to access the translation.json inside my "normal" js and count the number of entries? and how can i build a menu piece by piece with the entries? (this is bonus, i think i'd manage to do that. the main question is the first one)
thanks
Upvotes: 1
Views: 208
Reputation: 591
Check out lodash.js for some good collection utility functions. You can iterate over the object with something like:
_.each(subcategory, function(val, key){
$(".menu").append("<li>" + key + ": " + val + "</li>");
});
is that helpful?
UPDATE
After clarifying your question in the comments above, I think what you're looking for is either getResource() or getResourceBundle().
Upvotes: 1