-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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 i18n of video transcript #3494
Conversation
<a class="a11y-menu-item-link" href="#${item['value']}" title="${_(item['display_name'])}" data-value="${item['value']}"> | ||
${_(item['display_name'])} | ||
<% dname = item['display_name'] %> | ||
<a class="a11y-menu-item-link" href="#${item['value']}" title="${_(dname)}" data-value="${item['value']}"> |
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.
The mistake was here - defining _(item['display_name'])
resulted in 'display_name'
being scraped for translation, which caused obvious error 😓
So lesson learned: anything inside quotes will be scraped. So, to make sure the i18n and l10n works right here, we cannot put the dictionary lookup directly inside the _()
call, instead we make it in one place and substitute it in.
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.
Right, and it looks quite similar to original _('{file_format}'.format(file_format=item['display_name'])?
Thank you for update.
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.
Ah yeah it does. the problem with the original is, again, that we have to have the quotes in there, so '{file_format}'
got scraped as a string. These cases are very tricky.
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.
A-ha, so _('{}').format(item['display_name']) will also work?
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.
If you do this, then '{}'
will appear in the translation file. I think it is a bad idea, to a translator seeing the string '{}'
will be confusing and they very well may mis-translate it, add words, etc.
It is better to do
var = item['thing']
_(var)
because _(var)
will look up the value of var
in the translation file at runtime, but our static analysis scraper will not scrape anything in this call.
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.
o, you right. Thanks. 👍
@auraz yikes I made a mistake on this. Take a look to understand the mistake I made.
Proof this works: