Skip to content

Commit 205b2cf

Browse files
committed
refactor: rename getI18n to useI18n and update usage in hooks for improved clarity
1 parent 18d66ce commit 205b2cf

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

packages/i18n/src/hooks.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Locale } from 'discord.js';
2-
import { getI18n, type CommandLocalizationContext } from './i18n';
2+
import { useI18n, type CommandLocalizationContext } from './i18n';
33
import {
44
useEnvironment,
55
eventWorkerContext,
@@ -29,7 +29,7 @@ export function locale(locale?: Locale): CommandLocalizationContext {
2929

3030
const commandkit = context.commandkit;
3131

32-
const i18n = getI18n(commandkit);
32+
const i18n = useI18n(commandkit);
3333
const detectedLocale: Locale = locale || commandkit.config.defaultLocale;
3434

3535
return {
@@ -64,5 +64,5 @@ export function fetchT(
6464
ns?: string | null,
6565
keyPrefix?: string,
6666
): TFunction {
67-
return locale().i18n.getFixedT(lng, ns, keyPrefix);
67+
return useI18n().getFixedT(lng, ns, keyPrefix);
6868
}

packages/i18n/src/i18n.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import CommandKit, {
1818
PreparedAppCommandExecution,
1919
CommandBuilderLike,
2020
CommandKitHMREvent,
21+
getCommandKit,
2122
} from 'commandkit';
2223
import FsBackend from 'i18next-fs-backend';
2324
import { basename, extname, join } from 'path';
@@ -124,16 +125,18 @@ NativeContext.prototype.locale = function (locale?: Locale) {
124125
* @throws Error if the i18n instance is not found in the store.
125126
* @example
126127
* ```ts
127-
* import { getI18n } from '@commandkit/i18n';
128+
* import { useI18n } from '@commandkit/i18n';
128129
* import { commandkit } from 'commandkit';
129130
*
130-
* const i18n = getI18n(commandkit);
131+
* const i18n = useI18n(commandkit);
131132
*
132133
* // Use the i18n instance
133134
* i18n.t('key');
134135
* ```
135136
*/
136-
export function getI18n(commandkit: CommandKit): i18n {
137+
export function useI18n(commandkit?: CommandKit): i18n {
138+
commandkit ??= getCommandKit(true);
139+
137140
const i18n = commandkit.store.get('i18n:plugin:instance') as i18n;
138141

139142
if (!i18n) {

0 commit comments

Comments
 (0)