Description
Clear and concise description of the problem
Since keys in JSON are allowed to contain spaces and slashes, it would be nice if these characters could be used in our translation keys.
Suggested solution
I looked in the node module if there was anything like this search result I got for ruby, but didn't find anything.
For finding the key it seems the string is only split on .
, so I don't get why spaces and slashes in keys don't work. Looking at the code following the splitting of the key, this logic does look pretty complicated for what it should do. In an own project I did something similar on functionally one line as follows:
(key, obj) => {
const r = ([first, ...rest], obj) => Array.isArray(rest) && rest.length >= 1
? r(rest, obj[first])
: obj[first < 0 ? 0 : first]
return r(key.split('.'), obj);
}
I know this project is a tad more complicated than my own, however in my eyes it looks like this could be done in an easier way, and ideally in a way that supports spaces and slashes in keys, like my snippet does.
Alternative
My only other option is to remove the slashes and spaces everywhere i18n is used, but this
Additional context
For my project I need to use keys which contain spaces and slashes.
Validations
- Read the Contributing Guidelines
- Read the Documentation
- Check that there isn't already an issue that request the same feature to avoid creating a duplicate.