Closed Bug 1940756 Opened 1 year ago Closed 1 year ago

Further Unify Translations LangTag Matching

Categories

(Firefox :: Translations, task)

task

Tracking

()

RESOLVED FIXED
136 Branch
Tracking Status
firefox135 --- fixed
firefox136 --- fixed

People

(Reporter: nordzilla, Assigned: nordzilla)

References

Details

Attachments

(2 files)

Description

I did a further audit of language tag comparisons in the Translations ecosystem within Firefox, and noticed a few places that I missed in D231632.

❯ rg "(?i)((has|includes)\([a-z]*lang[a-z]*|[a-z]*lang[a-z]* +(==+|\!=+) +[a-z]*lang[a-z]*)" browser/components/translations toolkit/components/translations
toolkit/components/translations/TranslationsUtils.sys.mjs
75:    if (lhsLangTag === rhsLangTag) {

toolkit/components/translations/actors/TranslationsParent.sys.mjs
1343:          if (displayNames.has(langTag)) {
1889:      if (!hasToPivot.has(lang)) {
1904:      if (!hasFromPivot.has(lang)) {
3181:      lazy.alwaysTranslateLangTags.has(docLangTag) ||
3197:      lazy.neverTranslateLangTags.has(langTag) ||
3246:    if (!langTags.has(langTag)) {
3285:      mostRecentTargetLanguages.has(langTag) ||
3645:    if (this.#detectedLanguages === detectedLanguages) {

browser/components/translations/tests/browser/browser_translations_about_preferences_settings_ui.js
233:      getLangsFromPref(pref).includes(langTag),
255:      !getLangsFromPref(pref).includes(langTag),

browser/components/translations/tests/browser/head.js
1724:            return l10nArgs.language === expectedLanguageDisplayName;
2207:        fromLanguage !== toLanguage &&
2212:    if (fromLanguage === toLanguage) {

toolkit/components/translations/content/translations.mjs
165:        this.fromLanguage !== fromLanguage ||
166:        this.toLanguage !== toLanguage ||
242:          data.fromLanguage === fromLanguage &&
243:          data.toLanguage === toLanguage
682:        ({ toLang }) => toLang === sourceLanguage
687:        ({ fromLang }) => fromLang === targetLanguage

toolkit/components/translations/content/Translator.mjs
139:    if (fromLanguage === toLanguage) {
315:    if (fromLanguage !== toLanguage) {

toolkit/components/translations/content/translations-engine.worker.js
109:  if (FULL_WIDTH_PUNCTUATION_LANGUAGE_TAGS.includes(sourceLanguage)) {

We should unify more of these locations to utilize TranslationsUtils.langTagsMatch().

I would also like to make TranslationsUtils.normalizeLangTagForTranslations() into a private function, because ultimately we just want to find a match, which is what the previous function is for.


Tests to implement

All of this should provide equivalent behavior to before and existing tests should be sufficient.

This patch unifies more language-tag comparison locations to
utilize TranslationsUtils.langTagsMatch() instead of direct
string comparisons.

Attachment #9446558 - Attachment description: WIP: Bug 1940756 - Further Unfiy LangTag Matching in Translations r=#translations-reviewers! → Bug 1940756 - Further Unfiy LangTag Matching in Translations r=#translations-reviewers!
Attachment #9446558 - Attachment description: Bug 1940756 - Further Unfiy LangTag Matching in Translations r=#translations-reviewers! → Bug 1940756 - Further Unify LangTag Matching in Translations r=#translations-reviewers!
Pushed by enordin@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/f3d054bcf27f Further Unify LangTag Matching in Translations r=translations-reviewers,ohall,gregtatum
Status: NEW → RESOLVED
Closed: 1 year ago
Resolution: --- → FIXED
Target Milestone: --- → 136 Branch

This patch unifies more language-tag comparison locations to
utilize TranslationsUtils.langTagsMatch() instead of direct
string comparisons.

Original Revision: https://phabricator.services.mozilla.com/D233669

Attachment #9460734 - Flags: approval-mozilla-beta?
Attachment #9460734 - Flags: approval-mozilla-beta? → approval-mozilla-beta+
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: