Skip to content

Bugfix FXIOS-15212 #32729 [Translations Phase 2] "Automatically translate pages when available?" prompt is not displayed on supported webpages#32784

Merged
razvanlitianu merged 12 commits intomainfrom
rlitianu/translations-auto-translate-prompt
Apr 7, 2026
Merged

Bugfix FXIOS-15212 #32729 [Translations Phase 2] "Automatically translate pages when available?" prompt is not displayed on supported webpages#32784
razvanlitianu merged 12 commits intomainfrom
rlitianu/translations-auto-translate-prompt

Conversation

@razvanlitianu
Copy link
Copy Markdown
Collaborator

@razvanlitianu razvanlitianu commented Mar 30, 2026

📜 Tickets

Jira ticket
Github issue

💡 Description

After a user manually translates a page for the first time, a prompt appears at the bottom of the browser offering to enable auto-translate for future pages.

  • Tapping Enable saves the auto-translate preference and dismisses the prompt
  • Tapping × dismisses without enabling
  • The prompt is shown only once, guarded by translationAutoTranslatePromptShown pref
  • Auto-translate is skipped for the page load immediately following a manual restore, preventing re-translation when the user opts out

🎥 Demos

IMG_0346
Demo

📝 Checklist

  • I filled in the ticket numbers and a description of my work
  • I updated the PR name to follow our PR naming guidelines
  • I ensured unit tests pass and wrote tests for new code
  • If working on UI, I checked and implemented accessibility (Dynamic Text and VoiceOver)
  • If adding telemetry, I read the data stewardship requirements and will request a data review
  • If adding or modifying strings, I read the guidelines and will request a string review from l10n
  • If needed, I updated documentation and added comments to complex code

@razvanlitianu razvanlitianu changed the title Rlitianu/translations auto translate prompt Bugfix FXIOS-15212 #32729 [Translations Phase 2] "Automatically translate pages when available?" prompt is not displayed on supported webpages Mar 30, 2026
@mergify
Copy link
Copy Markdown
Contributor

mergify Bot commented Mar 31, 2026

This pull request has conflicts when rebasing. Could you fix it @razvanlitianu? 🙏

@razvanlitianu razvanlitianu force-pushed the rlitianu/translations-auto-translate-prompt branch from f5b8764 to 54b7bee Compare April 1, 2026 07:59
@razvanlitianu razvanlitianu requested review from FilippoZazzeroni, ih-codes and lmarceau and removed request for ih-codes April 1, 2026 11:34
@razvanlitianu razvanlitianu marked this pull request as ready for review April 1, 2026 11:35
@razvanlitianu razvanlitianu requested a review from a team as a code owner April 1, 2026 11:35
@mobiletest-ci-bot
Copy link
Copy Markdown

mobiletest-ci-bot commented Apr 1, 2026

Warnings
⚠️

❌ New file code coverage

The following new file(s) are below their scaled coverage:

File Coverage Required
firefox-ios/Client/Frontend/Translations/AutoTranslatePromptView.swift 0.0% 58.8%

Bypass label ignore-code-coverage detected — reporting as warnings only for this PR.

Messages
📖 Project coverage: 41.12%

✍️ Strings Updated

Detected changes in Shared/Strings.swift.
To keep strings up to standards, please add a member of the firefox-ios-l10n team as reviewer. 🌍

💪 Quality guardian

2 tests files modified. You're a champion of test coverage! 🚀

🧩 Neat Piece

This PR changes 524 lines. It's a substantial update,
but still review-friendly if there’s a clear description. Thanks for keeping things moving! 🚀

💬 Description craftsman

Great PR description! Reviewers salute you 🫡

🦊 BrowserViewController Check

We’re tracking the size of BrowserViewController.swift to keep it healthy.

  • ✨ Change in file size: +40 lines

Client.app: Coverage: 39.37

File Coverage
TranslationSettingsMiddleware.swift 86.88%
BrowserViewController.swift 34.83% ⚠️
TranslationsMiddleware.swift 96.36%
BrowserViewControllerState.swift 50.81%
AutoTranslatePromptState.swift 100.0%
TranslationsAction.swift 100.0%
AutoTranslatePromptView.swift 0.0% ⚠️

Shared: Coverage: 61.51

File Coverage
Prefs.swift 83.7%

Generated by 🚫 Danger Swift against 2046a74


private func handleAutoTranslatePrompt(state: BrowserViewControllerState) {
if state.autoTranslatePromptState.showPrompt {
guard autoTranslatePrompt == nil else { return }
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: we could move this guard up

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Moved the guard into showAutoTranslatePrompt() directly.


if isBottomSearchBar {
overKeyboardContainer.addArrangedViewToTop(prompt, animated: false, completion: {
self.view.layoutIfNeeded()
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

do we need to layout the entire view here ? shouldn't the stack view handles it already ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Removed, the stack view handles this.

})
} else {
bottomContainer.addArrangedViewToTop(prompt, animated: false, completion: {
self.view.layoutIfNeeded()
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

same here

switch notification.name {
case UIContentSizeCategory.didChangeNotification:
ensureMainThread {
self.messageLabel.font = FXFontStyles.Regular.body.scaledFont()
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

instead of having this method here setting up the font when size category changes, we could just specify in the setup of the labels the property adjustFontForContentSizeCategory to true

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Both labels already had this set at init, so removed the notification observer entirely.

Comment thread firefox-ios/Shared/Strings.swift Outdated

public struct AutoTranslatePrompt {
public static let Message = MZLocalizedString(
key: "", // Translations.AutoTranslatePrompt.Message.v151
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

why the keys are empty, you don't want to export already the translations ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Filled in the keys now. I was planning a later PR to enable all but let's do it here also.

@mergify
Copy link
Copy Markdown
Contributor

mergify Bot commented Apr 2, 2026

This pull request has conflicts when rebasing. Could you fix it @razvanlitianu? 🙏

Copy link
Copy Markdown
Collaborator

@FilippoZazzeroni FilippoZazzeroni left a comment

Choose a reason for hiding this comment

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

Hi @razvanlitianu just added another couple of comments worth checking before merging the rest looks good to me. i'd wait also for @lmarceau 's input before merging

guard autoTranslatePrompt == nil else { return }
showAutoTranslatePrompt()
} else {
guard autoTranslatePrompt != nil else { return }
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: at this point we can remove this since it is already handled in removeAutoTranslatePrompt

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I agree, that is redundant.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

do you think we need to update the constraints here ? same in removeAutoTranslatePrompt. theoretically the views should auto resize according to the subviews. Could you check this before merging ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The updateViewConstraints() calls match the microsurvey prompt pattern exactly (lines 2120 and 2144 in BVC). I took the microsurvey as the established reference for this kind of bottom-bar prompt, and kept the same pattern here.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Could you try removing it to see if does something cause it seems redundant to me, and also it is quite expansive to update all the constraints to just remove a view

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Tested it, the stack view handles the layout correctly without the explicit constraint update, so removed both calls.

@razvanlitianu
Copy link
Copy Markdown
Collaborator Author

Thanks for the input, @FilippoZazzeroni! I've addressed all the comments and will now wait for @lmarceau's feedback.

@razvanlitianu
Copy link
Copy Markdown
Collaborator Author

@mergify rebase

@mergify
Copy link
Copy Markdown
Contributor

mergify Bot commented Apr 3, 2026

rebase

❌ Base branch update has failed

Details

rebase conflict between base and head

@razvanlitianu razvanlitianu added the ignore-code-coverage Use this label with a comment and tag the unit tests owners label Apr 3, 2026
@razvanlitianu
Copy link
Copy Markdown
Collaborator Author

Adding ignore-code-coverage because the added controller AutoTranslatePromptView.swift would benefit more of UItests rather then Unit tests. cc @mozilla-mobile/fxios-unit-test-owners

- Add `translationAutoTranslate` pref key
- Add `toggleAutoTranslate` action type and `isAutoTranslateEnabled` middleware payload
- Add `isAutoTranslateEnabled` to state and reducer
- Add `autoTranslate` section/item to DiffableDataSource
- Add auto-translate toggle cell in TranslationPickerSettingsViewController
- Add strings: AutoTranslate.Title, AutoTranslate.Footer
- Move auto-translate section below preferred languages
- Add initialize action to read isTranslationsEnabled and
  isAutoTranslateEnabled synchronously before async fetch,
  preventing toggles from briefly showing incorrect state on load
…ranslation

Shows a one-time persistent prompt above the address bar after the user's
first manual translation (picker flag only), asking if they want to enable
auto-translate. Tapping Enable writes the pref and dismisses; tapping X
dismisses without enabling. Prompt is never shown again once seen, and is
suppressed if auto-translate is already on.

Also fixes a side effect where tapping the active translate icon to restore
the original page would immediately re-translate due to auto-translate being
enabled — the restore reload is now skipped for that one cycle.
- Add accessibilityIdentifier to messageLabel and explicit accessibilityLabel/identifier to enableButton
- Remove Notifiable conformance; adjustsFontForContentSizeCategory already handles Dynamic Type
- Move guard into showAutoTranslatePrompt(); remove layoutIfNeeded from completion closures
- Move @mainactor to class level in AutoTranslatePromptStateTests
- Add three tests for maybeShowAutoTranslatePrompt in TranslationsMiddlewareTests
- Fill in l10n string keys for AutoTranslatePrompt.Message and EnableButton
@razvanlitianu razvanlitianu force-pushed the rlitianu/translations-auto-translate-prompt branch from f22fb65 to 2046a74 Compare April 7, 2026 17:18
@razvanlitianu razvanlitianu merged commit 6c2e810 into main Apr 7, 2026
11 checks passed
@razvanlitianu razvanlitianu deleted the rlitianu/translations-auto-translate-prompt branch April 7, 2026 17:46
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 7, 2026

🚀 PR merged to main, targeting version: 150.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ignore-code-coverage Use this label with a comment and tag the unit tests owners

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants