decaporg / decap-cms

A Git-based CMS for Static Site Generators
https://decapcms.org
MIT License
17.69k stars 3.03k forks source link

i18n: Allow files with a subset of translations #6932

Open JMLFP opened 9 months ago

JMLFP commented 9 months ago

Issue

Right now the i18n support in Decap will create a file for every enabled locale even if no data was entered for this locale. This can be undesirable when the user would like to fallback to the default locale if content is not available in the user locale (or if translation will be done later). You can see the effects of this issue mentioned here: https://github.com/decaporg/decap-cms/issues/4480#issuecomment-947546677.

Example: if the user creates a new page and enters the content in the default locale (en), but leaves one of the other locales blank (es) the CMS will still commit a new-page.en.md and new-page.es.md. This means that new-page.es.md may show up on index pages and as a linked translation even though it's a blank file with just header data.

Proposed Solution

I suggest that we add a boolean configuration flag that would require manually enabling a translation. It would default to true to keep the existing behavior and keep backwards compatibility.

# config.yml
i18n:
  save_all_locales_by_default: false

This config flag could trigger an updated UI element that would require the content editor to enable a translation. If the translation is enabled, the translated file will be saved. If not, no translated file will be created:

image

Other Solutions

I have also thought about discarding the translation if certain fields are empty (for example, no body) - but this seems more likely to break workflows. Thoughts?

Final Thoughts

I am interested in cooperating on a PR to help implement a feature to resolve this issue, but I would appreciate some feedback on the architecture before I begin writing code :-)

martinjagodic commented 9 months ago

@JMLFP I like this idea. If you are willing to contribute a PR, that would be great.

I would rename the flag to save_all_locales. It's shorter and explains about the same. Like you said, default valuse is true to keep the current behavior.

i18n:
  save_all_locales: false # default is true

I am not sure what to do with the new UI element. We are talking about whether an MD file exists or not. That means that setting it to false should delete the file, which will delete all content. That should be very obvious to the user.

One option would be to set it to false for all locales when starting a new entry. When the user enters one i18n: true field, it switches to true automatically.

If the user sets it to false on a non-empty entry, we should display a warning that this will delete the file and therefore all i18n: true fields.

When enabling a translation back again, we have to be careful to include all i18n: duplicate from the default locale.

JMLFP commented 7 months ago

One option would be to set it to false for all locales when starting a new entry. When the user enters one i18n: true field, it switches to true automatically.

That's a good thought - that way the user doesn't need to do any extra steps and we don't need to clutter the UI with another option.