Skip to content

Commit b147352

Browse files
committed
fix: update i18n plugin
1 parent 49a513b commit b147352

File tree

10 files changed

+258
-262
lines changed

10 files changed

+258
-262
lines changed

packages/commandkit/src/cli/development.ts

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const isEventSource = (p: string) =>
3636
p.replaceAll('\\', '/').includes('src/app/events');
3737

3838
export async function bootstrapDevelopmentServer(configPath?: string) {
39+
process.env.COMMANDKIT_BOOTSTRAP_MODE = 'development';
3940
const start = performance.now();
4041
const cwd = configPath || process.cwd();
4142
const configPaths = getPossibleConfigPaths(cwd);

packages/commandkit/src/cli/production.ts

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { isCompilerPlugin } from '../plugins';
88
import { createSpinner } from './utils';
99

1010
export async function bootstrapProductionServer(configPath?: string) {
11+
process.env.COMMANDKIT_BOOTSTRAP_MODE = 'production';
1112
const cwd = configPath || process.cwd();
1213
const config = await loadConfigFile(cwd);
1314
const mainFile = join(config.distDir, 'index.js');
@@ -22,6 +23,7 @@ export async function bootstrapProductionServer(configPath?: string) {
2223
}
2324

2425
export async function createProductionBuild(configPath?: string) {
26+
process.env.COMMANDKIT_BOOTSTRAP_MODE = 'production';
2527
const cwd = configPath || process.cwd();
2628
const config = await loadConfigFile(cwd);
2729

packages/commandkit/src/utils/constants.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
export const COMMANDKIT_CACHE_TAG = Symbol('kCommandKitCacheTag');
22

3-
export const COMMANDKIT_IS_DEV = !!process.env.COMMANDKIT_IS_DEV;
3+
export const COMMANDKIT_IS_DEV = process.env.COMMANDKIT_IS_DEV === 'true';
44

55
export const COMMANDKIT_IS_TEST = process.env.COMMANDKIT_IS_TEST === 'true';
66

7+
export const COMMANDKIT_BOOTSTRAP_MODE = (process.env
8+
.COMMANDKIT_BOOTSTRAP_MODE || 'development') as 'development' | 'production';
9+
710
/**
811
* Types of Hot Module Replacement events
912
*/

packages/i18n/src/constants.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { Locale } from 'discord.js';
2+
3+
export const DISCORD_LOCALES = new Set(
4+
Object.values(Locale).filter((locale) => !/^\d+/.test(locale)),
5+
);
6+
7+
export const COMMAND_METADATA_KEY = '$command';

packages/i18n/src/hooks.ts

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import type { Locale } from 'discord.js';
2+
import type { CommandLocalizationContext } from './i18n';
3+
import { useEnvironment } from 'commandkit';
4+
5+
/**
6+
* Gets the localization context.
7+
* @param locale The locale to use. Defaults to the detected locale or the default locale.
8+
*/
9+
export function locale(locale?: Locale): CommandLocalizationContext {
10+
const env = useEnvironment();
11+
const context = env.context;
12+
13+
if (!context) {
14+
throw new Error('No localization context found');
15+
}
16+
17+
return context.locale(locale);
18+
}

0 commit comments

Comments
 (0)