# General Translation React SDKs (gt-react, gt-next, gt-react-native): Managing locale alias SEO URL: https://generaltranslation.com/en-GB/docs/react/nextjs/locale-alias-seo.mdx --- title: Managing locale alias SEO description: How to use custom locale aliases in Next.js URLs while publishing canonical language metadata for search engines. related: links: - /docs/react/nextjs/app-router-middleware - /docs/react/nextjs/app-router-static-site-generation - /docs/react/nextjs/registering-request-locales - /docs/react/nextjs/cache-components --- A locale alias lets a route use a custom segment such as `/cn` while translations use the canonical BCP 47 code `zh`. `gt-next` resolves the mapping for translations and routing, but your app remains responsible for ``, canonical URLs, language alternates, and sitemap entries. ## Configure an alias [#configure] Map the URL locale to its canonical code with [`customMapping`](/docs/react/reference/config#custom-mapping): ```json title="gt.config.json" { "defaultLocale": "en-US", "locales": ["en-US", "cn", "ja"], "customMapping": { "cn": { "code": "zh", "name": "Mandarin" } } } ``` The middleware accepts `/cn` as a localised route. General Translation resolves `cn` to `zh` when it requires the canonical locale. Keep these two values separate in SEO code: * Use the **alias** in route URLs, such as `/cn/about`. * Use the **canonical BCP 47 code** in `lang` and `hreflang`, such as `zh`. ## Set the document language [#document-language] Resolve the route locale before setting the `` attribute: ```tsx title="app/[locale]/layout.tsx" import { resolveCanonicalLocale } from 'gt-next/server'; export default async function LocaleLayout({ children, params, }: { children: React.ReactNode; params: Promise<{ locale: string }>; }) { const { locale } = await params; const canonicalLocale = resolveCanonicalLocale(locale); return (
{children} ); } ``` Without this conversion, the `/cn` route would render `lang="cn"`, which is not a valid Chinese language tag. ## Publish page alternates [#page-alternates] Next.js emits `hreflang` links from `metadata.alternates.languages`. Use canonical codes as the object keys and alias-based routes as the values: This homepage example belongs on the localised page. Build route-specific URLs in each nested page's metadata. ```tsx title="app/[locale]/page.tsx" import type { Metadata } from 'next'; import { resolveCanonicalLocale } from 'gt-next/server'; const locales = ['en-US', 'cn', 'ja']; const baseUrl = 'https://example.com'; export async function generateMetadata({ params, }: { params: Promise<{ locale: string }>; }): Promise