static-cms
static-cms copied to clipboard
i18n - metadata of the fields are saved according to `locale` positions when `default_locale` is set
Hello,
one strange thing just came up, while testing, i switched positions of locales inside i18n: { locales }
array. Previously they were like this ["cs", "en"]
. Because of the switch in the positions to ["en", "cs"]
, I had to set default_locale
in the config as I wanted to have the cs
value as default, it looks like everything works as expected, however, when I save (publish) the file, both of the files have the values from en
locale.
My current config:
{
"local_backend": true,
"publish_mode": "editorial_workflow",
"backend": {
"name": "github",
"base_url": "http://localhost:3000/",
"repo": "dallyh/daliborhon.dev",
"branch": "blog-test",
"commit_messages": {
"create": "Create {{collection}} \"{{slug}}\"",
"update": "Update {{collection}} \"{{slug}}\"",
"delete": "Delete {{collection}} \"{{slug}}\"",
"uploadMedia": "Upload \"{{path}}\"",
"deleteMedia": "Delete \"{{path}}\""
}
},
"media_folder": "public/assets/uploads/",
"public_folder": "/assets/uploads/",
"site_url": "http://localhost:4321/",
"slug": {
"clean_accents": true
},
"i18n": {
"structure": "multiple_folders",
"locales": [
"en",
"cs"
],
"default_locale": "cs"
},
"collections": [
{
"name": "posts",
"label": "Posts",
"label_singular": "Post",
"folder": "src/content/posts",
"create": true,
"delete": true,
"i18n": true,
"slug": "{{year}}-{{month}}-{{day}}-{{slug}}",
"sortable_fields": {
"fields": [
"title",
"pubDateTime"
],
"default": {
"field": "pubDateTime"
}
},
"summary_fields": [
"title",
"pubDateTime",
"hidden"
],
"view_filters": {
"filters": [
{
"name": "hidden",
"label": "Hidden posts",
"field": "hidden",
"pattern": true
},
{
"name": "visible",
"label": "Visible posts",
"field": "hidden",
"pattern": false
}
]
},
"view_groups": {
"groups": [
{
"name": "Year",
"label": "Year",
"field": "pubDateTime",
"pattern": "\\d{4}"
},
{
"name": "visibility",
"label": "Visibility",
"field": "hidden"
}
]
},
"fields": [
{
"name": "title",
"label": "Title",
"widget": "string",
"i18n": true
},
{
"name": "postId",
"label": "Post ID (UUID)",
"widget": "uuid",
"i18n": "duplicate"
},
{
"name": "description",
"label": "Description",
"widget": "string",
"i18n": true
},
{
"name": "author",
"label": "Author",
"widget": "string",
"default": "Dalibor Hon",
"i18n": "duplicate"
},
{
"name": "tags",
"label": "Tags",
"widget": "relation",
"i18n": true,
"collection": "tags",
"multiple": true,
"value_field": "id",
"search_fields": [
"id"
],
"display_fields": [
"languages.cs",
"languages.en"
]
},
{
"name": "language",
"label": "Language",
"widget": "select",
"i18n": true,
"options": [
{
"label": "Čeština",
"value": "cs"
},
{
"label": "English",
"value": "en"
}
]
},
{
"name": "hidden",
"label": "Hide post on the website",
"widget": "boolean",
"default": false,
"i18n": "duplicate",
"required": false
},
{
"name": "featured",
"label": "Featured",
"widget": "boolean",
"default": false,
"i18n": true,
"required": false
},
{
"name": "ogImage",
"label": "OG Image",
"widget": "image",
"i18n": "duplicate",
"choose_url": true,
"required": false
},
{
"name": "pubDateTime",
"label": "Publish Date",
"widget": "datetime",
"i18n": "duplicate",
"date_format": true,
"time_format": true
},
{
"name": "modDatetime",
"label": "Modified Date",
"widget": "datetime",
"i18n": "duplicate",
"required": false,
"date_format": true,
"time_format": true,
"default": ""
},
{
"name": "body",
"label": "Body",
"widget": "markdown",
"show_raw": true,
"i18n": true
}
]
},
{
"name": "tags",
"label": "Tags",
"label_singular": "Tag",
"folder": "src/content/tags",
"identifier_field": "id",
"create": true,
"delete": true,
"i18n": false,
"slug": "{{id}}",
"extension": "json",
"fields": [
{
"name": "id",
"label": "Tag dentifier",
"widget": "string",
"i18n": "duplicate"
},
{
"name": "languages",
"label": "Translations",
"widget": "object",
"fields": [
{
"name": "cs",
"label": "Čeština - tag translation",
"widget": "string",
"i18n": false
},
{
"name": "en",
"label": "English - tag translation",
"widget": "string",
"i18n": false
}
]
}
]
}
]
}
On this video, notice how the "cs" locale title "Title but in Czech locale" gets replaced by it's English version, but not only the Title, all of the fileds are saved from the English version
https://github.com/StaticJsCMS/static-cms/assets/6968534/862da248-3bc6-48d0-92cd-de48342d53fc
The file gets saved with the "cs" title as slug in both folders:
However the metadata for both files are the same. When I switch the locales back, that is ["cs", "en"]
everything works as expected.
I guess this is because the first position in the locales
array dictates the default locale, and somehow the config parameter default_locale
is missed in some cases.
This is on version 4.0.0.