Fix instances of double translation and guard translation calls using typescript (#11443)

Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
This commit is contained in:
Michael Telatynski 2023-08-22 16:32:05 +01:00 committed by GitHub
parent d13b6e1b41
commit ac70f7ac9b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
157 changed files with 554 additions and 780 deletions

View file

@ -24,7 +24,7 @@ import {
} from "matrix-js-sdk/src/matrix";
import { logger } from "matrix-js-sdk/src/logger";
import { _t, UserFriendlyError } from "../languageHandler";
import { _t, TranslationKey, UserFriendlyError } from "../languageHandler";
import SdkConfig from "../SdkConfig";
import { ValidatedServerConfig } from "./ValidatedServerConfig";
@ -104,21 +104,15 @@ export default class AutoDiscoveryUtils {
// don't make this easy to avoid.
if (pageName === "register") {
body = _t(
"You can register, but some features will be unavailable until the identity server is " +
"back online. If you keep seeing this warning, check your configuration or contact a server " +
"admin.",
"You can register, but some features will be unavailable until the identity server is back online. If you keep seeing this warning, check your configuration or contact a server admin.",
);
} else if (pageName === "reset_password") {
body = _t(
"You can reset your password, but some features will be unavailable until the identity " +
"server is back online. If you keep seeing this warning, check your configuration or contact " +
"a server admin.",
"You can reset your password, but some features will be unavailable until the identity server is back online. If you keep seeing this warning, check your configuration or contact a server admin.",
);
} else {
body = _t(
"You can log in, but some features will be unavailable until the identity server is " +
"back online. If you keep seeing this warning, check your configuration or contact a server " +
"admin.",
"You can log in, but some features will be unavailable until the identity server is back online. If you keep seeing this warning, check your configuration or contact a server admin.",
);
}
}
@ -223,7 +217,8 @@ export default class AutoDiscoveryUtils {
logger.error("Error determining preferred identity server URL:", isResult);
if (isResult.state === AutoDiscovery.FAIL_ERROR) {
if (AutoDiscovery.ALL_ERRORS.indexOf(isResult.error as string) !== -1) {
throw new UserFriendlyError(String(isResult.error));
// XXX: We mark these with _td at the top of Login.tsx - we should come up with a better solution
throw new UserFriendlyError(String(isResult.error) as TranslationKey);
}
throw new UserFriendlyError("Unexpected error resolving identity server configuration");
} // else the error is not related to syntax - continue anyways.
@ -239,7 +234,8 @@ export default class AutoDiscoveryUtils {
logger.error("Error processing homeserver config:", hsResult);
if (!syntaxOnly || !AutoDiscoveryUtils.isLivelinessError(hsResult.error)) {
if (AutoDiscovery.ALL_ERRORS.indexOf(hsResult.error as string) !== -1) {
throw new UserFriendlyError(String(hsResult.error));
// XXX: We mark these with _td at the top of Login.tsx - we should come up with a better solution
throw new UserFriendlyError(String(hsResult.error) as TranslationKey);
}
if (hsResult.error === AutoDiscovery.ERROR_HOMESERVER_TOO_OLD) {
throw new UserFriendlyError(

View file

@ -17,7 +17,7 @@ limitations under the License.
import React, { ReactNode } from "react";
import { MatrixError, ConnectionError } from "matrix-js-sdk/src/matrix";
import { _t, _td, Tags, TranslatedString } from "../languageHandler";
import { _t, _td, Tags, TranslatedString, TranslationKey } from "../languageHandler";
import SdkConfig from "../SdkConfig";
import { ValidatedServerConfig } from "./ValidatedServerConfig";
import ExternalLink from "../components/views/elements/ExternalLink";
@ -49,7 +49,7 @@ export const adminContactStrings = {
export function messageForResourceLimitError(
limitType: string | undefined,
adminContact: string | undefined,
strings: Record<string, string>,
strings: Record<string, TranslationKey>,
extraTranslations?: Tags,
): TranslatedString {
let errString = limitType ? strings[limitType] : undefined;
@ -154,8 +154,7 @@ export function messageForConnectionError(
return (
<span>
{_t(
"Can't connect to homeserver via HTTP when an HTTPS URL is in your browser bar. " +
"Either use HTTPS or <a>enable unsafe scripts</a>.",
"Can't connect to homeserver via HTTP when an HTTPS URL is in your browser bar. Either use HTTPS or <a>enable unsafe scripts</a>.",
{},
{
a: (sub) => {
@ -178,9 +177,7 @@ export function messageForConnectionError(
return (
<span>
{_t(
"Can't connect to homeserver - please check your connectivity, ensure your " +
"<a>homeserver's SSL certificate</a> is trusted, and that a browser extension " +
"is not blocking requests.",
"Can't connect to homeserver - please check your connectivity, ensure your <a>homeserver's SSL certificate</a> is trusted, and that a browser extension is not blocking requests.",
{},
{
a: (sub) => (

View file

@ -308,8 +308,7 @@ export default class MultiInviter {
case "ORG.MATRIX.JSSDK_MISSING_PARAM":
if (getAddressType(address) === AddressType.Email) {
errorText = _t(
"Cannot invite user by email without an identity server. " +
'You can connect to one under "Settings".',
'Cannot invite user by email without an identity server. You can connect to one under "Settings".',
);
}
}

View file

@ -17,7 +17,7 @@ limitations under the License.
import zxcvbn, { ZXCVBNFeedbackWarning } from "zxcvbn";
import { MatrixClient } from "matrix-js-sdk/src/matrix";
import { _t, _td } from "../languageHandler";
import { _t, _td, TranslationKey } from "../languageHandler";
import { MatrixClientPeg } from "../MatrixClientPeg";
const ZXCVBN_USER_INPUTS = ["riot", "matrix"];
@ -90,8 +90,9 @@ export function scorePassword(
}
for (let i = 0; i < zxcvbnResult.feedback.suggestions.length; ++i) {
// translate suggestions
zxcvbnResult.feedback.suggestions[i] = _t(zxcvbnResult.feedback.suggestions[i]);
// translate suggestions - we ensure we mark them as `_td` at the top of this file
// https://github.com/dropbox/zxcvbn/issues/284 will be a better approach when it lands
zxcvbnResult.feedback.suggestions[i] = _t(zxcvbnResult.feedback.suggestions[i] as TranslationKey);
}
// and warning, if any
if (zxcvbnResult.feedback.warning) {

View file

@ -135,8 +135,7 @@ export async function leaveRoomBehaviour(
Modal.createDialog(ErrorDialog, {
title: _t("Can't leave Server Notices room"),
description: _t(
"This room is used for important messages from the Homeserver, " +
"so you cannot leave it.",
"This room is used for important messages from the Homeserver, so you cannot leave it.",
),
});
return;

View file

@ -32,8 +32,7 @@ export const getLocationShareErrorMessage = (errorType?: LocationShareError): st
case LocationShareError.MapStyleUrlNotReachable:
default:
return _t(
`This homeserver is not configured correctly to display maps, ` +
`or the configured map server may be unreachable.`,
"This homeserver is not configured correctly to display maps, or the configured map server may be unreachable.",
);
}
};

View file

@ -27,8 +27,7 @@ export const positionFailureMessage = (code: number): string | undefined => {
switch (code) {
case 1:
return _t(
"%(brand)s was denied permission to fetch your location. " +
"Please allow location access in your browser settings.",
"%(brand)s was denied permission to fetch your location. Please allow location access in your browser settings.",
{ brand },
);
case 2: