-
Notifications
You must be signed in to change notification settings - Fork 73
Make field label
and default
options localizable
#403
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Sveltia already implements first-class i18n support on top of the Decap CMS i18n support. Please set up i18n with Decap CMS first and migrate to Sveltia CMS. Then let me know if something is not working. I’m happy to provide help with features specific to Sveltia CMS, but I can’t help set up basic i18n configuration. |
Hi, i18n works but you can't modify the defaults or labels of fields as far as I know. That would be useful if someone has spcific tags/categories or different labels for each language. Therefore I wanted to use a different approach. Just using i18n works but has some drawbacks. I at least didn't find any documentation on how one would implement that with sveltia's i18n |
Maybe I now understand what you want. If you want to localize tags/categories, create a separate collection for these tags/categories, and use the relation widget to refer to it, instead of using the list field and hardcoding defaults in the configuration. Unfortunately, localizing the |
Thank you very much. That sounds like a great idea. It at least solves my current problem since localizing the labels is kind of optional. I'd however recommend leaving this issue open since this feature would in my opinion be quite helpful. The approach that Hugo uses should solve this without any problems. It could enable localizing labels and allow configuring defaults without using the relation widget. |
I said I can’t help but here’s what I’ve got: Sample configuration{
config: {
load_config_file: false,
backend: {
// base_url: 'https://sveltia-cms-auth.servedsmart-6knt8ma96knt8ma9.workers.dev',
// branch: 'cms',
// name: 'github',
// repo: 'servedsmart/servedsmart.top',
name: 'test-repo',
},
collections: [
{
create: true,
i18n: true,
editor: { preview: false },
fields: [
{
name: 'label',
label: 'Label',
i18n: true,
},
],
slug: '{{uuid_short}}',
folder: 'content/tags',
format: 'toml-frontmatter',
label: 'Tags',
name: 'tags',
path: '{{slug}}/index',
},
{
create: true,
i18n: true,
editor: { preview: false },
fields: [
{
name: 'label',
label: 'Label',
i18n: true,
},
],
slug: '{{uuid_short}}',
folder: 'content/categories',
format: 'toml-frontmatter',
label: 'Categories',
name: 'categories',
path: '{{slug}}/index',
},
{
create: true,
i18n: true,
editor: { preview: true },
slug: '{{title | localize}}',
fields: [
{
label: 'Title',
name: 'title',
widget: 'string',
i18n: true,
},
{
default: '{{now}}',
format: 'YYYY-MM-DDTHH:mm:ssZ',
label: 'Date',
name: 'date',
picker_utc: true,
widget: 'datetime',
i18n: 'duplicate',
},
{
label: 'Description',
name: 'description',
required: false,
widget: 'string',
i18n: true,
},
{
label: 'Summary',
name: 'summary',
required: false,
widget: 'string',
i18n: true,
},
{
label: 'Categories',
name: 'categories',
required: false,
multiple: true,
widget: 'relation',
collection: 'categories',
value_field: '{{slug}}',
display_fields: ['label'],
i18n: 'duplicate',
},
{
label: 'Tags',
name: 'tags',
required: false,
multiple: true,
widget: 'relation',
collection: 'tags',
value_field: '{{slug}}',
display_fields: ['label'],
i18n: 'duplicate',
},
{
default: false,
label: 'Draft',
name: 'draft',
widget: 'boolean',
i18n: 'duplicate',
},
{
label: 'Body',
modes: ['raw', 'rich_text'],
name: 'body',
required: false,
sanitize_preview: true,
widget: 'markdown',
i18n: true,
},
],
folder: 'content/employees',
format: 'toml-frontmatter',
index_file: { name: '_index' },
label: 'Employees',
media_folder: '',
name: 'employees',
path: '{{slug}}/index',
public_folder: '',
},
{
create: true,
i18n: true,
editor: { preview: true },
slug: '{{title | localize}}',
fields: [
{
label: 'Title',
name: 'title',
widget: 'string',
i18n: true,
},
{
default: '{{now}}',
format: 'YYYY-MM-DDTHH:mm:ssZ',
label: 'Date',
name: 'date',
picker_utc: true,
widget: 'datetime',
i18n: 'duplicate',
},
{
label: 'Description',
name: 'description',
required: false,
widget: 'string',
i18n: true,
},
{
label: 'Summary',
name: 'summary',
required: false,
widget: 'string',
i18n: true,
},
{
label: 'Categories',
name: 'categories',
required: false,
multiple: true,
widget: 'relation',
collection: 'categories',
value_field: '{{slug}}',
display_fields: ['label'],
i18n: 'duplicate',
},
{
label: 'Tags',
name: 'tags',
required: false,
multiple: true,
widget: 'relation',
collection: 'tags',
value_field: '{{slug}}',
display_fields: ['label'],
i18n: 'duplicate',
},
{
default: false,
label: 'Draft',
name: 'draft',
widget: 'boolean',
i18n: 'duplicate',
},
{
label: 'Body',
modes: ['raw', 'rich_text'],
name: 'body',
required: false,
sanitize_preview: true,
widget: 'markdown',
i18n: true,
},
],
folder: 'content/posts',
format: 'toml-frontmatter',
index_file: { name: '_index' },
label: 'Posts',
media_folder: '',
name: 'posts',
path: '{{slug}}/index',
public_folder: '',
},
{
create: true,
i18n: true,
editor: { preview: true },
slug: '{{title | localize}}',
fields: [
{
label: 'Title',
name: 'title',
widget: 'string',
i18n: true,
},
{
default: '{{now}}',
format: 'YYYY-MM-DDTHH:mm:ssZ',
label: 'Date',
name: 'date',
picker_utc: true,
widget: 'datetime',
i18n: 'duplicate',
},
{
label: 'Description',
name: 'description',
required: false,
widget: 'string',
i18n: true,
},
{
label: 'Summary',
name: 'summary',
required: false,
widget: 'string',
i18n: true,
},
{
label: 'Categories',
name: 'categories',
required: false,
multiple: true,
widget: 'relation',
collection: 'categories',
value_field: '{{slug}}',
display_fields: ['label'],
i18n: 'duplicate',
},
{
label: 'Tags',
name: 'tags',
required: false,
multiple: true,
widget: 'relation',
collection: 'tags',
value_field: '{{slug}}',
display_fields: ['label'],
i18n: 'duplicate',
},
{
default: false,
label: 'Draft',
name: 'draft',
widget: 'boolean',
i18n: 'duplicate',
},
{
label: 'Body',
modes: ['raw', 'rich_text'],
name: 'body',
required: false,
sanitize_preview: true,
widget: 'markdown',
i18n: true,
},
],
folder: 'content/services',
format: 'toml-frontmatter',
index_file: { name: '_index' },
label: 'Services',
media_folder: '',
name: 'services',
path: '{{slug}}/index',
public_folder: '',
},
{
create: true,
i18n: true,
editor: { preview: true },
slug: '{{title | localize}}',
fields: [
{
label: 'Title',
name: 'title',
widget: 'string',
i18n: true,
},
{
default: '{{now}}',
format: 'YYYY-MM-DDTHH:mm:ssZ',
label: 'Date',
name: 'date',
picker_utc: true,
widget: 'datetime',
i18n: 'duplicate',
},
{
label: 'Description',
name: 'description',
required: false,
widget: 'string',
i18n: true,
},
{
label: 'Summary',
name: 'summary',
required: false,
widget: 'string',
i18n: true,
},
{
label: 'Categories',
name: 'categories',
required: false,
multiple: true,
widget: 'relation',
collection: 'categories',
value_field: '{{slug}}',
display_fields: ['label'],
i18n: 'duplicate',
},
{
label: 'Tags',
name: 'tags',
required: false,
multiple: true,
widget: 'relation',
collection: 'tags',
value_field: '{{slug}}',
display_fields: ['label'],
i18n: 'duplicate',
},
{
default: false,
label: 'Draft',
name: 'draft',
widget: 'boolean',
i18n: 'duplicate',
},
{
label: 'Body',
modes: ['raw', 'rich_text'],
name: 'body',
required: false,
sanitize_preview: true,
widget: 'markdown',
i18n: true,
},
],
folder: 'content/terms',
format: 'toml-frontmatter',
index_file: { name: '_index' },
label: 'Terms',
media_folder: '',
name: 'terms',
path: '{{slug}}/index',
public_folder: '',
},
],
i18n: { default_locale: 'de', locales: ['de', 'en'], structure: 'multiple_files' },
media_folder: 'static/img',
media_libraries: {
default: {
config: {
transformations: {
raster_image: { format: 'webp', height: 2048, quality: 85, width: 2048 },
svg: { optimize: true },
},
},
},
},
public_folder: '/img',
publish_mode: 'simple',
show_preview_links: false,
site_url: 'https://cms.servedsmart.top/',
slug: { clean_accents: true, encoding: 'ascii', sanitize_replacement: '_' },
},
}
I believe defaults, especially for tags/categories that can be added/renamed later, should never be hardcoded within the configuration. But yes, hypothetically I could make {
"widget": "string",
"name": "description",
"label": { "en": "Description", "de": "Beschreibung" },
},
{
"widget": "list",
"name": "categories",
"label": { "en": "Categories", "de": "Kategorien" },
"default": {
"en": [
"car repair",
"tuning",
"team",
"internal",
"legal",
"announcement",
"service"
],
"de": [
"autoreparatur",
"tuning",
"mitarbeiter",
"unternehmensintern",
"rechtliches",
"ankündigung",
"dienstleistung"
],
},
}, |
label
and default
options localizable
You can of course use localized tags/categories for links on your site for SEO purposes. But within data, it’s always better to use a permanent value when connecting different collections using a relation field. UUID slugs won’t change from time to time, so it’s suitable for Hardcoding makes things just difficult; what if you want to change “car repair” to “auto repair” later? The latter is common here in Canada. It can be done easily with a relation field connected with a UUID slug, but you have to rewrite many entries if tags/categories are hardcoded. I’m not familiar with the structure of Hugo as I’m no longer an active user of it. |
Uh oh!
There was an error while loading. Please reload this page.
Hello,
I have noticed that it isn't possible to localize a lot of the entries in the configuration. I would mainly use this for collections, but it might also be feasible to implement this for other config options.
I tried using an approach layed out here, I'm not sure if the same behaviour can be observed in Decap CMS, but when opening Sveltia I just get a list of the entries in collections with the different localized labels. Switching the locale through the select widget will also not change the label of specified fields. As far as I know, there is no other option that would enable users to customize that behaviour or other config options.
Since sveltia already has a language switcher button in the editor if you use i18n: true, I'd suggest adding logic that allows a user to add localized entries to fields in their collections or other config keys.
This is an example of how hugo does this. It should be possible to implement a similar approach here.
This is my current auto-generated configuration for reference.
The text was updated successfully, but these errors were encountered: