lingui / js-lingui

🌍 πŸ“– A readable, automated, and optimized (3 kb) internationalization for JavaScript
https://lingui.dev
MIT License
4.62k stars 382 forks source link

How to pass variables to select? #725

Closed SilentImp closed 4 years ago

SilentImp commented 4 years ago

I have a gender-dependent translation for Italian. A string that I want to translate also includes the variable. I tried:

                 <Select
                    value={gender}
                    female="Find {professionPluralName} near you"
                    other="Find {professionPluralName} near you"
                  />

generated: "{gender, select, female {Find {professionPluralName} near you} other {Find {professionPluralName} near you}}": "{gender, select, female {Find {professionPluralName} near you} other {Find {professionPluralName} near you}}", But professionPluralName was replaced with empty string, despite being present in same scope.

                 <Select
                    value={gender}
                    female={<Trans>Find {professionPluralName} near you</Trans>}
                    other={<Trans>Find {professionPluralName} near you</Trans>}
                  />

generated: "{gender, select, female {} other {}}": "{gender, select, female {} other {}}" which was obviously broken.

                  <Trans>
                    <Select
                      value={gender}
                      female="Find {professionPluralName} near you"
                      other="Find {professionPluralName} near you"
                    />
                  </Trans>

generated: "{gender, select, female {Find {professionPluralName} near you} other {Find {professionPluralName} near you}}" same problem us without Trans

What I need to do to pass professionPluralName, and what is the correct way to do it?

Expected behavior To be able to pass multiple variables to the Select component.

module.exports = { presets: [ [ "next/babel", { "preset-env": { corejs: 3, modules: isTestEnvironment ? "commonjs" : false, debug: false, useBuiltIns: "entry", targets: { browsers: [">0.2%", "not dead", "not ie < 11", "not op_mini all"], }, }, }, ], ], plugins: [ "macros", "ramda", [ "emotion", { labelFormat: "[local]", }, ], [ "module-resolver", { alias: { infrastructure: "./src/infrastructure", pages: "./src/ui/pages", sharedKernel: "./src/ui/sharedKernel", designSystem: "./lib/designSystem", }, }, ], ], };

SilentImp commented 4 years ago

It looks like if I write it this way it works properly: Looks like if I write it in this manner it's works:

                  <Trans
                    id="{gender, select, female {Find {professionPluralName} near you} other {Find {professionPluralName} near you}}"
                    defaults="{gender, select, female {Find {professionPluralName} near you} other {Find {professionPluralName} near you}}"
                    values={{ professionPluralName, gender }}
                  />

But looks really sad.

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.