Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
amannn committed Nov 1, 2024
1 parent c94d2b8 commit 20d1a96
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ Note that by default, `next-intl` returns [the `link` response header](/docs/rou

Next.js supports providing alternate URLs per language via the [`alternates` entry](https://nextjs.org/docs/app/api-reference/file-conventions/metadata/sitemap#generate-a-localized-sitemap) as of version 14.2. You can use your default locale for the main URL and provide alternate URLs based on all locales that your app supports. Keep in mind that also the default locale should be included in the `alternates` object.

```tsx filename="app/sitemap.ts" {4-5,8-9}
```tsx filename="app/sitemap.ts" {5-6,9-10}
import {MetadataRoute} from 'next';
import {Locale} from 'next-intl';
import {routing, getPathname} from '@/i18n/routing';
Expand Down
2 changes: 1 addition & 1 deletion docs/src/pages/docs/environments/error-files.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export default function RootLayout({children}) {
}
```

For the 404 page to render, we need to call the `notFound` function in the root layout when we detect an incoming `locale` param that isn't a valid locale.
For the 404 page to render, we need to call the `notFound` function in the root layout when we detect an incoming `locale` param that isn't valid.

```tsx filename="app/[locale]/layout.tsx"
import {hasLocale} from 'next-intl';
Expand Down
10 changes: 5 additions & 5 deletions docs/src/pages/docs/workflows/typescript.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ function Component() {
}
```

To enable this validation, export the formats that you're using in your request configuration:
To enable this validation, export the formats that you're using e.g. from your request configuration:

```ts filename="i18n/request.ts"
import {Formats} from 'next-intl';
Expand Down Expand Up @@ -128,7 +128,7 @@ declare module 'next-intl' {

## `Locale`

Augmenting the `Locale` type will affect the return type of [`useLocale`](/docs/usage/configuration#locale), as well as all `locale` arguments that are received by `next-intl` (e.g. the `locale` prop of [`<Link />`](/docs/routing/navigation#link)).
Augmenting the `Locale` type will affect the return type of [`useLocale`](/docs/usage/configuration#locale), as well as all `locale` arguments that are accepted by APIs from `next-intl` (e.g. the `locale` prop of [`<Link />`](/docs/routing/navigation#link)).

```tsx
// ✅ 'en' | 'de'
Expand Down Expand Up @@ -173,9 +173,9 @@ declare module 'next-intl' {

Once the `Locale` type is augmented, it can be used across your codebase if you need to pass the locale to functions outside of your components:

```tsx {2,10}
import {getLocale} from 'next-intl/server';
```tsx {1,10}
import {Locale} from 'next-intl';
import {getLocale} from 'next-intl/server';

async function BlogPosts() {
const locale = await getLocale();
Expand Down Expand Up @@ -238,4 +238,4 @@ If you're encountering problems, double check that:
1. The interface uses the correct name `AppConfig`.
2. You're using correct paths for all modules you're importing into your global declaration file.
3. Your type declaration file is included in `tsconfig.json`.
4. Your editor has loaded the most recent type declarations. When in doubt, you can restart.
4. Your editor has loaded the latest types. When in doubt, restart your editor.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Metadata} from 'next';
import {useTranslations} from 'next-intl';
import {Locale, getPathname} from '@/i18n/routing';
import {Locale, useTranslations} from 'next-intl';
import {getPathname} from '@/i18n/routing';

type Props = {
params: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {ImageResponse} from 'next/og';
import {Locale} from 'next-intl';
import {getTranslations} from 'next-intl/server';
import {Locale} from '@/i18n/routing';

type Props = {
params: {
Expand Down
3 changes: 0 additions & 3 deletions examples/example-app-router-playground/src/i18n/routing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,5 @@ export const routing = defineRouting({
}
});

export type Pathnames = keyof typeof routing.pathnames;
export type Locale = (typeof routing.locales)[number];

export const {Link, getPathname, redirect, usePathname, useRouter} =
createNavigation(routing);
2 changes: 1 addition & 1 deletion packages/use-intl/src/core/AppConfig.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export default interface AppConfig {
// Locale
// Formats
// Messages (todo)
// Messages
}

export type Locale = AppConfig extends {
Expand Down

0 comments on commit 20d1a96

Please sign in to comment.