Skip to content

Commit

Permalink
move to playground
Browse files Browse the repository at this point in the history
  • Loading branch information
dBianchii committed Sep 18, 2024
1 parent 090294d commit 77e8de1
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 37 deletions.
3 changes: 3 additions & 0 deletions examples/example-app-router-playground/global.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import en from './messages/en.json';
import {formats} from './src/i18n/request';

type Messages = typeof en;
type Formats = typeof formats;

declare global {
// Use type safe message keys with `next-intl`
interface IntlMessages extends Messages {}
interface IntlFormats extends Formats {}
}
21 changes: 12 additions & 9 deletions examples/example-app-router-playground/src/i18n/request.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
import {headers} from 'next/headers';
import {notFound} from 'next/navigation';
import {Formats} from 'next-intl';
import {getRequestConfig} from 'next-intl/server';
import defaultMessages from '../../messages/en.json';
import {routing} from './routing';

export const formats = {
dateTime: {
medium: {
dateStyle: 'medium',
timeStyle: 'short',
hour12: false
}
}
} as const satisfies Partial<Formats>;

export default getRequestConfig(async ({locale}) => {
// Validate that the incoming `locale` parameter is valid
if (!routing.locales.includes(locale as any)) notFound();
Expand All @@ -22,15 +33,7 @@ export default getRequestConfig(async ({locale}) => {
globalString: 'Global string',
highlight: (chunks) => <strong>{chunks}</strong>
},
formats: {
dateTime: {
medium: {
dateStyle: 'medium',
timeStyle: 'short',
hour12: false
}
}
},
formats,
onError(error) {
if (
error.message ===
Expand Down
3 changes: 0 additions & 3 deletions examples/example-app-router/global.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import en from './messages/en.json';
import {formats} from './src/i18n/request';

type Messages = typeof en;
type Formats = typeof formats;

declare global {
// Use type safe message keys with `next-intl`
interface IntlMessages extends Messages {}
interface IntlFormats extends Formats {}
}
26 changes: 1 addition & 25 deletions examples/example-app-router/src/i18n/request.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,16 @@
import {notFound} from 'next/navigation';
import {Formats} from 'next-intl';
import {getRequestConfig} from 'next-intl/server';
import {routing} from './routing';

export const formats = {
dateTime: {
short: {
day: 'numeric',
month: 'short',
year: 'numeric'
}
},
number: {
precise: {
maximumFractionDigits: 5
}
},
list: {
enumeration: {
style: 'long',
type: 'conjunction'
}
}
} as const satisfies Partial<Formats>;

export default getRequestConfig(async ({locale}) => {
// Validate that the incoming `locale` parameter is valid
if (!routing.locales.includes(locale as any)) notFound();

return {
messages: (
await (locale === 'en'
? // When using Turbopack, this will enable HMR for `en`
import('../../messages/en.json')
: import(`../../messages/${locale}.json`))
).default,
formats
).default
};
});

0 comments on commit 77e8de1

Please sign in to comment.