Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit ac05a8e

Browse files
committed
Translate the rest of the errors
1 parent cd17889 commit ac05a8e

File tree

1 file changed

+41
-14
lines changed

1 file changed

+41
-14
lines changed

src/SlashCommands.tsx

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,25 @@ export class Command {
141141

142142
run(roomId: string, threadId: string, args: string) {
143143
// if it has no runFn then its an ignored/nop command (autocomplete only) e.g `/me`
144-
if (!this.runFn) return reject(_t("Command error"));
144+
if (!this.runFn) {
145+
return reject(
146+
newTranslatableError(
147+
"Command error: This command should have been handled by another handler and we" +
148+
" can't try to run something without a command function.",
149+
),
150+
);
151+
}
145152

146153
const renderingType = threadId
147154
? TimelineRenderingType.Thread
148155
: TimelineRenderingType.Room;
149156
if (this.renderingTypes && !this.renderingTypes?.includes(renderingType)) {
150-
return reject(_t("Command error"));
157+
return reject(
158+
newTranslatableError(
159+
"Command error: Unable to find rendering type (%(renderingType)s)",
160+
{ renderingType },
161+
),
162+
);
151163
}
152164

153165
return this.runFn.bind(this)(roomId, args);
@@ -270,7 +282,9 @@ export const Commands = [
270282
const cli = MatrixClientPeg.get();
271283
const room = cli.getRoom(roomId);
272284
if (!room.currentState.mayClientSendStateEvent("m.room.tombstone", cli)) {
273-
return reject(_t("You do not have the required permissions to use this command."));
285+
return reject(
286+
newTranslatableError("You do not have the required permissions to use this command."),
287+
);
274288
}
275289

276290
const { finished } = Modal.createTrackedDialog('Slash Commands', 'upgrade room confirmation',
@@ -432,7 +446,7 @@ export const Commands = [
432446
return success(cli.setRoomTopic(roomId, args));
433447
}
434448
const room = cli.getRoom(roomId);
435-
if (!room) return reject(_t("Failed to set topic"));
449+
if (!room) return reject(newTranslatableError("Failed to set topic"));
436450

437451
const topicEvents = room.currentState.getStateEvents('m.room.topic', '');
438452
const topic = topicEvents && topicEvents.getContent().topic;
@@ -681,7 +695,14 @@ export const Commands = [
681695
}
682696
if (targetRoomId) break;
683697
}
684-
if (!targetRoomId) return reject(_t('Unrecognised room address:') + ' ' + roomAlias);
698+
if (!targetRoomId) {
699+
return reject(
700+
newTranslatableError(
701+
'Unrecognised room address: %(roomAlias)s',
702+
{ roomAlias },
703+
),
704+
);
705+
}
685706
}
686707
}
687708

@@ -820,10 +841,10 @@ export const Commands = [
820841
if (!isNaN(powerLevel)) {
821842
const cli = MatrixClientPeg.get();
822843
const room = cli.getRoom(roomId);
823-
if (!room) return reject(_t("Command failed"));
844+
if (!room) return reject(newTranslatableError("Command failed"));
824845
const member = room.getMember(userId);
825846
if (!member || getEffectiveMembership(member.membership) === EffectiveMembership.Leave) {
826-
return reject(_t("Could not find user in room"));
847+
return reject(newTranslatableError("Could not find user in room"));
827848
}
828849
const powerLevelEvent = room.currentState.getStateEvents('m.room.power_levels', '');
829850
return success(cli.setPowerLevel(roomId, userId, powerLevel, powerLevelEvent));
@@ -850,10 +871,16 @@ export const Commands = [
850871
if (matches) {
851872
const cli = MatrixClientPeg.get();
852873
const room = cli.getRoom(roomId);
853-
if (!room) return reject(_t("Command failed"));
874+
if (!room) {
875+
return reject(
876+
newTranslatableError("Command failed: Unable to find room (%(roomId)s", { roomId }),
877+
);
878+
}
854879

855880
const powerLevelEvent = room.currentState.getStateEvents('m.room.power_levels', '');
856-
if (!powerLevelEvent.getContent().users[args]) return reject(_t("Could not find user in room"));
881+
if (!powerLevelEvent.getContent().users[args]) {
882+
return reject(newTranslatableError("Could not find user in room"));
883+
}
857884
return success(cli.setPowerLevel(roomId, args, undefined, powerLevelEvent));
858885
}
859886
}
@@ -878,7 +905,7 @@ export const Commands = [
878905
isEnabled: () => SettingsStore.getValue(UIFeature.Widgets),
879906
runFn: function(roomId, widgetUrl) {
880907
if (!widgetUrl) {
881-
return reject(_t("Please supply a widget URL or embed code"));
908+
return reject(newTranslatableError("Please supply a widget URL or embed code"));
882909
}
883910

884911
// Try and parse out a widget URL from iframes
@@ -897,7 +924,7 @@ export const Commands = [
897924
}
898925

899926
if (!widgetUrl.startsWith("https://") && !widgetUrl.startsWith("http://")) {
900-
return reject(_t("Please supply a https:// or http:// widget URL"));
927+
return reject(newTranslatableError("Please supply a https:// or http:// widget URL"));
901928
}
902929
if (WidgetUtils.canUserModifyWidgets(roomId)) {
903930
const userId = MatrixClientPeg.get().getUserId();
@@ -919,7 +946,7 @@ export const Commands = [
919946

920947
return success(WidgetUtils.setRoomWidget(roomId, widgetId, type, widgetUrl, name, data));
921948
} else {
922-
return reject(_t("You cannot modify widgets in this room."));
949+
return reject(newTranslatableError("You cannot modify widgets in this room."));
923950
}
924951
},
925952
category: CommandCategories.admin,
@@ -1140,7 +1167,7 @@ export const Commands = [
11401167
runFn: function(roomId, args) {
11411168
const call = CallHandler.instance.getCallForRoom(roomId);
11421169
if (!call) {
1143-
return reject("No active call in this room");
1170+
return reject(newTranslatableError("No active call in this room"));
11441171
}
11451172
call.setRemoteOnHold(true);
11461173
return success();
@@ -1154,7 +1181,7 @@ export const Commands = [
11541181
runFn: function(roomId, args) {
11551182
const call = CallHandler.instance.getCallForRoom(roomId);
11561183
if (!call) {
1157-
return reject("No active call in this room");
1184+
return reject(newTranslatableError("No active call in this room"));
11581185
}
11591186
call.setRemoteOnHold(false);
11601187
return success();

0 commit comments

Comments
 (0)