-
-
Notifications
You must be signed in to change notification settings - Fork 115
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
Feat/locale #65
Feat/locale #65
Conversation
Thanks. Why do we need to copy the core? |
Also, does that mean each package should be installed via npm? That's not was the intention :) |
I think the translation should generate submodules with its own entry-points within packages/falso/src and bundled all together in one package. Maybe this might help to get the correct setup. |
@NetanelBasal no, user just need to install falso, i18n files are part of it. |
@NetanelBasal because without copying, when end user tries to access any function from i18n, it gives error of core functions not found. The reason behind that is lib is bundled separately and i18n files are bundled separately. Although, I will try to find out a way to eliminate that. |
Thanks for sharing. Initial structure was like that only, but nx only bundled main index.ts file. I will check if that can be changed through some configs. |
Looks tricky to setup correctly. I wonder if the rollup plugin for multiple entry files can do the trick. 🤔 |
@NetanelBasal modified the code which doesn't require copying core files. Let me know if this is good, then I can start looking into API integration. |
|
||
const data = jsonData.data; | ||
|
||
const updatedData = await translateDataArray(data, language); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need all this code? you have the data
array property from the JSON file, and we should translate its elements
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's needed for nested jsons.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For example?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For example data is array of objects instead of strings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we have such a case. Our data is always a list of strings
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@shhdharmen now I see the food example, you are right 😀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Chexk if you support this please
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checked for food, worked fine.
@@ -154,23 +77,29 @@ export function createLanguageIndexFile(outputDir: string) { | |||
|
|||
readdirSync(outputDir) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use glob
@@ -34,5 +34,8 @@ | |||
"devDependencies": { | |||
"@types/seedrandom": "3.0.1", | |||
"@types/uuid": "8.3.4" | |||
}, | |||
"exports": { | |||
"./i18n/*": "./i18n/*/index.cjs.js" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you verify it works with web bundlers such as Wepback, please? I' suggesting to build the library and npm link
to dist
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checked for webpack, it gave error for missing entry of .
in exports, so added that and it worked fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about this approach because you're referring only to cjs modules here, and web bundles can't tree-shake it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other approach could be to have package.json for each language, and it contains main
and module
entries in it and remove exports
from main package.json. Should I check that? We will need to take care that users still need to only install main package only.
Or can we use other builder than rollup? Like node? Which supports multiple entry points: https://nx.dev/node/build#additionalentrypoints. And it's built on top of webpack, which can help us with more configurations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We will need to ensure that users still need to install the main package only.
That's not an issue because it's tree-shakable. It'll not be bundled if they do not use the i18n functions.
There's a problem we did not think of - name collision. We should prefix the i18n function with the locale (e.g. ruRandFullName)
Let's try the other builder with the entry point support regarding the build.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the prefix in place, we can just export the i18n functions in the regular index.ts file, right? 🤔 No additional entry point is needed for packaging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@michaelxvoelker feel free to clone the repo or even the branch I created and try out what you mentioned. Let me know if it works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tried node builder, but doesn't produce results the way we want. I will research more.
PR Checklist
Please check if your PR fulfills the following requirements:
[ ] Tests for the changes have been added (for bug fixes / features)[ ] Docs have been added / updated (for bug fixes / features)PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: #1
What is the new behavior?
1. Translation languages
Add languages in
packages/falso/project.json
'stranslate
executor's options.2. Generate translation files
Above command will...
2. Add configuration for each language in
rollup.config.js
:Above approach can be simplified using glob patterns, but it requires more research.
3. Build the library with secondary entry points for each language
Above command will...
postBuild.js
script, which will internally run all needed scripts to create entry points for each language.3. Usage
After packing and publishing the library, one can use the translation like below:
Does this PR introduce a breaking change?