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
Hydrate translatable
#23982
Hydrate translatable
#23982
Conversation
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.
Hi! Thank you for your contribution, but I believe this is still incorrect!
Swapping the example case around by setting the user's language to es
and the post's to en
highlights the failure:
diff --git a/spec/lib/status_cache_hydrator_spec.rb b/spec/lib/status_cache_hydrator_spec.rb
index d1a1847309..da19f591c1 100644
--- a/spec/lib/status_cache_hydrator_spec.rb
+++ b/spec/lib/status_cache_hydrator_spec.rb
@@ -4,7 +4,7 @@ require 'rails_helper'
describe StatusCacheHydrator do
let(:status) { Fabricate(:status) }
- let(:account) { Fabricate(:account) }
+ let(:account) { Fabricate(:user, locale: 'es').account }
describe '#hydrate' do
let(:compare_to_hash) { InlineRenderer.render(status, account, :status) }
@@ -30,7 +30,7 @@ describe StatusCacheHydrator do
context 'when handling a translatable status' do
let(:poll) { Fabricate(:poll, account: account) }
- let(:status) { Fabricate(:status, poll: poll, account: account, language: 'es') }
+ let(:status) { Fabricate(:status, poll: poll, account: account, language: 'en') }
before do
service = instance_double(TranslationService::DeepL, supported?: true)
This is due to I18n.locale
not being set to the user's locale in StatusCacheHydrator
call sites, which makes sense as it did not previously return locale-specific values.
More generally, there is also the issue that the client can override the locale per API request using the lang
parameter.
Thank you for your review. I am still new to Mastodon, so I appreciate your insights. I have now wrapped the calls from
When the status is serialised via an API request, I considered whether the target locale should be passed as an argument for |
This is better, but I'm afraid this could negate some of the performance benefits of using What I'm more worried about though are the inconsistencies with how locale selection is done in other situations. Indeed, until your recent change, the streaming API was locale-agnostic, and the locale only mattered on the REST API endpoints. The locale selection for the REST API is handled in
The I'm not sure what the best way to proceed would be. Maybe a good compromise would be to come back on the initial change, and instead output the list of supported input languages, and the list of supported output languages. Though translation services might also work on language couples rather than such lists… |
Adding
I have opened a separate PR with an alternative implementation along these lines. This is a better fit for the current caching and streaming logic, and it only moves a little bit of the logic back into React. |
Closing in favour of #24037. |
Follow-up to #23879, based on comment from @ClearlyClaire:
StatusCacheHydrator
should hydratetranslatable
based on current user and locale.