forked from cardosofelipe/fast-next-template
Refactor i18n setup and improve structure for maintainability
- Relocated `i18n` configuration files to `src/lib/i18n` for better organization. - Removed obsolete `request.ts` and `routing.ts` files, simplifying `i18n` setup within the project. - Added extensive tests for `i18n/utils` to validate locale-related utilities, including locale name, native name, and flag retrieval. - Introduced a detailed `I18N_IMPLEMENTATION_PLAN.md` to document implementation phases, decisions, and recommendations for future extensions. - Enhanced TypeScript definitions and modularity across i18n utilities for improved developer experience.
This commit is contained in:
@@ -14,7 +14,7 @@
|
||||
*/
|
||||
|
||||
import { getRequestConfig } from 'next-intl/server';
|
||||
import { routing } from './routing';
|
||||
import { routing } from '@/lib/i18n/routing';
|
||||
|
||||
export default getRequestConfig(async ({ locale }) => {
|
||||
// Validate that the incoming `locale` parameter is valid
|
||||
@@ -2,11 +2,10 @@
|
||||
/**
|
||||
* Utility functions for internationalization.
|
||||
*
|
||||
* This file demonstrates type-safe translation usage.
|
||||
* This file provides pure utility functions for i18n without React dependencies.
|
||||
* For React hooks, see hooks.ts
|
||||
*/
|
||||
|
||||
import { useTranslations } from 'next-intl';
|
||||
|
||||
/**
|
||||
* Get the display name for a locale code.
|
||||
*
|
||||
@@ -54,28 +53,6 @@ export function getLocaleFlag(locale: string): string {
|
||||
return flags[locale] || flags.en;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook to get common translations.
|
||||
* This demonstrates type-safe usage of useTranslations.
|
||||
*
|
||||
* @returns Object with commonly used translation functions
|
||||
*/
|
||||
export function useCommonTranslations() {
|
||||
const t = useTranslations('common');
|
||||
|
||||
return {
|
||||
loading: () => t('loading'),
|
||||
error: () => t('error'),
|
||||
success: () => t('success'),
|
||||
cancel: () => t('cancel'),
|
||||
save: () => t('save'),
|
||||
delete: () => t('delete'),
|
||||
edit: () => t('edit'),
|
||||
close: () => t('close'),
|
||||
confirm: () => t('confirm'),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a relative time string (e.g., "2 hours ago").
|
||||
* This is a placeholder for future implementation with next-intl's date/time formatting.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import type { NextRequest } from 'next/server';
|
||||
import createMiddleware from 'next-intl/middleware';
|
||||
import { routing } from './i18n/routing';
|
||||
import { routing } from './lib/i18n/routing';
|
||||
|
||||
// Create next-intl middleware for locale handling
|
||||
const intlMiddleware = createMiddleware(routing);
|
||||
|
||||
Reference in New Issue
Block a user