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 1
1
import type { Locale } from 'discord.js' ;
2
- import { getI18n , type CommandLocalizationContext } from './i18n' ;
2
+ import { useI18n , type CommandLocalizationContext } from './i18n' ;
3
3
import {
4
4
useEnvironment ,
5
5
eventWorkerContext ,
@@ -29,7 +29,7 @@ export function locale(locale?: Locale): CommandLocalizationContext {
29
29
30
30
const commandkit = context . commandkit ;
31
31
32
- const i18n = getI18n ( commandkit ) ;
32
+ const i18n = useI18n ( commandkit ) ;
33
33
const detectedLocale : Locale = locale || commandkit . config . defaultLocale ;
34
34
35
35
return {
@@ -64,5 +64,5 @@ export function fetchT(
64
64
ns ?: string | null ,
65
65
keyPrefix ?: string ,
66
66
) : TFunction {
67
- return locale ( ) . i18n . getFixedT ( lng , ns , keyPrefix ) ;
67
+ return useI18n ( ) . getFixedT ( lng , ns , keyPrefix ) ;
68
68
}
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ import CommandKit, {
18
18
PreparedAppCommandExecution ,
19
19
CommandBuilderLike ,
20
20
CommandKitHMREvent ,
21
+ getCommandKit ,
21
22
} from 'commandkit' ;
22
23
import FsBackend from 'i18next-fs-backend' ;
23
24
import { basename , extname , join } from 'path' ;
@@ -124,16 +125,18 @@ NativeContext.prototype.locale = function (locale?: Locale) {
124
125
* @throws Error if the i18n instance is not found in the store.
125
126
* @example
126
127
* ```ts
127
- * import { getI18n } from '@commandkit/i18n';
128
+ * import { useI18n } from '@commandkit/i18n';
128
129
* import { commandkit } from 'commandkit';
129
130
*
130
- * const i18n = getI18n (commandkit);
131
+ * const i18n = useI18n (commandkit);
131
132
*
132
133
* // Use the i18n instance
133
134
* i18n.t('key');
134
135
* ```
135
136
*/
136
- export function getI18n ( commandkit : CommandKit ) : i18n {
137
+ export function useI18n ( commandkit ?: CommandKit ) : i18n {
138
+ commandkit ??= getCommandKit ( true ) ;
139
+
137
140
const i18n = commandkit . store . get ( 'i18n:plugin:instance' ) as i18n ;
138
141
139
142
if ( ! i18n ) {
You can’t perform that action at this time.
0 commit comments