Closed CarlosNZ closed 2 years ago
Hi. Can u attach part of app.json
and your i18n-unused.config.js
? it hard to say, where the problem by stack trace.
Thanks. This .zip contains:
i18n-unused.config.js
app.json
(which seems to be the only file that is behaving correctly)common.json
(which I think is the next file analysed which throws the error)You can clone our repo if you'd like to see more detail: https://github.com/openmsupply/openmsupply-client (Branch with this is called i18n-unused
)
Many thanks. :)
Ok, I'll take a look this week.
I looked at your code. U have errors, because u use wrong deep translations. For example in distribution.json
u use "label.group-by-item": "Group by Item",
instead of object structure for t('label.group-by-item')
. So, when my lib builds the structure t('label.group-by-item')
back, it expands into an object, not a string, e.g.:
// wrong
{
...
"label.group-by-item": "Group by Item",
...
}
// change to
{
...
"label": {
"group-by-item": "Group by Item"
}
...
}
If I helped solve your problem, please, close an issue. Also will be glad for star =)
@CarlosNZ, do you have any updates?
Okay thanks, I'll take a closer look tomorrow and close the issue.
Hi, it seems like "flat" nested keys should be acceptable in i18n JSON files: https://www.codeandweb.com/babeledit/documentation/file-formats#flat-json
And indeed we are using t('label.group-by-item')
-style using the https://www.i18next.com/ package throughout our app with no problems.
Ok, I see your point. I did a little research on this topic. I think it's possible to make implementation for flat json in next minor version at this week.
Excellent, thank you, I look forward to trying it out. :)
Hi. Thx for waiting =) U can try new 0.8.0 version. Now available option flatTranslations
, boolean, switch locale builder to flat json mode.
Thanks @mxmvshnvsk ,
it's working better now (gets further), but it's still throwing an error at a certain point when running mark
:
Successfully marked: /Users/carl/GitHub/openmsupply/client/packages/common/src/intl/locales/ar/app.json
Successfully marked: /Users/carl/GitHub/openmsupply/client/packages/common/src/intl/locales/ar/common.json
Successfully marked: /Users/carl/GitHub/openmsupply/client/packages/common/src/intl/locales/ar/replenishment.json
Successfully marked: /Users/carl/GitHub/openmsupply/client/packages/common/src/intl/locales/en/app.json
(node:63505) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'default-sell-price' of undefined
at applyToFlatKey.flatTranslations (/Users/carl/GitHub/openmsupply/client/node_modules/i18n-unused/dist/i18n-unused.cjs:485:51)
at /Users/carl/GitHub/openmsupply/client/node_modules/i18n-unused/dist/i18n-unused.cjs:395:7
at Array.reduce (<anonymous>)
at applyToFlatKey (/Users/carl/GitHub/openmsupply/client/node_modules/i18n-unused/dist/i18n-unused.cjs:393:16)
at /Users/carl/GitHub/openmsupply/client/node_modules/i18n-unused/dist/i18n-unused.cjs:484:37
at Array.forEach (<anonymous>)
at /Users/carl/GitHub/openmsupply/client/node_modules/i18n-unused/dist/i18n-unused.cjs:484:22
at Array.forEach (<anonymous>)
at markUnusedTranslations (/Users/carl/GitHub/openmsupply/client/node_modules/i18n-unused/dist/i18n-unused.cjs:481:35)
Oddly, there doesn't seem to be anything unique about "label.default-sell-price": "Default sell price",
-- it's just one of several label.
entries in that file.
@CarlosNZ, it's strange, because I cloned your repo and ran in i18n-unused
branch:
Try remove your node_modules
or clear cache and install packages again.
Weird, I tried it on a different machine with a freshly-cloned repo and I'm still getting the same error.
Running on macOS 12.3.
I cloned this repo and ran the your tests and got similar errors:
The current tests do not cover the codebase. I'll deal with this issue later. I'll try run clean installation on another machine later.
@CarlosNZ, I think I found the problem =) I looked at your update commit, you update package version, but not turn on flat json option in config, please, add follow option (it's in nested mode by default):
flatTranslations: true
@CarlosNZ, I think I found the problem =) I looked at your update commit, you update package version, but not turn on flat json option in config, please, add follow option (it's in nested mode by default):
Ah right, yes, my bad -- I didn't realise we needed to manually add that config option. Working well now, thank you :)
I'll close this issue now, but I just wanted to point out one tiny little thing you might want to address at some point: When running mark
or remove
your script removes a final line break in each file (even when there's nothing changed), which is different to how our auto-formatter (Prettier) does it (adds a final line break). So any file that we've manually saved shows up in the git diff after running this script, even if nothing has actually changed.
Thx, I made note about line break.
It's working fine (and giving seemingly correct results) with "display-unused". However, when I run "mark-unused" or "remove-unused", I get an error like so:
It deals with the first file (
app.json
) fine, but then gets no further.Any ideas?