-
-
Notifications
You must be signed in to change notification settings - Fork 655
introduce returnResolved t option that pratically exposes the result of the resolve function #1764
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…of the resolve function
@pedrodurek ok for the types? Or is there a clash when using also |
hey @adrai, it's good enough 😄 , nice job! |
@pedrodurek can't we change the return type based on the returnResolved option? Something like: /**
* Object returned from t() function when passed returnResolved: true option.
*/
export type ResolvedResult = {
usedKey: string;
res: TFunctionResult;
exactUsedKey: string,
usedLng: string,
usedNS: string,
};
export type TFunctionResult = string | object | ResolvedResult | Array<string | object> | undefined | null;
export type TFunctionKeys = string | TemplateStringsArray;
export interface TFunction {
// basic usage
<
TReturnResolved extends boolean | undefined,
TResult extends TFunctionResult = TReturnResolved extends true ? ResolvedResult : string,
TKeys extends TFunctionKeys = string,
TInterpolationMap extends object = StringMap & { returnResolved?: TReturnResolved },
>(
key: TKeys | TKeys[],
options?: TOptions<TInterpolationMap> | string,
): TResult; This will for sure not work, because I've no clue of TypeScript, but just to give you the idea of what I'm asking for... basically if returnResolved is passed with true, the ResolvedResult type should be returned, else the string type... |
I think I got it: cf5bc34 |
@pedrodurek I've also tried with the returnObjects case: 5eaec77 Can you check if this is ok or if I messed up everything? |
Thank you for your proposal! Looks great!
|
Is it already possible to configure |
no, this is not a global option yet... I don't think this makes sense to make this a global option, right? |
I'm a bit inclined to say that it could make sense, but I'm probably biased. |
ok, now it is... for JS there is for sure no problem... but I have no idea about TS |
|
thank you |
regarding the name: I'm not bound to returnResolved, I just took that, because internally the translation key needs to be resolved and the resulting information is exactly what we return... |
Ok, after thinking a bit about "verbose", that could be a bit confusing considering that this is a localization/translation library. 🤔 |
I think my favorite name is |
renamed |
😍 |
thank you, I like it |
Do you think it is ready to be merged? |
Yes. |
Do you mean this? c9754be |
Perfect |
Thank you very much again! |
released with v21.7.0 |
If you like this module don’t forget to star this repo. Make a tweet, share the word or have a look at our https://locize.com to support the devs of this project. There are many ways to help this project 🙏 |
usage:
While this PR technically works to help in use cases like #1763 I'm not sure if we should offer this kind of interface...
Normally the lang HTML attribute is set to the i18next.resolvedLanguage value.
Checklist
npm run test