feat(i18n): Hebrew locale + full RTL support

This commit is contained in:
Shuki Vaknin
2026-07-08 00:07:34 +02:00
committed by Linus Rath
parent 8904d724bb
commit 22418c17cf
113 changed files with 3958 additions and 494 deletions
+31 -1
View File
@@ -1,11 +1,33 @@
import { getRequestConfig } from 'next-intl/server';
import { headers } from 'next/headers';
import { mergeMessages } from './merge-messages';
import { routing, type Locale } from './routing';
// Default a first-time visitor (no explicit stored choice) to the best supported
// language from their browser's Accept-Language header, so "Auto" is the real
// default and the first server render already matches the browser language.
function localeFromAcceptLanguage(header: string | null): string | null {
if (!header) return null;
const supported = new Set<string>(routing.locales as readonly string[]);
const ranked = header
.split(',')
.map((part) => {
const [tag, q] = part.trim().split(';q=');
return { base: tag.toLowerCase().split('-')[0], q: q ? parseFloat(q) : 1 };
})
.sort((a, b) => b.q - a.q);
for (const { base } of ranked) {
if (supported.has(base)) return base;
}
return null;
}
export default getRequestConfig(async ({ requestLocale }) => {
let locale = await requestLocale;
if (!locale || !routing.locales.includes(locale as Locale)) {
locale = routing.defaultLocale;
const accept = (await headers()).get('accept-language');
locale = localeFromAcceptLanguage(accept) ?? routing.defaultLocale;
}
// Use static imports for better compatibility
@@ -23,6 +45,9 @@ export default getRequestConfig(async ({ requestLocale }) => {
case 'es':
messages = (await import('../locales/es/common.json')).default;
break;
case 'he':
messages = (await import('../locales/he/common.json')).default;
break;
case 'fa':
messages = (await import('../locales/fa/common.json')).default;
break;
@@ -75,6 +100,11 @@ export default getRequestConfig(async ({ requestLocale }) => {
messages = (await import('../locales/en/common.json')).default;
}
if (locale !== 'en') {
const enBase = (await import('../locales/en/common.json')).default as Record<string, unknown>;
messages = mergeMessages(enBase, messages as Record<string, unknown>);
}
return {
locale,
messages,