mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-23 12:51:06 +00:00
Bug 1733498 - Migrate necko errors l10n strings from properties to Fluent r=necko-reviewers,valentin,flod
Differential Revision: https://phabricator.services.mozilla.com/D136612
This commit is contained in:
parent
42485afae5
commit
f75f7b7494
18
netwerk/locales/en-US/necko.ftl
Normal file
18
netwerk/locales/en-US/necko.ftl
Normal file
@ -0,0 +1,18 @@
|
||||
# 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/.
|
||||
|
||||
## Variables:
|
||||
## $host (String): A website host address
|
||||
|
||||
network-connection-status-looking-up = Looking up { $host }…
|
||||
network-connection-status-connected = Connected to { $host }…
|
||||
network-connection-status-sending-request = Sending request to { $host }…
|
||||
network-connection-status-transferring-data = Transferring data from { $host }…
|
||||
network-connection-status-connecting = Connecting to { $host }…
|
||||
network-connection-status-read = Read { $host }
|
||||
network-connection-status-wrote = Wrote { $host }
|
||||
network-connection-status-waiting = Waiting for { $host }…
|
||||
network-connection-status-looked-up = Looked up { $host }…
|
||||
network-connection-status-tls-handshake = Performing a TLS handshake to { $host }…
|
||||
network-connection-status-tls-handshake-finished = The TLS handshake finished for { $host }…
|
@ -2,18 +2,6 @@
|
||||
# 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/.
|
||||
|
||||
3=Looking up %1$S…
|
||||
4=Connected to %1$S…
|
||||
5=Sending request to %1$S…
|
||||
6=Transferring data from %1$S…
|
||||
7=Connecting to %1$S…
|
||||
8=Read %1$S
|
||||
9=Wrote %1$S
|
||||
10=Waiting for %1$S…
|
||||
11=Looked up %1$S…
|
||||
12=Performing a TLS handshake to %1$S…
|
||||
13=The TLS handshake finished for %1$S…
|
||||
|
||||
RepostFormData=This web page is being redirected to a new location. Would you like to resend the form data you have typed to the new location?
|
||||
|
||||
# Directory listing strings
|
||||
|
@ -3,6 +3,8 @@
|
||||
# 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/.
|
||||
|
||||
[localization] @AB_CD@.jar:
|
||||
netwerk/necko.ftl (%necko.ftl)
|
||||
|
||||
@AB_CD@.jar:
|
||||
% locale necko @AB_CD@ %locale/@AB_CD@/necko/
|
||||
|
63
python/l10n/fluent_migrations/bug_1733498_necko.py
Normal file
63
python/l10n/fluent_migrations/bug_1733498_necko.py
Normal file
@ -0,0 +1,63 @@
|
||||
# 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 REPLACE
|
||||
|
||||
|
||||
def migrate(ctx):
|
||||
"""Bug 1733498 - Convert necko.properties to Fluent, part {index}."""
|
||||
|
||||
source = "netwerk/necko.properties"
|
||||
target = "netwerk/necko.ftl"
|
||||
ctx.add_transforms(
|
||||
target,
|
||||
target,
|
||||
[
|
||||
FTL.Message(
|
||||
id=FTL.Identifier("network-connection-status-looking-up"),
|
||||
value=REPLACE(source, "3", {"%1$S": VARIABLE_REFERENCE("host")}),
|
||||
),
|
||||
FTL.Message(
|
||||
id=FTL.Identifier("network-connection-status-connected"),
|
||||
value=REPLACE(source, "4", {"%1$S": VARIABLE_REFERENCE("host")}),
|
||||
),
|
||||
FTL.Message(
|
||||
id=FTL.Identifier("network-connection-status-sending-request"),
|
||||
value=REPLACE(source, "5", {"%1$S": VARIABLE_REFERENCE("host")}),
|
||||
),
|
||||
FTL.Message(
|
||||
id=FTL.Identifier("network-connection-status-transferring-data"),
|
||||
value=REPLACE(source, "6", {"%1$S": VARIABLE_REFERENCE("host")}),
|
||||
),
|
||||
FTL.Message(
|
||||
id=FTL.Identifier("network-connection-status-connecting"),
|
||||
value=REPLACE(source, "7", {"%1$S": VARIABLE_REFERENCE("host")}),
|
||||
),
|
||||
FTL.Message(
|
||||
id=FTL.Identifier("network-connection-status-read"),
|
||||
value=REPLACE(source, "8", {"%1$S": VARIABLE_REFERENCE("host")}),
|
||||
),
|
||||
FTL.Message(
|
||||
id=FTL.Identifier("network-connection-status-wrote"),
|
||||
value=REPLACE(source, "9", {"%1$S": VARIABLE_REFERENCE("host")}),
|
||||
),
|
||||
FTL.Message(
|
||||
id=FTL.Identifier("network-connection-status-waiting"),
|
||||
value=REPLACE(source, "10", {"%1$S": VARIABLE_REFERENCE("host")}),
|
||||
),
|
||||
FTL.Message(
|
||||
id=FTL.Identifier("network-connection-status-looked-up"),
|
||||
value=REPLACE(source, "11", {"%1$S": VARIABLE_REFERENCE("host")}),
|
||||
),
|
||||
FTL.Message(
|
||||
id=FTL.Identifier("network-connection-status-tls-handshake"),
|
||||
value=REPLACE(source, "12", {"%1$S": VARIABLE_REFERENCE("host")}),
|
||||
),
|
||||
FTL.Message(
|
||||
id=FTL.Identifier("network-connection-status-tls-handshake-finished"),
|
||||
value=REPLACE(source, "13", {"%1$S": VARIABLE_REFERENCE("host")}),
|
||||
),
|
||||
],
|
||||
)
|
@ -1201,11 +1201,11 @@ NS_IMETHODIMP nsDocLoader::OnStatus(nsIRequest* aRequest, nsresult aStatus,
|
||||
}
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIStringBundleService> sbs =
|
||||
mozilla::components::StringBundle::Service();
|
||||
if (!sbs) return NS_ERROR_FAILURE;
|
||||
nsAutoString host;
|
||||
host.Append(aStatusArg);
|
||||
|
||||
nsAutoString msg;
|
||||
nsresult rv = sbs->FormatStatusMessage(aStatus, aStatusArg, msg);
|
||||
nsresult rv = FormatStatusMessage(aStatus, host, msg);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// Keep around the message. In case a request finishes, we need to make sure
|
||||
@ -1240,6 +1240,76 @@ void nsDocLoader::ClearInternalProgress() {
|
||||
mProgressStateFlags = nsIWebProgressListener::STATE_STOP;
|
||||
}
|
||||
|
||||
/* static */
|
||||
mozilla::Maybe<nsLiteralCString> nsDocLoader::StatusCodeToL10nId(
|
||||
nsresult aStatus) {
|
||||
switch (aStatus) {
|
||||
case NS_NET_STATUS_WRITING:
|
||||
return mozilla::Some("network-connection-status-wrote"_ns);
|
||||
case NS_NET_STATUS_READING:
|
||||
return mozilla::Some("network-connection-status-read"_ns);
|
||||
case NS_NET_STATUS_RESOLVING_HOST:
|
||||
return mozilla::Some("network-connection-status-looking-up"_ns);
|
||||
case NS_NET_STATUS_RESOLVED_HOST:
|
||||
return mozilla::Some("network-connection-status-looked-up"_ns);
|
||||
case NS_NET_STATUS_CONNECTING_TO:
|
||||
return mozilla::Some("network-connection-status-connecting"_ns);
|
||||
case NS_NET_STATUS_CONNECTED_TO:
|
||||
return mozilla::Some("network-connection-status-connected"_ns);
|
||||
case NS_NET_STATUS_TLS_HANDSHAKE_STARTING:
|
||||
return mozilla::Some("network-connection-status-tls-handshake"_ns);
|
||||
case NS_NET_STATUS_TLS_HANDSHAKE_ENDED:
|
||||
return mozilla::Some(
|
||||
"network-connection-status-tls-handshake-finished"_ns);
|
||||
case NS_NET_STATUS_SENDING_TO:
|
||||
return mozilla::Some("network-connection-status-sending-request"_ns);
|
||||
case NS_NET_STATUS_WAITING_FOR:
|
||||
return mozilla::Some("network-connection-status-waiting"_ns);
|
||||
case NS_NET_STATUS_RECEIVING_FROM:
|
||||
return mozilla::Some("network-connection-status-transferring-data"_ns);
|
||||
default:
|
||||
return mozilla::Nothing();
|
||||
}
|
||||
}
|
||||
|
||||
nsresult nsDocLoader::FormatStatusMessage(nsresult aStatus,
|
||||
const nsAString& aHost,
|
||||
nsAString& aRetVal) {
|
||||
auto l10nId = StatusCodeToL10nId(aStatus);
|
||||
|
||||
if (!l10nId) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsAutoCString RetVal;
|
||||
ErrorResult rv;
|
||||
auto l10nArgs = dom::Optional<intl::L10nArgs>();
|
||||
l10nArgs.Construct();
|
||||
|
||||
auto dirArg = l10nArgs.Value().Entries().AppendElement();
|
||||
dirArg->mKey = "host";
|
||||
dirArg->mValue.SetValue().SetAsUTF8String().Assign(
|
||||
NS_ConvertUTF16toUTF8(aHost));
|
||||
|
||||
// Handle mL10n (necko.ftl) on demand
|
||||
if (!mL10n) {
|
||||
nsTArray<nsCString> resIds = {
|
||||
"netwerk/necko.ftl"_ns,
|
||||
};
|
||||
mL10n = mozilla::intl::Localization::Create(resIds, true);
|
||||
}
|
||||
MOZ_LOG(gDocLoaderLog, LogLevel::Debug,
|
||||
("DocLoader:%p: FormatStatusMessage, [mL10n=%d]\n", this, !!mL10n));
|
||||
MOZ_RELEASE_ASSERT(mL10n);
|
||||
|
||||
mL10n->FormatValueSync(*l10nId, l10nArgs, RetVal, rv);
|
||||
aRetVal = NS_ConvertUTF8toUTF16(RetVal);
|
||||
if (rv.Failed()) {
|
||||
return rv.StealNSResult();
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* |_code| is executed for every listener matching |_flag|
|
||||
* |listener| should be used inside |_code| as the nsIWebProgressListener var.
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "nsCOMPtr.h"
|
||||
#include "PLDHashTable.h"
|
||||
#include "nsCycleCollectionParticipant.h"
|
||||
#include "mozilla/intl/Localization.h"
|
||||
|
||||
#include "mozilla/LinkedList.h"
|
||||
#include "mozilla/UniquePtr.h"
|
||||
@ -362,6 +363,11 @@ class nsDocLoader : public nsIDocumentLoader,
|
||||
bool IsBlockingLoadEvent() const {
|
||||
return mIsLoadingDocument || mDocumentOpenedButNotLoaded;
|
||||
}
|
||||
|
||||
RefPtr<mozilla::intl::Localization> mL10n;
|
||||
static mozilla::Maybe<nsLiteralCString> StatusCodeToL10nId(nsresult aStatus);
|
||||
nsresult FormatStatusMessage(nsresult aStatus, const nsAString& aHost,
|
||||
nsAString& aRetVal);
|
||||
};
|
||||
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(nsDocLoader, NS_THIS_DOCLOADER_IMPL_CID)
|
||||
|
Loading…
Reference in New Issue
Block a user