Locale priorization for translations (bug 983749)#18
Closed
magopian wants to merge 8 commits intomozilla:masterfrom
Closed
Locale priorization for translations (bug 983749)#18magopian wants to merge 8 commits intomozilla:masterfrom
magopian wants to merge 8 commits intomozilla:masterfrom
Conversation
Contributor
There was a problem hiding this comment.
Put the comment on a new line to be consistent with Second/Third ones.
Member
There was a problem hiding this comment.
Mention somewhere in the docstring and/or the inline comments that it tries to avoid duplicates.
Using .distinct() is too restrictive on the queryset and prevents it to be used in more general ways. Another solution is this hack to add a group_by clause.
Contributor
Author
|
This PR can't be merged as is, as it's introducing a "group by" clause (magopian@c792776#diff-547abaa7344efed8cabde90545e60135R132) that is very bad performance wise. |
Contributor
Author
There was a problem hiding this comment.
This group_by, at this place, is very dangerous: it will merge two addons with the same name. If a "group by" must be done, it may perhaps be done at the JOIN level using something like:
JOIN (
SELECT * from translations
WHERE localized_string IS NOT NULL
GROUP BY id
) T1
ON xxxx.name = T1.id
Contributor
Author
|
Closing this for now. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix bug 983749
The aim of this PR is to have various fallbacks when requesting a translation,
and not only one as we have at the moment.
Before: first get the translation for the active language, and if there's none,
check if there's a fallback translation (either in a locale provided via
model.get_fallback(), or thesettings.LANGUAGE_CODE).After: Check the following locales in order
1/ the active language
2/ the model fallback provided by the
get_fallback()method (if it exists)3/
settings.LANGUAGE_CODE4/ in last resort return just any translation found
This PR is quite hairy, as I implemented it in a way to minimize the number of
joins: if the three locales to choose from are all the same, just join twice
(once for the locale, and once for the "last chance" fallback returning any
translation) instead of four times.
I've tried to factorize as much code possible between
translation.queryand
translation.transformer.build_query, but both are using differentAPIs, and for different use cases, so the only bit in common is the
get_localesfunction.I've tried to comment it as thoroughly as possible to ease the review and the
maintenance, but I aknowledge that it's still a big piece of SQL generation,
and deep django code.
If you need help understand some pieces of the code, please let me know and
I'll try my best to explain it.