Skip to content

Commit

Permalink
feat(next-international): add Next.js 13 app directory support (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
QuiiBz authored Jul 2, 2023
1 parent c230d85 commit 1cad8d6
Show file tree
Hide file tree
Showing 71 changed files with 3,091 additions and 1,375 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ node_modules/
out/
dist/
coverage/
.vscode/

.DS_Store
*.log*
Expand Down
File renamed without changes.
35 changes: 35 additions & 0 deletions examples/next-app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env*.local

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts
36 changes: 36 additions & 0 deletions examples/next-app/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).

## Getting Started

First, run the development server:

```bash
npm run dev
# or
yarn dev
# or
pnpm dev
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.

[http://localhost:3000/api/hello](http://localhost:3000/api/hello) is an endpoint that uses [Route Handlers](https://beta.nextjs.org/docs/routing/route-handlers). This endpoint can be edited in `app/api/hello/route.ts`.

This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font.

## Learn More

To learn more about Next.js, take a look at the following resources:

- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.

You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!

## Deploy on Vercel

The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.

Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
12 changes: 12 additions & 0 deletions examples/next-app/app/[locale]/client/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use client';

import { ReactNode } from 'react';
import { I18nProviderClient } from '../../../locales/client';

export default function Layout({ children, params: { locale } }: { children: ReactNode; params: { locale: string } }) {
return (
<I18nProviderClient locale={locale} fallback={<p>Loading...</p>}>
{children}
</I18nProviderClient>
);
}
66 changes: 66 additions & 0 deletions examples/next-app/app/[locale]/client/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
'use client';

import { useI18n, useScopedI18n, useChangeLocale, useCurrentLocale } from '../../../locales/client';

export default function Client() {
const t = useI18n();
const changeLocale = useChangeLocale();
const t2 = useScopedI18n('scope.more');
const locale = useCurrentLocale();

return (
<div>
<h1>CSR</h1>
<p>
Current locale:
<span>{locale}</span>
</p>
<p>Hello: {t('hello')}</p>
<p>
Hello:{' '}
{t('welcome', {
name: 'John',
})}
</p>
<p>
Hello (with React components):{' '}
{t('welcome', {
name: <strong>John</strong>,
})}
</p>
<p>
Hello:{' '}
{t('about.you', {
age: '23',
name: 'Doe',
})}
</p>
<p>
Hello (with React components):{' '}
{t('about.you', {
age: <strong>23</strong>,
name: 'Doe',
})}
</p>
<p>{t2('test')}</p>
<p>
{t2('param', {
param: 'test',
})}
</p>
<p>
{t2('param', {
param: <strong>test</strong>,
})}
</p>
<p>{t2('and.more.test')}</p>
<p>{t('missing.translation.in.fr')}</p>
<button type="button" onClick={() => changeLocale('en')}>
EN
</button>
<button type="button" onClick={() => changeLocale('fr')}>
FR
</button>
</div>
);
}
107 changes: 107 additions & 0 deletions examples/next-app/app/[locale]/globals.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
:root {
--max-width: 1100px;
--border-radius: 12px;
--font-mono: ui-monospace, Menlo, Monaco, 'Cascadia Mono', 'Segoe UI Mono',
'Roboto Mono', 'Oxygen Mono', 'Ubuntu Monospace', 'Source Code Pro',
'Fira Mono', 'Droid Sans Mono', 'Courier New', monospace;

--foreground-rgb: 0, 0, 0;
--background-start-rgb: 214, 219, 220;
--background-end-rgb: 255, 255, 255;

--primary-glow: conic-gradient(
from 180deg at 50% 50%,
#16abff33 0deg,
#0885ff33 55deg,
#54d6ff33 120deg,
#0071ff33 160deg,
transparent 360deg
);
--secondary-glow: radial-gradient(
rgba(255, 255, 255, 1),
rgba(255, 255, 255, 0)
);

--tile-start-rgb: 239, 245, 249;
--tile-end-rgb: 228, 232, 233;
--tile-border: conic-gradient(
#00000080,
#00000040,
#00000030,
#00000020,
#00000010,
#00000010,
#00000080
);

--callout-rgb: 238, 240, 241;
--callout-border-rgb: 172, 175, 176;
--card-rgb: 180, 185, 188;
--card-border-rgb: 131, 134, 135;
}

@media (prefers-color-scheme: dark) {
:root {
--foreground-rgb: 255, 255, 255;
--background-start-rgb: 0, 0, 0;
--background-end-rgb: 0, 0, 0;

--primary-glow: radial-gradient(rgba(1, 65, 255, 0.4), rgba(1, 65, 255, 0));
--secondary-glow: linear-gradient(
to bottom right,
rgba(1, 65, 255, 0),
rgba(1, 65, 255, 0),
rgba(1, 65, 255, 0.3)
);

--tile-start-rgb: 2, 13, 46;
--tile-end-rgb: 2, 5, 19;
--tile-border: conic-gradient(
#ffffff80,
#ffffff40,
#ffffff30,
#ffffff20,
#ffffff10,
#ffffff10,
#ffffff80
);

--callout-rgb: 20, 20, 20;
--callout-border-rgb: 108, 108, 108;
--card-rgb: 100, 100, 100;
--card-border-rgb: 200, 200, 200;
}
}

* {
box-sizing: border-box;
padding: 0;
margin: 0;
}

html,
body {
max-width: 100vw;
overflow-x: hidden;
}

body {
color: rgb(var(--foreground-rgb));
background: linear-gradient(
to bottom,
transparent,
rgb(var(--background-end-rgb))
)
rgb(var(--background-start-rgb));
}

a {
color: inherit;
text-decoration: none;
}

@media (prefers-color-scheme: dark) {
html {
color-scheme: dark;
}
}
24 changes: 24 additions & 0 deletions examples/next-app/app/[locale]/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { ReactElement } from 'react';
import { I18nProviderServer } from '../../locales/server';
import './globals.css';

export const metadata = {
title: 'Create Next App',
description: 'Generated by create next app',
};

export default function RootLayout({
children,
params: { locale },
}: {
children: ReactElement;
params: { locale: string };
}) {
return (
<html lang="en">
<body>
<I18nProviderServer locale={locale}>{children}</I18nProviderServer>
</body>
</html>
);
}
Loading

0 comments on commit 1cad8d6

Please sign in to comment.