Skip to content

Commit 2da9eb9

Browse files
committed
refactor: update http-framework-i18n
BREAKING CHANGE: refactor: Updated `@skyra/http-framework-i18n` to `2.0.0` BREAKING CHANGE: refactor: Removed `LanguageKeys` in favour of `@skyra/i18next-type-generator` and `i18next` v23's enhanced type support
1 parent 2e39517 commit 2da9eb9

File tree

8 files changed

+37
-37
lines changed

8 files changed

+37
-37
lines changed

packages/shared-http-pieces/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ The shared commands used for ArchId Network's HTTP-only bots.
44

55
## Setup
66

7-
- Define `locales/{{lng}}/commands/shared:infoEmbedDescription` as a string. This is the content displayed in `/info`'s embed description.
7+
- Define `locales/{{lng}}/commands/shared:infoEmbedDescription` as a string. This is the content displayed in `/info`'s embed description, no augmentation is required for this key.
88
- Define the information variables.
99

1010
## Usage

packages/shared-http-pieces/src/commands/info.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { EmbedBuilder, time, TimestampStyles } from '@discordjs/builders';
22
import { Command, RegisterCommand } from '@skyra/http-framework';
3-
import { applyLocalizedBuilder, getSupportedUserLanguageT, type TFunction } from '@skyra/http-framework-i18n';
3+
import { applyLocalizedBuilder, getSupportedUserLanguageName, getT, type TFunction } from '@skyra/http-framework-i18n';
44
import {
55
ButtonStyle,
66
ComponentType,
@@ -10,16 +10,16 @@ import {
1010
type APIMessageActionRowComponent
1111
} from 'discord-api-types/v10';
1212
import { cpus, uptime, type CpuInfo } from 'node:os';
13-
import { LanguageKeys } from '../lib/i18n/LanguageKeys.js';
1413
import { getInvite, getRepository } from '../lib/information.js';
1514

1615
@RegisterCommand((builder) => applyLocalizedBuilder(builder, 'commands/shared:info'))
1716
export class UserCommand extends Command {
1817
public override chatInputRun(interaction: Command.ChatInputInteraction) {
19-
const t = getSupportedUserLanguageT(interaction);
18+
const lng = getSupportedUserLanguageName(interaction);
19+
const t = getT(lng);
2020
const embed = new EmbedBuilder()
21-
.setDescription(t(LanguageKeys.Commands.Shared.InfoEmbedDescription))
22-
.addFields(this.getUptimeStatistics(t), this.getServerUsageStatistics(t));
21+
.setDescription(t('commands/shared:infoEmbedDescription'))
22+
.addFields(this.getUptimeStatistics(t), this.getServerUsageStatistics(t, lng));
2323
const components = this.getComponents(t);
2424

2525
return interaction.reply({ embeds: [embed.toJSON()], components, flags: MessageFlags.Ephemeral });
@@ -30,23 +30,23 @@ export class UserCommand extends Command {
3030
const nowSeconds = Math.round(now / 1000);
3131

3232
return {
33-
name: t(LanguageKeys.Commands.Shared.InfoFieldUptimeTitle),
34-
value: t(LanguageKeys.Commands.Shared.InfoFieldUptimeValue, {
33+
name: t('commands/shared:infoFieldUptimeTitle'),
34+
value: t('commands/shared:infoFieldUptimeValue', {
3535
host: time(Math.round(nowSeconds - uptime()), TimestampStyles.RelativeTime),
3636
client: time(Math.round(nowSeconds - process.uptime()), TimestampStyles.RelativeTime)
3737
})
3838
};
3939
}
4040

41-
private getServerUsageStatistics(t: TFunction): APIEmbedField {
41+
private getServerUsageStatistics(t: TFunction, lng: string): APIEmbedField {
4242
const usage = process.memoryUsage();
4343

4444
return {
45-
name: t(LanguageKeys.Commands.Shared.InfoFieldServerUsageTitle),
46-
value: t(LanguageKeys.Commands.Shared.InfoFieldServerUsageValue, {
45+
name: t('commands/shared:infoFieldServerUsageTitle'),
46+
value: t('commands/shared:infoFieldServerUsageValue', {
4747
cpu: cpus().map(UserCommand.formatCpuInfo.bind(null)).join(' | '),
48-
heapUsed: (usage.heapUsed / 1048576).toLocaleString(t.lng, { maximumFractionDigits: 2 }),
49-
heapTotal: (usage.heapTotal / 1048576).toLocaleString(t.lng, { maximumFractionDigits: 2 })
48+
heapUsed: (usage.heapUsed / 1048576).toLocaleString(lng, { maximumFractionDigits: 2 }),
49+
heapTotal: (usage.heapTotal / 1048576).toLocaleString(lng, { maximumFractionDigits: 2 })
5050
})
5151
};
5252
}
@@ -71,7 +71,7 @@ export class UserCommand extends Command {
7171
return {
7272
type: ComponentType.Button,
7373
style: ButtonStyle.Link,
74-
label: t(LanguageKeys.Commands.Shared.InfoButtonSupport),
74+
label: t('commands/shared:infoButtonSupport'),
7575
emoji: { name: '🆘' },
7676
url: 'https://discord.gg/6gakFR2'
7777
};
@@ -81,7 +81,7 @@ export class UserCommand extends Command {
8181
return {
8282
type: ComponentType.Button,
8383
style: ButtonStyle.Link,
84-
label: t(LanguageKeys.Commands.Shared.InfoButtonInvite),
84+
label: t('commands/shared:infoButtonInvite'),
8585
emoji: { name: '🎉' },
8686
url
8787
};
@@ -91,7 +91,7 @@ export class UserCommand extends Command {
9191
return {
9292
type: ComponentType.Button,
9393
style: ButtonStyle.Link,
94-
label: t(LanguageKeys.Commands.Shared.InfoButtonGitHub),
94+
label: t('commands/shared:infoButtonGitHub'),
9595
emoji: { id: '950888087188283422', name: 'github2' },
9696
url: getRepository()
9797
};
@@ -101,7 +101,7 @@ export class UserCommand extends Command {
101101
return {
102102
type: ComponentType.Button,
103103
style: ButtonStyle.Link,
104-
label: t(LanguageKeys.Commands.Shared.InfoButtonDonate),
104+
label: t('commands/shared:infoButtonDonate'),
105105
emoji: { name: '🧡' },
106106
url: 'https://donate.skyra.pw'
107107
};

packages/shared-http-pieces/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@
22
/// <reference lib="dom" />
33

44
export * as Sentry from '@sentry/node';
5-
export * from './lib/i18n/LanguageKeys.js';
65
export * from './lib/information.js';
76
export * from './lib/sentry.js';

packages/shared-http-pieces/src/lib/i18n/LanguageKeys.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/shared-http-pieces/src/lib/i18n/LanguageKeys/All.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/shared-http-pieces/src/lib/i18n/LanguageKeys/Commands/All.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/shared-http-pieces/src/lib/i18n/LanguageKeys/Commands/Shared.ts

Lines changed: 0 additions & 16 deletions
This file was deleted.

packages/shared-http-pieces/src/register.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,23 @@ import { load } from '@skyra/http-framework-i18n';
33

44
container.stores.registerPath(new URL('.', import.meta.url));
55
await load(new URL('../src/locales', import.meta.url));
6+
7+
declare module 'i18next' {
8+
interface CustomTypeOptions {
9+
resources: {
10+
'commands/shared': {
11+
infoName: 'info';
12+
infoDescription: 'Provides information about me, and links for adding the bot and joining the support server';
13+
infoEmbedDescription: string;
14+
infoFieldUptimeTitle: 'Uptime';
15+
infoFieldUptimeValue: '• **Host**: {{host}}\n• **Client**: {{client}}';
16+
infoFieldServerUsageTitle: 'Server Usage';
17+
infoFieldServerUsageValue: '• **CPU Usage**: {{cpu}}\n• **Memory**: {{heapUsed}}MB (Total: {{heapTotal}}MB)';
18+
infoButtonInvite: 'Add me to your server!';
19+
infoButtonSupport: 'Support server';
20+
infoButtonGitHub: 'GitHub Repository';
21+
infoButtonDonate: 'Donate';
22+
};
23+
};
24+
}
25+
}

0 commit comments

Comments
 (0)