Skip to content

Commit 7813202

Browse files
feat(i18n): warn about missing translation keys in development
1 parent 3115648 commit 7813202

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

‎context/TranslationContext.tsx‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,23 @@ export function TranslationProvider({ children }: { children: ReactNode }) {
118118

119119
if (value === undefined) {
120120
value = getNestedValue(translations.en as Record<string, unknown>, path);
121+
122+
if (process.env.NODE_ENV === 'development' && currentLang !== 'en') {
123+
console.warn(
124+
`[i18n] Missing translation for "${path}" in "${currentLang}", falling back to English.`
125+
);
126+
}
121127
}
122128

123129
if (value === undefined) {
124130
if (process.env.NODE_ENV === 'development') {
125131
console.warn(`⚠ Missing translation key "${path}" in locale "${currentLang}"`);
126132
}
133+
127134
if (params && 'defaultValue' in params) {
128135
return params.defaultValue;
129136
}
137+
130138
return path;
131139
}
132140

@@ -158,11 +166,13 @@ export function useTranslation() {
158166
const value = getNestedValue(en, path);
159167
if (value === undefined) {
160168
if (process.env.NODE_ENV === 'development') {
161-
console.warn(`⚠ Missing translation key "${path}" in locale "en"`);
169+
console.warn(`[i18n] Missing translation key "${path}" in English locale.`);
162170
}
171+
163172
if (params && 'defaultValue' in params) {
164173
return params.defaultValue;
165174
}
175+
166176
return path;
167177
}
168178
if (params) {

0 commit comments

Comments
 (0)