简体   繁体   中英

Context added to translation tags do not pull through correctly to extracted translations

I'm using react-i18n to translate a web app.

I'm extracting translations from the tags I add to a JSON file using babel-plugin-i18next-extract .

I define a tag like so in my component:

{t("Departure", { context: "air" })}
{t("Departure", { context: "rail" })}

But in my extracted translations folder it comes through as:

"Departure": "",
"Departure_female": "",
"Departure_male": "",

It seems the extracted translation is ignoring the context and simply adding _male and _female is this a bug with babel-plugin-i18next-extract

babel-plugin-i18next-extract indeed doesn't extract the value of context keys because they are more likely to be variables and therfore parsing them would be pointless most of the time. One solution would be to use comment hints :

{/* i18next-extract-mark-context-next-line ["air"] */}
{t("Departure", { context: "air" })}

{/* i18next-extract-mark-context-next-line ["rail"] */}
{t("Departure", { context: "rail" })}

There's an open issue about this: https://github.com/gilbsgilbs/babel-plugin-i18next-extract/issues/121

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM