Concepts

Locales

Use locales for multilingual and regional content.

Prismic supports creating localized versions of your content for different languages and regions. Each locale uses a code like en-us or fr-ca to represent a specific language and region combination.

Learn how content writers use locales

See the Next.js, Nuxt, or SvelteKit guides for framework-specific examples.

Fetch content from locales

Use the Prismic client’s lang query parameter to fetch from a specific locale:

// Fetches all blog posts from the `en-ca` locale.
const blogPosts = await client.getAllByType("blog_post", {
  lang: "en-ca",
});

Use the * wildcard to fetch content from all locales:

// Fetches all blog posts from all locales.
const page = await client.getAllByType("blog_post", {
  lang: "*",
});

By default, pages are fetched from your repository’s master locale:

const client = createClient("example-prismic-repo");

// Fetches all blog posts from the master locale.
const blogPosts = await client.getAllByType("blog_post");

Learn more about the lang query parameter

Add locales to routes

You can add locales to page URLs by configuring your website’s route resolvers.

The following example route resolver adds a page’s locale to the start of its URL via the :lang keyword. The :lang keyword is replaced with the page’s locale.

{
  "type": "page",
  "path": "/:lang/:uid"
}

The above route resolver may output a URL like /en-ca/my-first-post.

The :lang? keyword (with a ?) omits the locale if the page is from the master locale.

{
  "type": "page",
  "path": "/:lang?/:uid"
}

If en-ca is the master locale, the previous /en-ca/my-first-post example URL would be /my-first-post instead.

Learn more about routes

Locales in the API

The Content API provides a page’s locale in its lang property:

{
  "id": "YCiUyRUAACQAxfZK",
  "uid": "my-first-post",
  "url": "/blog/my-first-post",
  "type": "blog_post",
  "href": "https://example-prismic-repo.cdn.prismic.io/api/v2/...",
  "tags": ["Tag 1", "Tag 2"],
  "first_publication_date": "2021-02-14T03:22:26+0000",
  "last_publication_date": "2022-07-09T00:36:18+0000",
  "slugs": ["my-first-post"],
  "linked_documents": [],
  "lang": "fr-fr",
  "alternate_languages": [],
  "data": {
    // ...
  }
}

A page’s translated versions are listed in the page’s alternate_languages property.

{
  "id": "YCiUyRUAACQAxfZK",
  "uid": "my-first-post",
  // ...
  "alternate_languages": [
    {
      "id": "XTb4mBAAACQAOfrg",
      "type": "homepage",
      "lang": "fr-fr"
    }
  ],
  "data": {
    // ...
  }
}
Was this page helpful?