# Localization

Localization lets editors maintain content in several languages. It doesn't change the language of the SP CMS interface. For the editing side, see [edit translations](/guides/translations/).

Pick the scheme that matches how the site already stores translations:

- `files`: one file per language, such as `about.md` and `about.fr.md`.
- `fields`: language keys inside one file, such as `title: { en: About, fr: À propos }`.

## 1. Declare your languages

At the root of `.pages.yml`:

```yaml
i18n:
  default: en
  locales:
    - en
    - code: fr
      label: Français
```

Codes must match exactly what's in your filenames or keys. They start with a letter and use letters, numbers, `-` and `_`. Labels are optional. You can declare up to 50 languages. Without `default`, the first language is the default.

## 2. Localize content

Add `i18n` to each collection or file that has translations. Everything else stays in one language.

### One file per language

Configure the collection to use one file per language:

```yaml
content:
  - name: posts
    type: collection
    path: src/content/posts
    i18n:
      scheme: files
      path:
        type: filename
        position: suffix
        default: omit
    fields:
      - name: title
        type: string
      - name: body
        type: rich-text
```

This pairs `src/content/posts/about.md` (English) with `src/content/posts/about.fr.md` (French).

`path` describes where each language's file lives. It's required for this scheme.

With `type: filename`, the code goes in the filename:

| Key         | Values                                                                                    | Default    |
| ----------- | ----------------------------------------------------------------------------------------- | ---------- |
| `type`      | `filename`                                                                                | Required   |
| `position`  | `prefix` or `suffix`                                                                      | Required   |
| `separator` | Dots, underscores or hyphens, such as `.`, `_` or `-`                                     | `.`        |
| `default`   | `omit`: no code for the default language. `explicit`: always add it, as in `about.en.md`. | `explicit` |

With `type: folder`, the code is a folder. For the file `src/content/posts/guides/about.md` and `default: omit`, French goes to:

| `position`                 | French file                            |
| -------------------------- | -------------------------------------- |
| `root`                     | `fr/src/content/posts/guides/about.md` |
| `collection`               | `src/content/posts/fr/guides/about.md` |
| `parent`                   | `src/content/posts/guides/fr/about.md` |
| `custom` with `after: src` | `src/fr/content/posts/guides/about.md` |

`after` must name an exact ancestor folder of the content path. Single files support filename rules and the `root`, `parent` and `custom` folder positions.

With `default: omit`, names that look like translations are reserved. For example, an English file can't be called `about.fr.md`.

### Languages in one file

Mark the fields that have a value for each language:

```yaml
content:
  - name: home
    type: file
    path: src/data/home.json
    i18n:
      scheme: fields
    fields:
      - name: title
        type: string
        localized: true
      - name: published
        type: boolean
```

For example, `src/data/home.json` could contain:

```json
{
  "title": { "en": "Home", "fr": "Accueil" },
  "published": true
}
```

Fields marked `localized: true` hold one value per language; unmarked fields are shared. Where you put `localized` decides the shape:

| `localized: true` on     | Stored as                                      |
| ------------------------ | ---------------------------------------------- |
| A field                  | `title: { en: …, fr: … }`                      |
| An object                | `hero: { en: { title: … }, fr: { title: … } }` |
| A list                   | A separate list per language                   |
| The content entry itself | `{ en: { title: … }, fr: { title: … } }`       |

Mark only one level: don't add `localized` inside something that's already localized.

This scheme works with JSON, YAML, TOML and their front matter variants. The Markdown `body` can't be localized inside one file; use one file per language for translated bodies.

## Languages per collection or file

A collection or file inherits every project language. To use a subset, set `locales` on its `i18n`; this replaces the project list. If the subset leaves out the project's default, also set `default`.

```yaml
i18n:
  scheme: files
  locales: [en, de]
  path: { type: filename, position: suffix }
```

## Good to know

- Missing translations don't fall back to another language. The site decides what to show.
- Required localized fields need a value in every language.
- Language keys that aren't declared stay in the file, but editors don't see them and SP CMS doesn't check them.
- [Reference fields](/configuration/fields/reference/) pick entries in the current language when the target collection is localized; `{locale}` is available in their templates.
- There are no per-language permissions: anyone who can edit the content can edit every language.
