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
726 stars 33 forks source link

Multiple Files JSON File Structure - Localized File Collections #146

Closed CarloBu closed 1 month ago

CarloBu commented 1 month ago

Hello, it's me again, I'm trying add multiple-folders JSON structure to the Sveltia CMS so that the client can easily navigate and change localized navigation links: image

Sveltia CMS let me directly define files:

  - label: Navigation
    name: navigation
    create: false
    delete: false
    icon: link
    i18n: true
    format: json
    extension: json
    files:
      - file: 'src/locales/lt/headerData.json'
        label: 'header'
        name: 'headerData'
        fields:
          - label: "Links"
            name: "links"
            widget: "list"
            i18n: duplicate
            fields:
              - label: "Text"
              ...
      - file: 'src/locales/lt/footerData.json'
        label: 'footer'
        name: 'footerData'
        fields:   
          - label: "Links"
          ...
      - file: 'src/locales/lt/shared.json'
        label: 'shared'
        name: 'sharedData'
        fields:   
          - label: "Title"
          ...

This setup works well, and surprisingly, Sveltia CMS functions with a single JSON file for both locales. However, the localization library I use is highly opinionated and uses a multiple-folder JSON file structure. It also doesn't support nested folders, which leads to issues. This is the folder structure of localized json files that I setup. image

Would it be possible for you to add Multiple Folders JSON File Structure?

In this case, I would imagine the workflow: provide the file path of json file: i18n: true files:

I hope I explained my idea clearly.

kyoshino commented 1 month ago

Itโ€™s an open issue in Netlify/Decap CMS and on my todo list ๐Ÿ˜Ž

I was wondering how to solve this without breaking backward compatibility, but itโ€™s probably not hard to do it.

  1. Allow developers to use the {{locale}} template tag in the file path file path, e.g. src/locales/{{locale}}/shared.json
  2. Sveltia CMS enables multiple files/folders mode only if {{locale}} is used
  3. Sveltia CMS will parse and generate files for all the locales while replacing {{locale}}

Letโ€™s see if this works.

kyoshino commented 1 month ago

A workaround is suggested in the Netlify/Decap CMS issue, btw. You can use a folder collection with create: false and delete: false options, create a set of files, then it looks like a file collection.

CarloBu commented 1 month ago

Yes, I was thinking about a solution too that does not break the existing workflow, but your src/locales/{{locale}}/shared.json idea looks more logical and it's an elegant solution. {{locale}} does not break any existing logic. ๐Ÿ‘ and it's easy for the developer to follow.

CarloBu commented 1 month ago

Thank you for the workaround tip; it would work for most cases. However, in my situation, the footerData.json and header.json structures are different. :/

Actually, I'm using the same workaround for the Studio Pages YAML file: a folder collection with the create: false and delete: false options. All the page text is stored in single yaml file. It works perfectly for this case. I will do the same for all pages. That way, I can translate an entire page using a single well-defined YAML file, and it will look well-structured for the client.

kyoshino commented 1 month ago

Done in v0.29.0 ๐Ÿšข

CarloBu commented 1 month ago

whoah! Thanks a lot! It was the last barrier to building a functional fully i18n web personal stack. ๐Ÿ’ฏ

CarloBu commented 1 month ago

@kyoshino, serious question: how are you so productive with this project? Decap CMS has 500+ contributors, but their last commit was one month ago with a single feature. You added 4 features in the past 2 days.

kyoshino commented 1 month ago

I just want to ship a much better product than Decap CMS ๐Ÿ˜„ The i18n support is my particular concern since my own clients usually require a multilingual setup. A new client wants to have content in Japanese, English and French.

Not sure whatโ€™s happening with Decap. There are even no maintainer responses to new issues and PRs these days. Perhaps some of them have been laid off, or the company has strictly limited their time working on the project ๐Ÿค”

Most of the contributors are from the Netlify CMS era, btw.

CarloBu commented 1 month ago

Yeah, something strange is happening. There are over 500 open issues, and most of them with bug tags concern me. I think I have tried almost all the CMSs on the market, from closed-source Contentful to open-source Fresh Star Payload CMS. Most of them were overkill for my needs, so I narrowed my search to Git-based CMSs to avoid running a server for the CMS or being at the mercy of corporations that might pull the plug. In my humble opinion, the Keystatic CMS is great option, I liked the keystatic.cloud, but I didn't like the UX; it is too dev-centric with all the Git functions. Pages CMS is great too; I liked the UI a lot, but the i18n is non-existent and it lacks some advance features. After some testing, I thought I would stick with the half-decent Decap until I found your CMS. This is all I need, and the i18n is perfect. In Europe, i18n is a must. I'm glad I found your CMS. ๐Ÿ‘

CarloBu commented 1 month ago

@kyoshino, I think I encountered a bug when I try to upload an image with a localized file structure. It doesn't matter whether it is an md, yaml, or json file. The image won't upload when there is a localized file structure, but I can pick the existing image from the "All Asset" though. Additionally, I can't see my local images in the "All Asset" window.

To recreate, run this schema:

collections:
  - label: 'Test'
    name: 'test'
    create: true
    format: json
    extension: json
    i18n: duplicate
    editor:
      preview: false
    files:
      - file: 'src/content/{{locale}}/test.json'
        label: Test Data
        name: testData
        i18n: duplicate
        editor:
          preview: false
        fields:
          - label: Test Image
            name: testImage
            widget: object
            i18n: duplicate
            fields:
              - {label: Image, name: src, widget: image, i18n: duplicate}

https://github.com/sveltia/sveltia-cms/assets/145860771/3f500ef6-c91b-4d79-9f11-fa550e40d2ab

kyoshino commented 1 month ago

Will check.

kyoshino commented 1 month ago

Fixed in v0.29.1 ๐Ÿ™‡๐Ÿผ Two unrelated issues were involved.

CarloBu commented 1 month ago

that was fast! It's now working ๐Ÿ‘

kyoshino commented 1 month ago

Yeah, something strange is happening. There are over 500 open issues, and most of them with bug tags concern me.

I was checking the numbers last night. Sveltia CMS has already solved at least 90 (or 120 if you count duplicates) of these Netlify/Decap CMS issues. Will soon reach a milestone ๐Ÿ’ฏ

CarloBu commented 1 month ago

That's a crazy number for a single dev, especially considering that I constantly distract you from the 100-number goal :)