Skip to content
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

Bug 1955387 - Add locale fallback handling to the Rust based search engine selector. #6680

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mandysGit
Copy link
Contributor

  • Introduce a new record type for a list of availablelocales in the search configuration
  • Implement logic to use the user's locale directly, or strip the regional part for fallback
  • Map unsupported English locales to en-US

Pull Request checklist

  • Breaking changes: This PR follows our breaking change policy
    • This PR follows the breaking change policy:
      • This PR has no breaking API changes, or
      • There are corresponding PRs for our consumer applications that resolve the breaking changes and have been approved
  • Quality: This PR builds and tests run cleanly
    • Note:
      • For changes that need extra cross-platform testing, consider adding [ci full] to the PR title.
      • If this pull request includes a breaking change, consider cutting a new release after merging.
  • Tests: This PR includes thorough tests or an explanation of why it does not
  • Changelog: This PR includes a changelog entry in CHANGELOG.md or an explanation of why it does not need one
    • Any breaking changes to Swift or Kotlin binding APIs are noted explicitly
  • Dependencies: This PR follows our dependency management guidelines
    • Any new dependencies are accompanied by a summary of the due diligence applied in selecting them.

Branch builds: add [firefox-android: branch-name] to the PR title.

Sorry, something went wrong.

@mandysGit mandysGit requested a review from Standard8 April 1, 2025 15:19
…ngine selector.

- Introduce a new record type for a list of availablelocales in the search configuration
- Implement logic to use the user's locale directly, or strip the regional part for fallback
- Map unsupported English locales to en-US
@mandysGit mandysGit force-pushed the add-locale-fallback branch from bbb7e0a to e830bed Compare April 1, 2025 15:23
Copy link
Member

@Standard8 Standard8 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've started looking at this, but haven’t had much time, will finish looking tomorrow but thought I'd submit the two comments in-line anyway in case you have time to have a look.

Comment on lines +177 to +180
if locales_map_to_en_us.contains(&user_locale) {
user_environment.locale = "en-us".to_string();
return;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could simplify this to if user_locale starts with "en-" then make it "en-US".

The en-* locales we care about will presumably have already been listed in available_locales_set, so any other version of en- should just fall back to en-US. This would also avoid hard-coding the list of en-* locales which could easily be incomplete or be missed later.

available_locales = locales_record.locales.clone();
}
}
let mut user_environment = user_environment.clone();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should pass in a cloned, mutable user_environment here - currently I think filter_engine_configuration_impl would not get the updated locale, and hence it might determine the sort order/default engines incorrectly.

Copy link
Member

@Standard8 Standard8 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, one additional comment to address. The tests look good.

Comment on lines +197 to +201
let stringified = serde_json::to_string(&record.fields)?;
if let Some(val) = record.fields.get("recordType") {
if *val == "availableLocales" {
let locales_record: Option<JSONAvailableLocalesRecord> =
serde_json::from_str(&stringified)?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please can you put the serde_json::to_string statement within the second if statement to avoid it being called unnecessarily.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants