The Node.js® Website
at main 1.1 kB view raw
1import { getRequestConfig } from 'next-intl/server'; 2 3import { availableLocaleCodes } from '@/next.locales.mjs'; 4 5// Loads the Application Locales/Translations Dynamically 6const loadLocaleDictionary = async (locale: string) => { 7 if (locale === 'en') { 8 // This enables HMR on the English Locale, so that instant refresh 9 // happens while we add/change texts on the source locale 10 return import('./i18n/locales/en.json').then(f => f.default); 11 } 12 13 if (availableLocaleCodes.includes(locale)) { 14 // Other languages don't really require HMR as they will never be development languages 15 // so we can load them dynamically 16 return import(`./i18n/locales/${locale}.json`).then(f => f.default); 17 } 18 19 throw new Error(`Unsupported locale: ${locale}`); 20}; 21 22// Provides `next-intl` configuration for RSC/SSR 23export default getRequestConfig(async ({ locale }) => ({ 24 // This is the dictionary of messages to be loaded 25 messages: await loadLocaleDictionary(locale), 26 // We always define the App timezone as UTC 27 timeZone: 'Etc/UTC', 28}));