Features
Localization
Translated text fields, picked per request with a locale.
Graph stores each entry's field values in the base locale, en-US, and lets editors add translations of its text fields in the other languages your workspace enables. Any request can ask for a locale, and gets those translations back in place of the original text.
Requesting a locale
Add locale to any REST request:
curl "https://api.graphcms.io/v1/content/blog-posts/hello-world?locale=fr-FR" \ -H "Authorization: Bearer $GRAPH_API_KEY"{ "success": true, "data": { "slug": "hello-world", "locale": "fr-FR", "fields": { "excerpt": "Notre premier article.", "body": "<p>Welcome to the blog.</p>", "featured": true } }}Or pass it as an argument in GraphQL, on contentEntries, contentEntry and contentEntryById:
1query {2 contentEntry(contentType: "blog-posts", slug: "hello-world", locale: "fr-FR") {3 locale4 fields5 }6}The SDK takes it as an option: graph.content.entry('blog-posts', 'hello-world', { locale: 'fr-FR' }).
How translations resolve
- Only
textandtextareafields are translated. Every other field type (html,number,mediaand so on) always returns its original value. - A text field with no translation in the requested locale returns the original, en-US text. You never get an empty field because a translation is missing.
- Without
locale, or withlocale=en-US, you get the original values. - The response's
localeproperty says which locale was applied.
In the example above, excerpt (a textarea) is translated, body (an html field) is not, and featured (a boolean) is not translatable.
Supported locales
| Code | Language | Code | Language |
|---|---|---|---|
en-US | English (base) | ru-RU | Russian |
en-GB | English (UK) | nl-NL | Dutch |
es-ES | Spanish | sv-SE | Swedish |
fr-FR | French | no-NO | Norwegian |
de-DE | German | da-DK | Danish |
it-IT | Italian | fi-FI | Finnish |
pt-PT | Portuguese | pl-PL | Polish |
pt-BR | Portuguese (Brazil) | tr-TR | Turkish |
ja-JP | Japanese | ar-SA | Arabic |
zh-CN | Chinese (Simplified) | hi-IN | Hindi |
ko-KR | Korean |
Codes are case-sensitive. Anything else is rejected: 400 over REST with Unsupported locale "fr". Use a code like en-US or fr-FR., and a BAD_USER_INPUT error over GraphQL. A supported code your workspace hasn't enabled simply has no translations, so it returns the original text.
Which languages editors can translate into is set in the dashboard under Settings → Localization.
Locale versus language
Entries also have a language, and the API accepts a language parameter. They do different things:
localechooses which translation of an entry's text fields to return. It never changes which entries you get.languagefilters entries by the language they were written in. On REST it defaults toen-US.
For a site that shows the same entries in several languages, use locale. See Querying.
A multilingual site
1const API_URL = 'https://api.graphcms.io/v1';23export async function getPost(slug, locale = 'en-US') {4 const params = new URLSearchParams({ locale });5 const response = await fetch(`${API_URL}/content/blog-posts/${slug}?${params}`, {6 headers: { Authorization: `Bearer ${process.env.GRAPH_API_KEY}` },7 });8 if (response.status === 404) return null;9 const { data } = await response.json();10 return data;11}1213// /fr/blog/hello-world14const post = await getPost('hello-world', 'fr-FR');