Bug 1792464 - Convert findbar.properties to Fluent. r=NeilDeakin,fluent-reviewers,flod

Differential Revision: https://phabricator.services.mozilla.com/D158768
This commit is contained in:
Eemeli Aro 2022-10-07 08:23:50 +00:00
Родитель 565554ea3b
Коммит b30456f337
10 изменённых файлов: 235 добавлений и 119 удалений

Просмотреть файл

@ -0,0 +1,118 @@
# Any copyright is dedicated to the Public Domain.
# http://creativecommons.org/publicdomain/zero/1.0/
import fluent.syntax.ast as FTL
from fluent.migrate.helpers import VARIABLE_REFERENCE
from fluent.migrate.transforms import COPY, PLURALS, REPLACE_IN_TEXT
def migrate(ctx):
"""Bug 1792464 - Convert findbar.properties to Fluent, part {index}."""
source = "toolkit/chrome/global/findbar.properties"
target = "toolkit/toolkit/main-window/findbar.ftl"
ctx.add_transforms(
target,
target,
[
FTL.Message(
id=FTL.Identifier("findbar-not-found"), value=COPY(source, "NotFound")
),
FTL.Message(
id=FTL.Identifier("findbar-wrapped-to-top"),
value=COPY(source, "WrappedToTop"),
),
FTL.Message(
id=FTL.Identifier("findbar-wrapped-to-bottom"),
value=COPY(source, "WrappedToBottom"),
),
FTL.Message(
id=FTL.Identifier("findbar-normal-find"),
attributes=[
FTL.Attribute(
id=FTL.Identifier("placeholder"),
value=COPY(source, "NormalFind"),
)
],
),
FTL.Message(
id=FTL.Identifier("findbar-fast-find"),
attributes=[
FTL.Attribute(
id=FTL.Identifier("placeholder"), value=COPY(source, "FastFind")
)
],
),
FTL.Message(
id=FTL.Identifier("findbar-fast-find-links"),
attributes=[
FTL.Attribute(
id=FTL.Identifier("placeholder"),
value=COPY(source, "FastFindLinks"),
)
],
),
FTL.Message(
id=FTL.Identifier("findbar-case-sensitive-status"),
attributes=[
FTL.Attribute(
id=FTL.Identifier("value"), value=COPY(source, "CaseSensitive")
)
],
),
FTL.Message(
id=FTL.Identifier("findbar-match-diacritics-status"),
attributes=[
FTL.Attribute(
id=FTL.Identifier("value"),
value=COPY(source, "MatchDiacritics"),
)
],
),
FTL.Message(
id=FTL.Identifier("findbar-entire-word-status"),
attributes=[
FTL.Attribute(
id=FTL.Identifier("value"), value=COPY(source, "EntireWord")
)
],
),
FTL.Message(
id=FTL.Identifier("findbar-found-matches"),
attributes=[
FTL.Attribute(
id=FTL.Identifier("value"),
value=PLURALS(
source,
"FoundMatches",
VARIABLE_REFERENCE("total"),
foreach=lambda n: REPLACE_IN_TEXT(
n,
{
"#1": VARIABLE_REFERENCE("current"),
"#2": VARIABLE_REFERENCE("total"),
},
),
),
)
],
),
FTL.Message(
id=FTL.Identifier("findbar-found-matches-count-limit"),
attributes=[
FTL.Attribute(
id=FTL.Identifier("value"),
value=PLURALS(
source,
"FoundMatchesCountLimit",
VARIABLE_REFERENCE("limit"),
foreach=lambda n: REPLACE_IN_TEXT(
n,
{"#1": VARIABLE_REFERENCE("limit")},
),
),
)
],
),
],
)

Просмотреть файл

@ -5,6 +5,8 @@ const { ContentTaskUtils } = ChromeUtils.import(
"resource://testing-common/ContentTaskUtils.jsm"
);
requestLongerTimeout(2);
const TEST_PAGE_URI = "data:text/html;charset=utf-8,The letter s.";
// Using 'javascript' schema to bypass E10SUtils.canLoadURIInRemoteType, because
// it does not allow 'data:' URI to be loaded in the parent process.
@ -78,8 +80,8 @@ add_task(async function test_not_found() {
await promiseFindFinished(gBrowser, "--- THIS SHOULD NEVER MATCH ---", false);
let findbar = gBrowser.getCachedFindBar();
is(
findbar._findStatusDesc.textContent,
findbar._notFoundStr,
findbar._findStatusDesc.dataset.l10nId,
"findbar-not-found",
"Findbar status text should be 'Phrase not found'"
);
@ -95,7 +97,7 @@ add_task(async function test_found() {
// Search for a string that WILL be found, with 'Highlight All' on
await promiseFindFinished(gBrowser, "S", true);
ok(
!gBrowser.getCachedFindBar()._findStatusDesc.textContent,
!gBrowser.getCachedFindBar()._findStatusDesc.dataset.l10nId,
"Findbar status should be empty"
);
@ -125,8 +127,8 @@ add_task(async function test_tabwise_case_sensitive() {
// Not found for first tab.
await promiseFindFinished(gBrowser, "S", true);
is(
findbar1._findStatusDesc.textContent,
findbar1._notFoundStr,
findbar1._findStatusDesc.dataset.l10nId,
"findbar-not-found",
"Findbar status text should be 'Phrase not found'"
);
@ -134,7 +136,10 @@ add_task(async function test_tabwise_case_sensitive() {
// But it didn't affect the second findbar.
await promiseFindFinished(gBrowser, "S", true);
ok(!findbar2._findStatusDesc.textContent, "Findbar status should be empty");
ok(
!findbar2._findStatusDesc.dataset.l10nId,
"Findbar status should be empty"
);
gBrowser.removeTab(tab1);
gBrowser.removeTab(tab2);
@ -167,13 +172,13 @@ add_task(async function test_reinitialization_at_remoteness_change() {
// Findbar should operate normally.
await promiseFindFinished(gBrowser, "z", false);
is(
findbar._findStatusDesc.textContent,
findbar._notFoundStr,
findbar._findStatusDesc.dataset.l10nId,
"findbar-not-found",
"Findbar status text should be 'Phrase not found'"
);
await promiseFindFinished(gBrowser, "s", false);
ok(!findbar._findStatusDesc.textContent, "Findbar status should be empty");
ok(!findbar._findStatusDesc.dataset.l10nId, "Findbar status should be empty");
// Moving browser into the parent process and reloading sample data.
ok(browser.isRemoteBrowser, "Browser should be remote now.");
@ -192,13 +197,13 @@ add_task(async function test_reinitialization_at_remoteness_change() {
// Findbar should keep operating normally after remoteness change.
await promiseFindFinished(gBrowser, "z", false);
is(
findbar._findStatusDesc.textContent,
findbar._notFoundStr,
findbar._findStatusDesc.dataset.l10nId,
"findbar-not-found",
"Findbar status text should be 'Phrase not found'"
);
await promiseFindFinished(gBrowser, "s", false);
ok(!findbar._findStatusDesc.textContent, "Findbar status should be empty");
ok(!findbar._findStatusDesc.dataset.l10nId, "Findbar status should be empty");
BrowserTestUtils.removeTab(tab);
});
@ -430,7 +435,7 @@ add_task(async function test_preservestate_on_reload() {
for (let stateChange of ["case-sensitive", "entire-word"]) {
let tab = await BrowserTestUtils.openNewForegroundTab(
gBrowser,
"data:text/html,<p>There is a cat named Theo in the kitchen with another cat named Catherine. The two of them are thirsty."
"data:text/html,<!DOCTYPE html><p>There is a cat named Theo in the kitchen with another cat named Catherine. The two of them are thirsty."
);
// Start a find and wait for the findbar to open.

Просмотреть файл

@ -8,7 +8,7 @@ const TEST_PAGE_URI =
let gUpdateCount = 0;
requestLongerTimeout(2);
requestLongerTimeout(5);
function initForBrowser(browser) {
gUpdateCount = 0;

Просмотреть файл

@ -30,7 +30,7 @@ async function promiseFindFinished(gBrowser, searchText, highlightOn = false) {
// forces foundOrTimeout wait for the second "FOUND" message before
// resolving the promise.
let waitMore = highlightOn;
let findTimeout = setTimeout(() => foundOrTimedout(null), 2000);
let findTimeout = setTimeout(() => foundOrTimedout(null), 5000);
let foundOrTimedout = function(aData) {
if (aData !== null && waitMore) {
waitMore = false;
@ -40,7 +40,7 @@ async function promiseFindFinished(gBrowser, searchText, highlightOn = false) {
info("Result listener not called, timeout reached.");
}
clearTimeout(findTimeout);
findbar.browser.finder.removeResultListener(resultListener);
findbar.browser?.finder.removeResultListener(resultListener);
resolve();
};

Просмотреть файл

@ -169,8 +169,8 @@
await toggleHighlightAndWait(false);
let matches = gFindBar._foundMatches.value.match(/([\d]*)\sof\s([\d]*)/);
is(matches[1], "2", "Found correct amount of matches")
const matches = JSON.parse(gFindBar._foundMatches.dataset.l10nArgs);
is(matches.total, 2, "Found correct amount of matches")
await SpecialPowers.spawn(gBrowser, [], async function(args) {
function getSelection(docShell) {

Просмотреть файл

@ -402,10 +402,10 @@
"match case label is hidden in automatic mode");
await enterStringIntoFindField("a");
var insensitiveLabel = matchCaseLabel.value;
const insensitiveL10nId = matchCaseLabel.dataset.l10nId;
await enterStringIntoFindField("A");
var sensitiveLabel = matchCaseLabel.value;
ok(insensitiveLabel != sensitiveLabel,
const sensitiveL10nId = matchCaseLabel.dataset.l10nId;
ok(insensitiveL10nId != sensitiveL10nId,
"Case Sensitive label was not correctly updated");
// bug 365551
@ -621,12 +621,12 @@
current: 0,
total: 0
}];
let regex = /([\d]*)\sof\s([\d]*)/;
function assertMatches(aTest, aMatches) {
is(aMatches[1], String(aTest.current),
function assertMatches(aTest) {
const matches = JSON.parse(foundMatches.dataset.l10nArgs);
is(matches.current, aTest.current,
`${linksOnly ? "[Links-only] " : ""}Currently highlighted match should be at ${aTest.current} for '${aTest.text}'`);
is(aMatches[2], String(aTest.total),
is(matches.total, aTest.total,
`${linksOnly ? "[Links-only] " : ""}Total amount of matches should be ${aTest.total} for '${aTest.text}'`);
}
@ -643,11 +643,10 @@
await new Promise(resolve => setTimeout(resolve, timeout));
await enterStringIntoFindField(test.text, false);
await promiseMatchesCountResult(test.text);
let matches = foundMatches.value.match(regex);
if (!test.total) {
ok(!matches, "No message should be shown when 0 matches are expected");
ok(!foundMatches.dataset.l10nId, "No message should be shown when 0 matches are expected");
} else {
assertMatches(test, matches);
assertMatches(test);
for (let i = 1; i < test.total; i++) {
await new Promise(resolve => setTimeout(resolve, timeout));
gFindBar.onFindAgainCommand();
@ -658,7 +657,7 @@
text: test.text,
current,
total: test.total
}, foundMatches.value.match(regex));
});
}
}
}

Просмотреть файл

@ -10,12 +10,6 @@
const { AppConstants } = ChromeUtils.import(
"resource://gre/modules/AppConstants.jsm"
);
let LazyConstants = {};
ChromeUtils.defineModuleGetter(
LazyConstants,
"PluralForm",
"resource://gre/modules/PluralForm.jsm"
);
const PREFS_TO_OBSERVE_BOOL = new Map([
["findAsYouType", "accessibility.typeaheadfind"],
@ -55,9 +49,9 @@
data-l10n-id="findbar-match-diacritics" oncommand="_setDiacriticMatching(this.checked ? 1 : 0);"/>
<checkbox anonid="find-entire-word" class="findbar-entire-word tabbable"
data-l10n-id="findbar-entire-word" oncommand="toggleEntireWord(this.checked);"/>
<label anonid="match-case-status" class="findbar-label" />
<label anonid="match-diacritics-status" class="findbar-label" />
<label anonid="entire-word-status" class="findbar-label" />
<label anonid="match-case-status" class="findbar-label" data-l10n-attrs="value" />
<label anonid="match-diacritics-status" class="findbar-label" data-l10n-attrs="value" />
<label anonid="entire-word-status" class="findbar-label" data-l10n-attrs="value" />
<label anonid="found-matches" class="findbar-label found-matches" hidden="true" />
<image anonid="find-status-icon" class="find-status-icon" />
<description anonid="find-status" control="findbar-textbox" class="findbar-label findbar-find-status" />
@ -127,8 +121,6 @@
this._destroyed = false;
this._strBundle = null;
this._xulBrowserWindow = null;
// These elements are accessed frequently and are therefore cached.
@ -345,20 +337,14 @@
get browser() {
if (!this._browser) {
this._browser = document.getElementById(this.getAttribute("browserid"));
const id = this.getAttribute("browserid");
if (id) {
this._browser = document.getElementById(id);
}
}
return this._browser;
}
get strBundle() {
if (!this._strBundle) {
this._strBundle = Services.strings.createBundle(
"chrome://global/locale/findbar.properties"
);
}
return this._strBundle;
}
observe(subject, topic, prefName) {
if (topic == TOPIC_MAC_APP_ACTIVATE) {
this._onAppActivateMac();
@ -572,7 +558,10 @@
let statusLabel = this.getElement("match-case-status");
checkbox.checked = caseSensitive;
statusLabel.value = caseSensitive ? this._caseSensitiveStr : "";
document.l10n.setAttributes(
statusLabel,
caseSensitive ? "findbar-case-sensitive-status" : ""
);
// Show the checkbox on the full Find bar in non-auto mode.
// Show the label in all other cases.
@ -623,7 +612,10 @@
let statusLabel = this.getElement("match-diacritics-status");
checkbox.checked = matchDiacritics;
statusLabel.value = matchDiacritics ? this._matchDiacriticsStr : "";
document.l10n.setAttributes(
statusLabel,
matchDiacritics ? "findbar-match-diacritics-status" : ""
);
// Show the checkbox on the full Find bar in non-auto mode.
// Show the label in all other cases.
@ -665,7 +657,10 @@
let statusLabel = this.getElement("entire-word-status");
checkbox.checked = entireWord;
statusLabel.value = entireWord ? this._entireWordStr : "";
document.l10n.setAttributes(
statusLabel,
entireWord ? "findbar-entire-word-status" : ""
);
// Show the checkbox on the full Find bar in non-auto mode.
// Show the label in all other cases.
@ -710,19 +705,6 @@
this.findMode = mode;
}
if (!this._notFoundStr) {
var bundle = this.strBundle;
this._notFoundStr = bundle.GetStringFromName("NotFound");
this._wrappedToTopStr = bundle.GetStringFromName("WrappedToTop");
this._wrappedToBottomStr = bundle.GetStringFromName("WrappedToBottom");
this._normalFindStr = bundle.GetStringFromName("NormalFind");
this._fastFindStr = bundle.GetStringFromName("FastFind");
this._fastFindLinksStr = bundle.GetStringFromName("FastFindLinks");
this._caseSensitiveStr = bundle.GetStringFromName("CaseSensitive");
this._matchDiacriticsStr = bundle.GetStringFromName("MatchDiacritics");
this._entireWordStr = bundle.GetStringFromName("EntireWord");
}
this._findFailedString = null;
this._updateFindUI();
@ -966,13 +948,15 @@
this._findField.classList.remove("minimal");
}
let l10nId;
if (this.findMode == this.FIND_TYPEAHEAD) {
this._findField.placeholder = this._fastFindStr;
l10nId = "findbar-fast-find";
} else if (this.findMode == this.FIND_LINKS) {
this._findField.placeholder = this._fastFindLinksStr;
l10nId = "findbar-fast-find-links";
} else {
this._findField.placeholder = this._normalFindStr;
l10nId = "findbar-normal-find";
}
document.l10n.setAttributes(this._findField, l10nId);
}
_find(value) {
@ -1061,34 +1045,36 @@
}
_updateStatusUI(res, findPrevious) {
let statusL10nId;
switch (res) {
case Ci.nsITypeAheadFind.FIND_WRAPPED:
this._findStatusIcon.setAttribute("status", "wrapped");
this._findStatusDesc.textContent = findPrevious
? this._wrappedToBottomStr
: this._wrappedToTopStr;
this._findField.removeAttribute("status");
statusL10nId = findPrevious
? "findbar-wrapped-to-bottom"
: "findbar-wrapped-to-top";
break;
case Ci.nsITypeAheadFind.FIND_NOTFOUND:
this._findStatusDesc.setAttribute("status", "notfound");
this._findStatusIcon.setAttribute("status", "notfound");
this._findStatusDesc.textContent = this._notFoundStr;
this._findField.setAttribute("status", "notfound");
statusL10nId = "findbar-not-found";
break;
case Ci.nsITypeAheadFind.FIND_PENDING:
this._findStatusIcon.setAttribute("status", "pending");
this._findStatusDesc.textContent = "";
this._findField.removeAttribute("status");
this._findStatusDesc.removeAttribute("status");
statusL10nId = "";
break;
case Ci.nsITypeAheadFind.FIND_FOUND:
default:
this._findStatusIcon.removeAttribute("status");
this._findStatusDesc.textContent = "";
this._findField.removeAttribute("status");
this._findStatusDesc.removeAttribute("status");
statusL10nId = "";
break;
}
document.l10n.setAttributes(this._findStatusDesc, statusL10nId);
}
updateControlState(result, findPrevious) {
@ -1306,25 +1292,21 @@
* - {Number} current Vector of the current result.
*/
onMatchesCountResult(result) {
if (result.total !== 0) {
if (result.total == -1) {
this._foundMatches.value = LazyConstants.PluralForm.get(
result.limit,
this.strBundle.GetStringFromName("FoundMatchesCountLimit")
).replace("#1", result.limit);
} else {
this._foundMatches.value = LazyConstants.PluralForm.get(
result.total,
this.strBundle.GetStringFromName("FoundMatches")
)
.replace("#1", result.current)
.replace("#2", result.total);
}
this._foundMatches.hidden = false;
} else {
this._foundMatches.hidden = true;
this._foundMatches.value = "";
let l10nId;
switch (result.total) {
case 0:
l10nId = "";
this._foundMatches.hidden = true;
break;
case -1:
l10nId = "findbar-found-matches-count-limit";
this._foundMatches.hidden = false;
break;
default:
l10nId = "findbar-found-matches";
this._foundMatches.hidden = false;
}
document.l10n.setAttributes(this._foundMatches, l10nId, result);
}
onHighlightFinished(result) {

Просмотреть файл

@ -1,23 +0,0 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# strings used by the Find bar, split from browser.properties
NotFound=Phrase not found
WrappedToTop=Reached end of page, continued from top
WrappedToBottom=Reached top of page, continued from bottom
NormalFind=Find in page
FastFind=Quick find
FastFindLinks=Quick find (links only)
CaseSensitive=(Case sensitive)
MatchDiacritics=(Matching diacritics)
EntireWord=(Whole words only)
# LOCALIZATION NOTE (FoundMatches): Semicolon-separated list of plural forms.
# See: http://developer.mozilla.org/en/docs/Localization_and_Plurals
# #1 is currently selected match and #2 the total amount of matches.
FoundMatches=#1 of #2 match;#1 of #2 matches
# LOCALIZATION NOTE (FoundMatchesCountLimit): Semicolon-separated list of plural
# forms.
# See: http://developer.mozilla.org/en/docs/Localization_and_Plurals
# #1 is the total amount of matches allowed before counting stops.
FoundMatchesCountLimit=More than #1 match;More than #1 matches

Просмотреть файл

@ -34,3 +34,41 @@ findbar-entire-word =
.label = Whole Words
.accesskey = W
.tooltiptext = Search whole words only
findbar-not-found = Phrase not found
findbar-wrapped-to-top = Reached end of page, continued from top
findbar-wrapped-to-bottom = Reached top of page, continued from bottom
findbar-normal-find =
.placeholder = Find in page
findbar-fast-find =
.placeholder = Quick find
findbar-fast-find-links =
.placeholder = Quick find (links only)
findbar-case-sensitive-status =
.value = (Case sensitive)
findbar-match-diacritics-status =
.value = (Matching diacritics)
findbar-entire-word-status =
.value = (Whole words only)
# Variables:
# $current (Number): Index of the currently selected match
# $total (Number): Total count of matches
findbar-found-matches =
.value =
{ $total ->
[one] { $current } of { $total } match
*[other] { $current } of { $total } matches
}
# Variables:
# $limit (Number): Total count of matches allowed before counting stops
findbar-found-matches-count-limit =
.value =
{ $limit ->
[one] More than { $limit } match
*[other] More than { $limit } matches
}

Просмотреть файл

@ -21,9 +21,6 @@
locale/@AB_CD@/global/extensions.properties (%chrome/global/extensions.properties)
locale/@AB_CD@/global/fallbackMenubar.properties (%chrome/global/fallbackMenubar.properties)
locale/@AB_CD@/global/filepicker.properties (%chrome/global/filepicker.properties)
#ifndef MOZ_FENNEC
locale/@AB_CD@/global/findbar.properties (%chrome/global/findbar.properties)
#endif
locale/@AB_CD@/global/intl.css (%chrome/global/intl.css)
locale/@AB_CD@/global/intl.properties (%chrome/global/intl.properties)
locale/@AB_CD@/global/keys.properties (%chrome/global/keys.properties)