Skip to content

Commit f16b49e

Browse files
committed
i18n: Clean up language loading
1 parent b0b65d0 commit f16b49e

3 files changed

Lines changed: 14 additions & 3 deletions

File tree

src/i18n/language.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { PSRoomConfigs } from '@/cache';
2+
3+
import type { Language } from '@/i18n/index';
4+
import type { Room, User } from 'ps-client';
5+
6+
export function getLanguage(target: Room | User | undefined): Language | undefined {
7+
if (!target) return;
8+
if ('userid' in target) return;
9+
return PSRoomConfigs[target.id]?.language;
10+
}

src/ps/handlers/commands/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { PSRoomConfigs } from '@/cache';
21
import { prefix } from '@/config/ps';
32
import { LanguageMap, i18n } from '@/i18n';
3+
import { getLanguage } from '@/i18n/language';
44
import { LivePSStuff } from '@/sentinel/live';
55
import { ChatError } from '@/utils/chatError';
66
import { Logger } from '@/utils/logger';
@@ -43,7 +43,7 @@ export async function commandHandler(message: PSMessage, indirect: IndirectCtx |
4343
};
4444

4545
const argData = messageContent.substring(prefix.length);
46-
let language = message.type === 'chat' ? PSRoomConfigs[message.target.id]?.language : undefined;
46+
let language = getLanguage(message.target);
4747
if (language && !LanguageMap[language]) {
4848
language = undefined;
4949
message.privateReply(`Could not find translations for ${language}.`);

src/ps/handlers/tours.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { ANNOUNCEMENTS_CHANNEL, ROLES } from '@/discord/constants/servers/petmod
77
import { getChannel } from '@/discord/loaders/channels';
88
import { IS_ENABLED } from '@/enabled';
99
import { i18n } from '@/i18n';
10+
import { getLanguage } from '@/i18n/language';
1011
import { TimeZone } from '@/ps/handlers/cron/constants';
1112
import getSecretFunction from '@/secrets/functions';
1213
import { toId } from '@/tools';
@@ -134,7 +135,7 @@ export function tourHandler(this: Client, roomId: string, line: string, isIntro?
134135
target: room,
135136
parent: this,
136137
};
137-
const $T = i18n(); // TODO: Use language pref
138+
const $T = i18n(getLanguage(room));
138139
const partialContext: Partial<PSCommandContext> = {
139140
args: [],
140141
message: partialMessage as PSMessage,

0 commit comments

Comments
 (0)