Internationalization (i18n)
Relevant source files
The following files were used as context for generating this wiki page:
- src/app/llms.txt/route.ts
- src/lib/category-faq-server.ts
- src/app/[locale]/(platform)/tos/page.tsx/tos/page.tsx)
- src/app/sitemaps/sitemap.ts
- src/app/[locale]/admin/integrations/_components/AdminIntegrationsForm.tsx
- src/app/[locale]/admin/(general)/_actions/update-general-settings.ts/_actions/update-general-settings.ts)
Internationalization (i18n) in the prediction market platform is built using next-intl to support multi-language routing, content translation, and localized metadata. The system ensures that all user-facing strings—including legal documents like the Terms of Service, category-specific FAQs, and SEO metadata—can be adapted for different locales.
The architecture relies on a [locale] dynamic route segment, allowing the application to serve content specific to the requested language. Core configuration includes defining supported locales, managing localized sitemaps for search engine optimization, and providing administrative interfaces to manage integration settings across different regions.
Sources: src/app/[locale]/(platform)/tos/page.tsx, src/app/llms.txt/route.ts:5-7, src/app/sitemaps/sitemap.ts:13-14
Core Routing and Middleware
The platform utilizes locale-aware routing where the locale is a top-level parameter in the URL structure (e.g., /[locale]/tos). This is supported by utility functions that build localized paths and handle alternate language links for SEO.
Locale Configuration and Detection
The system defines a DEFAULT_LOCALE and a set of SUPPORTED_LOCALES. These are used to generate prefixes for public application routes. For machine-readable indexes like llms.txt, non-default locale prefixes are explicitly identified to guide LLMs toward canonical English content while acknowledging localized versions.
Sources: src/app/llms.txt/route.ts:7-9, src/app/sitemaps/sitemap.ts:12-14
Localized Sitemaps
Sitemaps are generated dynamically and include alternate language links for every path. This ensures that search engines can discover all localized versions of a page through the alternates.languages property.
The buildAlternateLanguages function maps each supported locale to its absolute URL and includes an x-default entry pointing to the base URL.
Sources: src/app/sitemaps/sitemap.ts:83-108
Content Translation Logic
Translation is handled through the next-intl library, utilizing both server-side and client-side hooks.
Server-Side Translation
Server components use getExtracted and setRequestLocale to fetch translations and set the context for the current request. This is critical for generating localized metadata and rendering page content.
- Metadata Generation: Functions like
generateMetadatause the locale parameter to translate page titles and descriptions. - Dynamic FAQ Generation: The
buildTranslatedCategoryFaqItemsfunction usesgetExtracted({ locale })to translate complex strings with multiple interpolation variables.
// Example of interpolation in translations
const messages = {
whatIsSiteAnswer: t(
"{siteName} is a prediction market where users trade on real-world outcomes...",
values
)
}
Sources: src/app/[locale]/(platform)/tos/page.tsx:10-14, src/lib/category-faq-server.ts:19-28
Client-Side Translation
In "use client" components, such as the AdminIntegrationsForm, the useExtracted hook provides access to the translation function. This allows the UI to update labels, placeholders, and toast notifications based on the active locale.
Sources: src/app/[locale]/admin/integrations/_components/AdminIntegrationsForm.tsx:104-106
Localized Data Structures
The system manages various data types that require localization or locale-specific handling.
Category FAQ Context
FAQs are built dynamically based on the category and locale. The translation logic supports specific placeholders for market counts, event counts, and subcategories.
| Variable | Description | Source |
|---|---|---|
categoryName | The name of the prediction category (e.g., Politics). | src/lib/category-faq-server.ts |
eventCount | Number of events in the category. | src/lib/category-faq-server.ts |
marketCount | Total active markets. | src/lib/category-faq-server.ts |
siteName | The configured name of the platform. | src/lib/category-faq-server.ts |
Sources: src/lib/category-faq-server.ts:20-27
Administrative Settings
The admin interface allows for the configuration of locale-sensitive integrations, such as Google Analytics and OpenRouter. When settings are updated, the system revalidates localized paths to ensure the cache reflects the new configuration across all supported languages.
Integration with External Services
Internationalization extends to how the platform interacts with third-party providers:
- AI (OpenRouter): AI models are used for generating market rules and featured market context. These interactions often require English as a base for logic but results may be surfaced in localized views.
- Identity (Sumsub): KYC verification levels and enforcement settings are managed via the admin panel, with localized feedback for successful or failed connections.
- Search Indexes: The
llms.txtroute explicitly notes that while app pages are localized, documentation content is canonical in English.
Sources: src/app/llms.txt/route.ts:145-148, src/app/[locale]/admin/integrations/_components/AdminIntegrationsForm.tsx:216-234
Summary
The i18n system provides a robust framework for delivering a localized prediction market experience. By leveraging next-intl alongside custom routing logic and dynamic sitemap generation, the platform ensures that both users and search engines can navigate the site in multiple languages effectively. Administrative tools further allow for the fine-tuning of localized settings and the revalidation of content across the entire locale spectrum.