Skip to content

Commit

Permalink
fix(i18next): fixed type compatibility with latest i18next changes
Browse files Browse the repository at this point in the history
  • Loading branch information
favna committed Dec 17, 2022
1 parent d9bb344 commit 38367da
Show file tree
Hide file tree
Showing 4 changed files with 298 additions and 47 deletions.
2 changes: 1 addition & 1 deletion packages/i18next/package.json
Expand Up @@ -41,7 +41,7 @@
"@sapphire/utilities": "^3.11.0",
"@skyra/i18next-backend": "^2.0.1",
"chokidar": "^3.5.3",
"i18next": "^22.4.1",
"i18next": "^22.4.5",
"tslib": "^2.4.1"
},
"repository": {
Expand Down
14 changes: 7 additions & 7 deletions packages/i18next/src/lib/InternationalizationHandler.ts
Expand Up @@ -2,11 +2,11 @@ import { Result } from '@sapphire/framework';
import { container, getRootData } from '@sapphire/pieces';
import { Awaitable, isFunction, NonNullObject } from '@sapphire/utilities';
import { Backend, PathResolvable } from '@skyra/i18next-backend';
import i18next, { TFunction, TOptions } from 'i18next';
import i18next, { TFuncKey, TFunction, TOptions } from 'i18next';
import type { PathLike } from 'node:fs';
import { opendir } from 'node:fs/promises';
import { join } from 'node:path';
import type { InternationalizationContext, InternationalizationOptions, StringMap, TFunctionKeys, TFunctionResult } from './types';
import type { InternationalizationContext, InternationalizationOptions, StringMap, TFunctionResult } from './types';

/**
* A generalized class for handling `i18next` JSON files and their discovery.
Expand Down Expand Up @@ -178,11 +178,11 @@ export class InternationalizationHandler {
* @see {@link https://www.i18next.com/overview/api#t}
* @returns The localized content.
*/
public format<
TResult extends TFunctionResult = string,
TKeys extends TFunctionKeys = string,
TInterpolationMap extends NonNullObject = StringMap
>(locale: string, key: TKeys | TKeys[], options?: TOptions<TInterpolationMap>): TResult {
public format<TResult extends TFunctionResult = string, TKeys extends TFuncKey = string, TInterpolationMap extends NonNullObject = StringMap>(
locale: string,
key: TKeys | TKeys[],
options?: TOptions<TInterpolationMap>
): TResult {
if (!this.languagesLoaded) throw new Error('Cannot call this method until InternationalizationHandler#init has been called');

const language = this.languages.get(locale);
Expand Down
4 changes: 2 additions & 2 deletions packages/i18next/src/lib/functions.ts
Expand Up @@ -2,7 +2,7 @@ import { container } from '@sapphire/pieces';
import { lazy, type NonNullObject } from '@sapphire/utilities';
import { APIApplicationCommandOptionChoice, Locale, type LocaleString } from 'discord-api-types/v10';
import { BaseCommandInteraction, Guild, Message, MessageComponentInteraction } from 'discord.js';
import type { TOptions } from 'i18next';
import type { TFuncKey, TOptions } from 'i18next';
import type {
BuilderWithDescription,
BuilderWithName,
Expand Down Expand Up @@ -78,7 +78,7 @@ export async function fetchT(target: Target) {
*/
export async function resolveKey<
TResult extends TFunctionResult = string,
TKeys extends TFunctionKeys = string,
TKeys extends TFuncKey = string,
TInterpolationMap extends NonNullObject = StringMap
>(target: Target, key: TKeys | TKeys[], options?: TOptions<TInterpolationMap>): Promise<TResult> {
return container.i18n.format(typeof options?.lng === 'string' ? options.lng : await fetchLanguage(target), key, options);
Expand Down

0 comments on commit 38367da

Please sign in to comment.