How to define a message with context, but without id, in JS without macro? #2490
-
|
I use Lingui on the server side in Node.js without macros, and it works well with simple strings like this: const text = i18n.t(/* i18n */ 'Right')The extractor correctly parses this and adds the strings to the translation files. But in some cases, I need to pass the context to the message string, like this: const text2 = i18n.t(/* i18n */ { message: 'Right', context: 'direction' })and this approach doesn't work; the extractor just misses the message. const text1 = i18n.t(/* i18n */ { id: 'right', message: 'Right', context: 'direction' })it starts to work well! But, if I switch to using manual ids instead of auto-generated, like this: const text1 = i18n.t(/* i18n */ { id: 'right_direction', message: 'Right', context: 'direction' })
const text2 = i18n.t(/* i18n */ { id: 'right_check_result', message: 'Right', context: 'check result' })there is no benefit for the context value, because the id values are already different, and adding the context just duplicates the information. So, the question is: is there any way to define a message with context, without assigning the message id to it manually? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Short answer - no. Long version: You got this correctly - there is no sense adding a context if you using a manual ids. And there is no difference if you pass or not pass context when you don't use macro. The "autogeneration" of id, happened on the macro level. It do it using a formula The only one way to provide a different translations for the same source message in your case - is manually provide and id. |
Beta Was this translation helpful? Give feedback.
Short answer - no.
Long version:
You got this correctly - there is no sense adding a context if you using a manual ids. And there is no difference if you pass or not pass context when you don't use macro.
The "autogeneration" of id, happened on the macro level. It do it using a formula
hash(message + context). If you are not using macro - you don't have id generation. Your id is your message "Right"The only one way to provide a different translations for the same source message in your case - is manually provide and id.