Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow slashes and spaces in keys #2066

Open
3 tasks done
kwmbe opened this issue Jan 3, 2025 · 0 comments
Open
3 tasks done

Allow slashes and spaces in keys #2066

kwmbe opened this issue Jan 3, 2025 · 0 comments
Labels
Status: Proposal Request for comments

Comments

@kwmbe
Copy link

kwmbe commented Jan 3, 2025

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

@kwmbe kwmbe added the Status: Proposal Request for comments label Jan 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Proposal Request for comments
Projects
None yet
Development

No branches or pull requests

1 participant