webpack-contrib / i18n-webpack-plugin

[DEPRECATED] Embed localization into your bundle
MIT License
317 stars 74 forks source link

Support adding nested values in JSON #16

Open shivasingh0101 opened 8 years ago

shivasingh0101 commented 8 years ago

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 commented 8 years ago

It would be great feature :)

JEGardner commented 8 years ago

This would be ideal

IvanProdaiko94 commented 8 years ago

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

IvanProdaiko94 commented 8 years ago

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 commented 8 years ago

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!

Nialaren commented 7 years ago

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 commented 6 years ago

I think this issue can be closed, no?