Localized website template #9997
Replies: 10 comments 13 replies
-
This is definitely much needed. The localization docs are really confusing as they stand. There's no clear, step-by-step guide to walk users through setting up a fully localized website. The documentation mentions various necessary steps, but it doesn't explain how to actually implement them. It would be a huge improvement if, when you enable localization in the config of a fresh website with the default demo data, a script would automatically update the field configurations of the existing structure. Even better, that script should also add a basic language select component so users can immediately start testing the localization. That would make the whole process so much smoother and more intuitive. |
Beta Was this translation helpful? Give feedback.
-
I would love this! I’m even willing to settle for better documentation or a tutorial, but this feature would be a dream. |
Beta Was this translation helpful? Give feedback.
-
I added {
name: 'url',
localized: true,
...
} to I couldn't find I was not able to print the current language's navigation bar in the header. I'm still trying to figure it out. |
Beta Was this translation helpful? Give feedback.
-
@vatro thank you for your assistance. I successfully translated the website template. It took some time as I needed to modify numerous payload components, but the result turned out well. I'll share the repository once I've finished adding some final touches. |
Beta Was this translation helpful? Give feedback.
-
Issue: Routes not working correctly for localized URLs (/en/pricing, /en/contact) When using the official template
Steps to reproduce:
Expected behavior:
Current behavior:
Could you please advise on how to properly set up routing for localized URLs in this template? Or share an example of a working implementation? |
Beta Was this translation helpful? Give feedback.
-
Although the template is 'old,' the payload part is the best we have as a boilerplate, minus the issue @petrhromadka mentioned. I believe there is already an issue opened: #9437 |
Beta Was this translation helpful? Give feedback.
-
Hi there, I recently started playing around with payload. My PR for reference: #12476 You can also see in the initial PR comment a link to some diffs trying to make things a bit more readable.
I somehow agree on this, but there often is no perfect solution in such context:
|
Beta Was this translation helpful? Give feedback.
-
I wanted to put some more emphasis on this proposal and back it up with some numbers, but then I've learned that only approximately 5% of websites are multilingual 👀 Btw, my multilingual Payload 3 pilot project website is almost finished and I'm very satisfied with Payload 3 as CMS so far. 👍 |
Beta Was this translation helpful? Give feedback.
-
Do I have to make changes to the seeding functionality? Since the seeding of the official 'website' template doesn't work anymore after making these changes. |
Beta Was this translation helpful? Give feedback.
-
Has anyone used this in production? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
An additional, localized website template (based on the single language template) would be awesome:
Best practices concerning collections & fields localization, e.g. what should be localized in different scenarios incl. caveats.
Preserving content structure across languages (where to / not add the
localized
property)Different content structure per language (where to / not add the
localized
property)Introduce possible (common / best) localization strategies
SEO remark: SEO meta is localized out-of-the-box, not need to modify anything, see Metadata in Docs
Examples of field migration strategies when changing the
localized
property, see corresponding remark in docs: https://payloadcms.com/docs/configuration/localizationBest practice development workflows for maximum flexibility / painless modifications (e.g. editing / replacing components of a website that already has a ton of content added across multiple languages).
The most awesome would be a new CLI command, like e.g.
npx create-payload-app -n my-project -t website --localized en,xx
generating a basic localized website template with specified languages already set up "properly" (default: preserve content layout across languages) + an optional flag--preserve yes | no
(default:yes
).Robust and flexible localization options are crucial for any company / website based in a non-English speaking country doing international business.
I'm currently converting the single language website template to a localized one, these are the things I had to do / touch so far, not mentioned in the Docs (https://payloadcms.com/docs/configuration/localization) - will update it as I go forward:
Localized Frontend
Use dynamic
[lang]
route: move the contents ofsrc/app/(frontend)/
intosrc/app/(frontend)/[lang]/
Modify
src/app/(frontend)/[lang]/layout.tsx
to setlang
attribute on<html>
:Modify
src/app/(frontend)/[lang]/[slug]/page.tsx
to use thelang
param in:Page
: uselang
generateMetadata
: uselang
queryPageBySlug
: uselang
and setlocale
tolang
generateStaticParams
: setlocale
inpayload.find
to fetch a language / fetch multiple languages.Localized Slugs
src/fields/slug/index.ts
const slugField: TextField = { name: 'slug', type: 'text', + localized: true,
Localized Live Preview / Preview
src/utilities/generatePreviewPath.ts
src/app/(frontend)/[lang]/next/preview/route.ts
Localized Header / Navigation
src/fields/link.ts
localized
label
, customurl
andreference
fieldsname: 'label', type: 'text', + localized: true,
name: 'url', type: 'text', + localized: true,
name: 'reference', type: 'relationship', + localized: true,
optionally localize the whole
header
if you need different nav menu per language:src/Header/config.ts
fields: [ { name: 'navItems', type: 'array', + localized: true, // allow different nav items per locale
src/app/(frontend)/[lang]/layout.tsx
src/utilities/getGlobals.ts
use
locale
and exportgetGlobal
because we need uncachedheader
data insrc/Header/Component.tsx
src/Header/Component.tsx
use
locale
and uncachedheader
data in order to get correct data on locale change.👆 not sure about using
getGlobal
/ not usinggetCachedGlobal
, but it works.Drill down
locale
toCMSLink
ComponentFor localized relational (
reference
) link-urls, e.g.<host>//[locale]/[slug]
instead of<host>//[slug]
.src/Header/Component.tsx
src/Header/Component.client.tsx
src/Header/Nav/index.tsx
src/components/Link/index.tsx
(CMSLink
Component)@payloadcms/plugin-redirects
Wasn't successful with fully localizing it.
Was able to localize the
to
fields (reference and custom URL), but not thefrom
field: e.g./home
slug doesn't take current locale into account, also/xx/home
slug doesn't work and I couldn't find the way how to inject the current locale into thefrom:
value, I guess this could be done with a hook. That's why I'm currently using middleware for redirects instead of the plugin.Beta Was this translation helpful? Give feedback.
All reactions