Merge pull request #161 from Hexastack/160-bug-nlu-training-i18n-translation-issue

fix(frontend): NLU Training I18n translation issue
This commit is contained in:
Mohamed Marrouchi 2024-10-05 07:35:43 +01:00 committed by GitHub
commit 090dcfc0d9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 14 additions and 6 deletions

View File

@ -435,7 +435,7 @@ const NlpDatasetSample: FC<NlpDatasetSampleProps> = ({
>
{!selection?.value
? t("button.select_some_text")
: t("button.add_nlp_entity", { defaultValue: selection.value })}
: t("button.add_nlp_entity", { 0: selection.value })}
</Button>
<Button

View File

@ -6,10 +6,13 @@
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
*/
import { TOptionsBase } from "i18next";
import { useTranslation } from "react-i18next";
import { TTranslateProps, TTranslationKeys } from "@/i18n/i18n.types";
import {
TTranslateProps,
TTranslationKeys,
TOptionsBaseExtended,
} from "@/i18n/i18n.types";
export const useTranslate = () => {
const { t, i18n } = useTranslation();
@ -21,13 +24,13 @@ export const useTranslate = () => {
// full key. For example: prop1 = label.buttons
if (typeof prop1 === "string" && prop1.includes(".")) {
const key = prop1 as TTranslationKeys;
const options = (prop2 || {}) as TOptionsBase;
const options = (prop2 || {}) as TOptionsBaseExtended;
return t(key, { defaultValue: "", ...options });
}
// key with nested key. For example: prop1=label prop2=buttons
const options = (prop3 || {}) as TOptionsBase;
const options = (prop3 || {}) as TOptionsBaseExtended;
return t([prop1, prop2].join(".") as TTranslationKeys, {
defaultValue: "",

View File

@ -22,8 +22,13 @@ export type TTranslationKeys = TFilterNestedKeysOfType<TEnTranslation> &
export type TNestedTranslation<T extends keyof TTranslation> =
TFilterNestedKeysOfType<TTranslation[T]>;
export type TOptionsBaseExtended = TOptionsBase & { 0?: string };
export type TTranslateProps = {
<K extends TTranslationKeys>(prop1: K, prop2?: TOptionsBase & object): string;
<K extends TTranslationKeys>(
prop1: K,
prop2?: TOptionsBaseExtended & object,
): string;
<K extends keyof TTranslation, N = TNestedTranslation<K>>(
prop1: K,
prop2: N & TNestedTranslation<K>,