Closed RushikeshGandhmal closed 3 months ago
To address the issue with the incorrect translation key, ensure that the translation key exists in the enTranslations
object and that the replaceOccurrences
function is correctly replacing the placeholders.
Here is the relevant part of the code that handles translations:
const translations = {
t: (key: string, values: Record<string, string | number | null | undefined>) => {
let translation = String(enTranslations[key as translationKeys] ?? "");
if (!translation) {
return "";
}
if (values) {
const valueKeys = Object.keys(values) as (keyof typeof values)[];
if (valueKeys.length) {
valueKeys.forEach((valueKey) => {
if (translation)
translation = translation.replace(
`{{${String(valueKey)}}}`,
values[valueKey]?.toString() ?? `{{${String(valueKey)}}}`
);
});
}
}
return replaceOccurrences(translation, enTranslations) ?? "";
},
i18n: {
language: "en",
defaultLocale: "en",
locales: ["en"],
exists: (key: translationKeys | string) => Boolean(enTranslations[key as translationKeys]),
},
};
Ensure that:
enTranslations
object.replaceOccurrences
function is correctly replacing the placeholders in the translation string.The replaceOccurrences
function is defined as follows:
function replaceOccurrences(input: string, replacementMap: { [key: string]: string }): string {
const pattern = /\$t\((.*?)\)/g;
return input.replace(pattern, (match, key) => {
if (key in replacementMap) {
return replacementMap[key];
}
return match;
});
}
Additionally, ensure that your translation keys are correctly identified and matched in your codebase. The following regex can be used to match translation keys in your code:
const translationKeyRegex = /(?<!\w)(?:t\(("[^"]*")(?:,\s*\{[^}]*\})?\)|i18nKey=".+"[^\w])/gi;
Make sure that the placeholders in your translation strings are correctly formatted and that the replacementMap
contains the necessary keys for replacement. If the key is not found in the replacementMap
, the original match will be returned, which might be the cause of the placeholder text being displayed [1][2][3].
To continue talking to Dosu, mention @dosu.
@RushikeshGandhmal I really don't understand what this issue is from the description
Hi @hariombalhara, I see, for event type google calendar is required got meet to work, redirecting the user to apps/google-calendar to install is better? what do u think ? The key "event_type_requred_google_cal" isn't present anywhere.
Found a bug? Please fill out the sections below. 👍
Issue Summary
Use correct translation key
Steps to Reproduce
Any other relevant information. For example, why do you consider this a bug and what did you expect to happen instead?
Actual Results
Expected Results
Technical details
Evidence