i18n-webpack-plugin icon indicating copy to clipboard operation
i18n-webpack-plugin copied to clipboard

Support adding nested values in JSON

Open shivasingh0101 opened this issue 8 years ago • 7 comments

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]

shivasingh0101 avatar Mar 07 '16 06:03 shivasingh0101

It would be great feature :)

IvanProdaiko94 avatar Jun 23 '16 13:06 IvanProdaiko94

This would be ideal

JEGardner avatar Jul 11 '16 10:07 JEGardner

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

IvanProdaiko94 avatar Jul 11 '16 10:07 IvanProdaiko94

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

IvanProdaiko94 avatar Jul 11 '16 10:07 IvanProdaiko94

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!

JEGardner avatar Jul 11 '16 13:07 JEGardner

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 :)

Nialaren avatar Aug 02 '17 14:08 Nialaren

I think this issue can be closed, no?

ianwalter avatar Jun 18 '18 15:06 ianwalter