sveltia / sveltia-cms

Alternative to Netlify/Decap CMS. Fast, lightweight, Git-based headless CMS. Modern UX, first-class i18n support, open source & free. Made with Svelte.
MIT License
750 stars 34 forks source link

Unclear i18n issue with multiple_files fails fatally #63

Closed privatemaker closed 9 months ago

privatemaker commented 9 months ago

I have Sveltia configured with the following i18n options:

locale: 'en'
i18n:
  structure: "multiple_files"
  locales: ["en", "de"]
  default_locale: "en"

My files are organized:

content/
  - index.en.md
  - index.de.md
content/articles/
  - file1.de.md
  - file2.de.md
  - file3.de.md

The error which is showing up in my console which makes entire Sveltia CMS fail fully is:

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'en')
    at sveltia-cms.js:222:3765
    at Array.map (<anonymous>)
    at jo (sveltia-cms.js:222:3731)
    at sveltia-cms.js:437:140954
    at u (sveltia-cms.js:437:141021)
    at sveltia-cms.js:437:141239
    at String.replace (<anonymous>)
    at v1 (sveltia-cms.js:437:141211)
    at Array.v7 (sveltia-cms.js:437:145714)
    at Pe (sveltia-cms.js:1:1473)

The only thing I thought might cause this was my articles/ files were all de while default lang is en but after a few attempts to reconfigure and harmonize thing the issue persists. Switching default language does not help either.

After testing the exact same config.yaml + Hugo site content with decap-cms@3.0.9 it seems to load fine there

kyoshino commented 9 months ago

Yeah, Sveltia should just skip nonexistent *.en.md files. The fix is coming.

kyoshino commented 9 months ago

I couldn’t reproduce the exact issue, which might be related to the relation widget, but I have fixed some issues with missing default locale content. The fix is now in. Please test on your side and let me know if it works!

privatemaker commented 9 months ago

As usual, thanks for super fast investigation + fix 😄

... might be related to the relation widget

Possible. That widget is being used in this collection. what you pushed fixes Sveltia CMS from failing fatally. However, it does not show listings whereby only one language type file exists, example:

file1.de.md
file1.en.md
file2.de.md

The item list shows only file1 and not file2

kyoshino commented 9 months ago

Hmm, I thought I’d fixed the entry listing issue as well. Will check again.

kyoshino commented 9 months ago

Not sure how to reproduce the issue. By the way, do you have any reason you can’t (or don’t) have file2.en.md? Sveltia CMS creates the file anyway even if (there are no required fields and) the content is empty.

If you really need to omit the file, I could implement something like https://github.com/decaporg/decap-cms/issues/6932

That said, disabling the default locale, not a translation, may still cause some issues.

kyoshino commented 9 months ago

I’m closing the issue as the original fatal error has been solved. Feel free to open a new issue to follow up!

privatemaker commented 9 months ago

Makes sense to close the issue 👍🏻

do you have any reason you can’t (or don’t) have file2.en.md

There are a few cases in my Hugo deployments where this is likely a case:

  1. Sites made without Sveltia / Decap where i18n coverage is uneven between content
  2. Only one language file is generated via some automated process
  3. Language files are inconsistent due to media types (in this case invoices)

For situations 1. and 2. yah, it's an issue as one can't fill in the gaps with current UI. For situation 3. the suggested implementation in Decap looks perfect!

kyoshino commented 9 months ago

For situation 3. the suggested implementation in Decap looks perfect!

Okay, I’ll get this done next week.

kyoshino commented 8 months ago

I made it: https://github.com/sveltia/sveltia-cms#disable-non-default-locale-content

One of my clients may want to use it, so it’s a good addition ☺️

privatemaker commented 8 months ago

Nice :smile: thanks for implementing this. I still can't get Sveltia CMS to show entries for items with non-uniform items, but I will keep testing this out!