mirror of
https://github.com/hexastack/hexabot
synced 2025-06-26 18:27:28 +00:00
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:
commit
090dcfc0d9
@ -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
|
||||
|
@ -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: "",
|
||||
|
@ -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>,
|
||||
|
Loading…
Reference in New Issue
Block a user