Skip to content

Commit 3bbc5bf

Browse files
authored
chore(examples): localization example (#10134)
1 parent 154ad9d commit 3bbc5bf

File tree

192 files changed

+23242
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

192 files changed

+23242
-0
lines changed

examples/localization/.env.example

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Database connection string
2+
DATABASE_URI=mongodb://127.0.0.1/payload-template-website
3+
4+
# Used to encrypt JWT tokens
5+
PAYLOAD_SECRET=YOUR_SECRET_HERE
6+
7+
# Used to format links and URLs
8+
PAYLOAD_PUBLIC_SERVER_URL=http://localhost:3000
9+
NEXT_PUBLIC_SERVER_URL=http://localhost:3000
10+
11+
# Allow robots to index the site (optional)
12+
NEXT_PUBLIC_IS_LIVE=
13+
14+
# Used to preview drafts
15+
PAYLOAD_PUBLIC_DRAFT_SECRET=demo-draft-secret
16+
NEXT_PRIVATE_DRAFT_SECRET=demo-draft-secret
17+
18+
# Used to revalidate static pages
19+
REVALIDATION_KEY=demo-revalation-key
20+
NEXT_PRIVATE_REVALIDATION_KEY=demo-revalation-key

examples/localization/.eslintignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.tmp
2+
**/.git
3+
**/.hg
4+
**/.pnp.*
5+
**/.svn
6+
**/.yarn/**
7+
**/build
8+
**/dist/**
9+
**/node_modules
10+
**/temp
11+
playwright.config.ts
12+
jest.config.js

examples/localization/.eslintrc.cjs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
extends: 'next',
3+
root: true,
4+
parserOptions: {
5+
project: ['./tsconfig.json'],
6+
tsconfigRootDir: __dirname,
7+
},
8+
}

examples/localization/.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
build
2+
dist / media
3+
node_modules
4+
.DS_Store
5+
.env
6+
.next
7+
.vercel
8+
9+
# Payload default media upload directory
10+
public/media/

examples/localization/.prettierignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
**/payload-types.ts
2+
.tmp
3+
**/.git
4+
**/.hg
5+
**/.pnp.*
6+
**/.svn
7+
**/.yarn/**
8+
**/build
9+
**/dist/**
10+
**/node_modules
11+
**/temp
12+
**/docs/**
13+
tsconfig.json
14+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"singleQuote": true,
3+
"trailingComma": "all",
4+
"printWidth": 100,
5+
"semi": false
6+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"command": "yarn dev",
9+
"name": "Debug Website",
10+
"request": "launch",
11+
"type": "node-terminal"
12+
}
13+
]
14+
}

examples/localization/Dockerfile

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
FROM node:18.8-alpine as base
2+
3+
FROM base as builder
4+
5+
WORKDIR /home/node/app
6+
COPY package*.json ./
7+
8+
COPY . .
9+
RUN yarn install
10+
RUN yarn build
11+
12+
FROM base as runtime
13+
14+
ENV NODE_ENV=production
15+
16+
WORKDIR /home/node/app
17+
COPY package*.json ./
18+
COPY yarn.lock ./
19+
20+
RUN yarn install --production
21+
22+
EXPOSE 3000
23+
24+
CMD ["node", "dist/server.js"]

examples/localization/README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Payload Localization Example (i18n)
2+
3+
This example is built based on an old version of the website template.
4+
5+
The objective is to show how to implement localization in a website. There is no guarantee that it will be kept up to date with the website template or the latest Payload enhancements.
6+
7+
To facilitate the localization process, this example uses the next-intl library.
8+
9+
## Setup
10+
11+
1. `cp .env.example .env` (copy the .env.example file to .env)
12+
2. `pnpm install` (`pnpm i --ignore-workspaces` if you are running from the monorepo)
13+
3. `pnpm run dev`
14+
4. Seed your database in the admin panel (see below)
15+
16+
## Seed
17+
18+
To seed the database with a few pages, posts, and projects you can click the 'seed database' link from the admin panel.
19+
20+
The seed script will also create a demo user for demonstration purposes only:
21+
22+
- Demo Author
23+
- Email: `demo-author@payloadcms.com`
24+
- Password: `password`
25+
26+
> NOTICE: seeding the database is destructive because it drops your current database to populate a fresh one from the seed template. Only run this command if you are starting a new project or can afford to lose your current data.
27+
28+
## Important!
29+
30+
The seed script only creates translations in English and Spanish, so you will not see the website translated to other languages even if you see them in the dropdown menu.
31+
32+
You can translate documents to other languages from the admin panel.

examples/localization/components.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"$schema": "https://ui.shadcn.com/schema.json",
3+
"style": "default",
4+
"rsc": true,
5+
"tsx": true,
6+
"tailwind": {
7+
"config": "tailwind.config.js",
8+
"css": "src/app/(frontend)/globals.css",
9+
"baseColor": "slate",
10+
"cssVariables": true,
11+
"prefix": ""
12+
},
13+
"aliases": {
14+
"components": "@/components",
15+
"utils": "@/utilities"
16+
}
17+
}

0 commit comments

Comments
 (0)