-
Notifications
You must be signed in to change notification settings - Fork 1k
Warehouse: l10n skeleton #6535
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
Warehouse: l10n skeleton #6535
Conversation
To follow up on the "deferred This is our current localization method: def localize(message, **kwargs):
request = get_current_request()
return request.localizer.translate(_translation_factory(message, **kwargs)) which we expose as the traditional from warehouse.i18n import localize as _
# ...
request.session.flash(
_(
"Email address ${email_address} verified. ${confirm_message}.",
mapping={"email_address": email.email, "confirm_message": confirm_message},
),
queue="success",
) This works well for the bodies of views and forms, since there's an active Unfortunately, this doesn't work in form field declarations, like so: class TOTPValueMixin:
totp_value = wtforms.StringField(
validators=[
wtforms.validators.DataRequired(),
wtforms.validators.Regexp(
rf"^[0-9]{{{TOTP_LENGTH}}}$",
message=_(f"TOTP code must be {TOTP_LENGTH} digits."),
),
]
) ...since |
Yeah this is the exact issue I was expecting to see - makes sense. The workflow with the
Your current approach combines both steps into 1 via the Ok cool, problem stated - my solution: I would suggest defining For module-scope you need to find a good location to take a translationstring marked with For wtforms (I don't have much experience with this library so my suggestion is likely to be vague here) it probably means at the spot where you handle errors, you receive the error messages and you then run them through I hope this helps and I'm happy to spitball on some other options. |
e044490
to
d70b6d3
Compare
Turn compile-pos into build-pos, make more clever. Tag more strings.
The WTForms expansion handles all of this.
Use the _ hack only for views, where calling str() on LazyStrings is less trivial.
Only render the language switcher if we have something other than English to switch to.
Remove test German locale.
The only outstanding question I have is how we will handle setting the locale when rendering messages in email templates. I don't know that it must be addressed immediately, but given that once we launch translation services the strings will be translatable we might want to consider that. |
Hmm, do we have access to the request that prompted the email? If so, we could use our normal locale negotiation. Otherwise, we could probably add a |
Adds a tagged string in manage/views as a smoke test.
Resolution to email question: Email templates are rendered in the request before being enqueued, so the Locale of the request determines the locale of the template rendering! |
TODO:
.mo
files should cause the web container/service to restart in development modeAccept-Language
is not working, for unclear reasonsrequest
so that we can use_()
in form fieldsCloses #6455