calcom / cal.com

Scheduling infrastructure for absolutely everyone.
https://cal.com
Other
32.07k stars 7.88k forks source link

Use correct translation key #15656

Closed RushikeshGandhmal closed 3 months ago

RushikeshGandhmal commented 3 months ago

Found a bug? Please fill out the sections below. 👍

Issue Summary

Use correct translation key

Steps to Reproduce

  1. (for example) Went to ...
  2. Clicked on...
  3. ...

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

dosubot[bot] commented 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:

  1. The translation key exists in the enTranslations object.
  2. The 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.

hariombalhara commented 3 months ago

@RushikeshGandhmal I really don't understand what this issue is from the description

RushikeshGandhmal commented 3 months ago

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.

https://www.loom.com/share/7f8ec97a78bc4f4ab56841935932da1d