Skip to content
This repository has been archived by the owner on Nov 15, 2019. It is now read-only.

Support adding nested values in JSON #16

Open
shivasingh0101 opened this issue Mar 7, 2016 · 7 comments
Open

Support adding nested values in JSON #16

shivasingh0101 opened this issue Mar 7, 2016 · 7 comments

Comments

@shivasingh0101
Copy link

Let say the json file look like

{
  "albums": {
    "sub_menu": {
       "all": "All Albums",
       "recent": "Recent",
    }
  }
}

In this case i want to use the recent keyword such as __('albums.sub_menu.recent') for now when using like this it is printing [object object]

@IvanProdaiko94
Copy link

It would be great feature :)

@JEGardner
Copy link

This would be ideal

@IvanProdaiko94
Copy link

I wrote it by myself but there already exists such a version

@IvanProdaiko94
Copy link

function byString(object, stringKey) {
stringKey = stringKey.replace(/^./, ''); // strip a leading dot

var keysArray = stringKey.split('.');
for (var i = 0, length = keysArray.length; i < length; ++i) {
    var key = keysArray[i];

    if (key in object) {
        object = object[key];
    } else {
        return;
    }
}

return object;

}

you can use this soulution

@JEGardner
Copy link

Thanks @IvanProdaiko94. On closer inspection it looks as if this code is in the repo (fixed in #9), but not the version on npm (as pointed out in #17). Could do with releasing a new version!

@michael-ciniawsky michael-ciniawsky changed the title feature for adding nested values in json file Support adding nested values in JSON Apr 14, 2017
@joshwiens joshwiens removed the pr label Apr 16, 2017
@Nialaren
Copy link

Nialaren commented Aug 2, 2017

Hello, just for the record and for all other people looking for the same answer.
The feature is already there by adding "nested" property into plugin config. It's not documented yet.
This issue can be closed I guess :)

@ianwalter
Copy link

I think this issue can be closed, no?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

8 participants
@ianwalter @Nialaren @michael-ciniawsky @JEGardner @joshwiens @shivasingh0101 @IvanProdaiko94 and others