File tree Expand file tree Collapse file tree 2 files changed +9
-6
lines changed
Expand file tree Collapse file tree 2 files changed +9
-6
lines changed Original file line number Diff line number Diff line change 11import type { Locale } from 'discord.js' ;
2- import { getI18n , type CommandLocalizationContext } from './i18n' ;
2+ import { useI18n , type CommandLocalizationContext } from './i18n' ;
33import {
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}
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ import CommandKit, {
1818 PreparedAppCommandExecution ,
1919 CommandBuilderLike ,
2020 CommandKitHMREvent ,
21+ getCommandKit ,
2122} from 'commandkit' ;
2223import FsBackend from 'i18next-fs-backend' ;
2324import { 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 ) {
You can’t perform that action at this time.
0 commit comments