-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix translation in repo selector #1295
Fix translation in repo selector #1295
Conversation
This is the same case happening in Task Management, the tooltip should be translated, but it is imported from ansible-hub-ui/src/constants.tsx Lines 278 to 279 in 2acbd97
|
Aah @jerabekjiri this is not really about different files, this is about the order in which things run.. Constants in modules are evaluated right away, before lingui switches the language to the right one .. so thay stay in English. Normally (traditional gettext way), this is solved by a 2 step translation... using Except lingui doesn't have an So.. I think the approach of using functions instead of constants is valid, definitely for this case, but I'm less inclined to wrap every single constant with a human name in a function, that doesn't sound right. So I think we should not reinvent the wheel, and come up with a way to achieve Do you want to look into that or should I? |
One more note.. Looking at gettext docs, Maybe we can reintroduce it? (Or, failing that, we could write our own babel |
We could theoretically use |
Aah, sounds like you've found it, yeah, that sounds about right 👍 (docs - lazy translations, defineMessage) |
Reworked it to the Also found out this |
@@ -271,7 +273,7 @@ export class TaskListView extends React.Component<RouteComponentProps, IState> { | |||
<tr aria-labelledby={name} key={index}> | |||
<td> | |||
<Link to={formatPath(Paths.taskDetail, { task: taskId })}> | |||
<Tooltip content={Constants.TASK_NAMES[name] || name}> | |||
<Tooltip content={i18n._(Constants.TASK_NAMES[name] || name)}> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<Tooltip content={i18n._(Constants.TASK_NAMES[name] || name)}> | |
<Tooltip content={i18n._(Constants.TASK_NAMES[name]) || name}> |
we shouldn't expect the translation to exist when not in TASK_NAMES .. and lingui doesn't fall back to the original string in production
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@himdel This will crash if Constants.TASK_NAMES[name]
is undefined
, i18n._(...)
will throw error.
Constants.TASK_NAMES[name] ? (i18n._(Constants.TASK_NAMES[name]) || name) : name
something like this would work. We first check if Constants.TASK_NAME[name]
exists and then try to translate with i18n._(...)
, if not, return name
. The code seems a bit longer though, that's why I used that first variant.
{i18n._( | ||
Constants.TASK_NAMES[parentTask.name] || | ||
parentTask.name, | ||
)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{i18n._( | |
Constants.TASK_NAMES[parentTask.name] || | |
parentTask.name, | |
)} | |
{i18n._( | |
Constants.TASK_NAMES[parentTask.name]) || | |
parentTask.name | |
} |
(+- prettier anyway :))
Works but it tries to translate the message when a language is set. Though, I suspect that means Verified that |
Works in the UI, I think the repo selector changes make sense as well 👍 So, just that one |
Well, we could write that as |
cb5e034
to
49265cb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works for me :)
Backport to stable-4.4: 💚 backport PR created✅ Backport PR branch: Backported as #1563 🤖 @patchback |
* fix repo selector string translating * remove getValFromFnc util * use defineMessage for constant translation * add translation of tasks * fix translation in task_detail page * fix translations * rewrite to clearer statement Issue: AAH-1070 (cherry picked from commit 2872781) Co-authored-by: Jiří Jeřábek <Jerabekjirka@email.cz>
Issue: AAH-1070
Strings that are marked for translation don't seem to be working if imported from a different file. This is fixed by returning the string in the function and then evoking the function in component. Not sure this is the right way, I couldn't find any mention about this in the Lingui documentation, wdyt @himdel ?
before:
after: