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

Add feature, nested locales folder structure #319

Closed
wants to merge 1 commit into from
Closed

Add feature, nested locales folder structure #319

wants to merge 1 commit into from

Conversation

Pavllick
Copy link

New feature which lets nesting locale files into folders. Nesting level is not limited. On a build step all nested files merge into single JSON file in language core folder with nested objects. Change doesn't break any existing API and fully compatible with current projects.

All source locale files stored in /locales folder as before and go into /localesBuild after build.

Example added, documentation updated.

Copy link
Owner

@aralroca aralroca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey @Pavllick . Thank you very much for your contribution! 👏 However, we are now working with version 1.0 of this library, without "build step", using a Next.js plugin, and I think it is not time to add this feature in the builder because you will be able to do something similar in version 1.0 and we will deprecate this "build step" soon.

I encourage you to try the 1.0.0-experimental.4 prerelease, you can achieve the same feature you develop with:

i18n.js

module.exports = {
  locales: ["en", "ca", "es"],
  defaultLocale: "en",
  pages: {
    "*": ["common"],
    "/404": ["error"],
    "/": ["home"],
    "/dashboard": ["home"],
    "rgx:^/more-examples": ["more-examples"]
  },
  // this way you can load "ns.js" / "ns.json" / "ns/index.js"
  loadLocaleFrom: (lang, ns) => import(`./locales/${lang}/${ns}`).then(m => m.default)
}

And then, you can have a structure like this:

.
├── ca
│   ├── common.json
│   ├── home.json
│   └── component
│       ├── index.json
│       ├── textEditor.json
│       └── singup.json
├── en
│   ├── common.json
│   ├── home.json
│   └── component
│       ├── index.js
│       ├── textEditor.json
│       └── singup.json
└── es
    ├── common.json
    ├── home.json
    └── component
        ├── index.js
        ├── textEditor.json
        └── singup.json

When in your index.js you can just export the JSON's:

import textEditor from './textEditor.json'
import signup from './signup.json'

export default { textEditor, signup }

You can already try this with the experimental version and it should work well. I am sorry that you have done so much work to add this new feature. 😔

@Pavllick
Copy link
Author

Hi @aralroca. That's cool, thank you, I didn't notice that new version support this feature. And it's ok, not so much work )

@aralroca
Copy link
Owner

@Pavllick ok! I close the PR! Anyway, if you dare to try the experimental version and find bugs don't hesitate to report them in the issue #129, because it is important that people try it in order to stabilize it. Thanks again, and I appreciate the contribution!

@aralroca aralroca closed this Nov 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants