Closed MrOrz closed 5 years ago
I figured out a minimal reproducible case:
// myfile.js
import { ngettext, msgid } from 'ttag';
export function* foo(length) {
yield bar(ngettext(
msgid`Foo ${length}`,
`Foo ${length}`,
length,
));
}
// .babelrc
{
"presets": [
[
"@babel/env",
{
"useBuiltIns": "usage",
"corejs": 3
}
]
],
"plugins": [
[
"babel-plugin-ttag",
{
"addComments": "t:",
"numberedExpressions": true,
"extract": { "output": "build/foo.po" }
}
]
]
}
$ babel myfile.js
Thanks @anilanar! Will try to investigate ASAP.
Sorry for the late investigation. But finally this issue was fixed in 1.7.17
. You can check out the new version. Please, let me know if that fixes your issue!
Keep in mind, while building for production always set resolve
setting in babel-plugin-ttag config. In other case the child nodes for ngettext
will not be transpiled.
@AlexMost That's a big problem for us, because we don't use resolve
. Our translations are only available during runtime (not at compile time). Can we use resolve.unresolved: skip
to overcome the issue?
@anilanar ah, if you are using this plugin only for translations extraction - you can just exclude ttag plugin for the production build. Have you tried ttag-cli
for the translations extract?
Or, you can also stay with resolve.unresolved: skip
in version 1.7.15
. I am going on a vacation for the next week and hope to fix that little issue after.
Sadly it’s not that simple. It’s a monorepo with shared dependencies and multiple projects having their own webpack builds so each project (and its deps) needs its own translations extracted. Therefore using a babel plugin is the easiest way of doing it. Otherwise I’d have to make webpack report all files that was part of a build and feed them into ttag-cli, which won’t be able to handle modules that were tree shaken or omitted from the build due to NODE_ENV flags etc.
Hi @anilanar, here is a fix for the validation - https://github.com/ttag-org/babel-plugin-ttag/pull/135. You can try 1.7.19
version. Let me know if that works for you.
@AlexMost Appreciate it. Added it to the current sprint, will let you know.
Reproduce
yarn
npm start
Expected
File being compiled and served in HTTP server, no error found
Actual
Shows error during compile:
Affected versions
babel-plugin-ttag
1.4.1
~1.7.3
babel-plugin-ttag
1.4.0
is the last good version.Note
Seems like a regression issue. Previous fix: https://github.com/ttag-org/babel-plugin-ttag/pull/81 .