Skip to content

Commit

Permalink
[docs] Fix issues reported by react compiler in docs folder (#42881)
Browse files Browse the repository at this point in the history
  • Loading branch information
sai6855 committed Jul 8, 2024
1 parent 86bc428 commit edb100c
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions packages/mui-docs/src/i18n/i18n.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,16 @@ export function useSetUserLanguage() {

const warnedOnce: Record<string, boolean> = {};

const warn = (userLanguage: string, key: string, ignoreWarning: boolean) => {
const fullKey = `${userLanguage}:${key}`;
// No warnings in CI env
if (!ignoreWarning && !warnedOnce[fullKey] && typeof window !== 'undefined') {
console.warn(`Missing translation for ${fullKey}`);

warnedOnce[fullKey] = true;
}
};

export interface TranslateOptions {
ignoreWarning?: boolean;
}
Expand All @@ -104,12 +114,7 @@ export function useTranslate() {
const translation = getPath(wordings, key);

if (!translation) {
const fullKey = `${userLanguage}:${key}`;
// No warnings in CI env
if (!ignoreWarning && !warnedOnce[fullKey] && typeof window !== 'undefined') {
console.error(`Missing translation for ${fullKey}`);
warnedOnce[fullKey] = true;
}
warn(userLanguage, key, ignoreWarning);
return getPath(translations.en, key);
}

Expand Down

0 comments on commit edb100c

Please sign in to comment.