1

I'm building a multi-lingual site and have found Craft's locales / translatable fields useful for setting up structures where each page will have a translated version. However, for at least one of the Channel sections it would make more sense to have separate entries for each locale, rather than having each entry being translatable and appearing in all locales.

This seems doable by disabling all but one of the locales on each entry in the section, but the problem I'm having is that if an entry has required fields, I can't save it if these fields are empty, even if they're only empty in a locale that I'm trying to disable. (eg. I want to have a Spanish-only post, but when I try to disable the English version I can't save the post because the English version has required fields that aren't filled in...)

It seems I either have to make my required fields non-required, or fill them with spurious stuff in the locale I want to disable. I'm sure there must be a way of making required fields work with multi-lingual posts, but I can't figure out quite how... I'd be grateful for any pointers here!

  • Hmmm... I'd actually try and do a feature request to P&T and ask them if they could implement a setting to disable new entries in a section by default. – carlcs Oct 13 '14 at 12:18
  • 1
    I think you can do this: in the section config page you can set default locales for new entries. I've currently set them to default to off for all locales, which partly solves my problem. – Nick F Oct 13 '14 at 14:07
  • 1
    Oh that's good, I had no idea one can actually already do this. Why does this solve your problem only partly, what else is missing? – carlcs Oct 13 '14 at 14:35
  • Basically, it seems to work ok with creating new posts (I can now create them with content only in one locale), but if I have an existing post in multiple locales, I can't disable a locale without having to fill in the required fields. – Nick F Oct 13 '14 at 16:08
  • For existing ones you could do that in the DB or, if there aren't many, delete and create them from scratch. But good to hear that you found a solution, Nick! – carlcs Oct 13 '14 at 16:25
2

I don't know if you re-use the fields you're using in that channel in other sections and if you do, my suggestion might not work for you, but here's what you could do:

Set all fields to be "not translatable" and if content is entered in one locale it will get synced to all locales. Thereby all required fields will always be filled out and disabling individual "dummy versions" is no problem any more.

  • Ah, unfortunately one of the fields does need to be translatable - it's a matrix field that's widely used across the site, including on pages where it needs to be fully replaceable on entries for different locales. – Nick F Oct 13 '14 at 14:09
  • OK, but if that matrix field is the only field that is shared, you could set it to be not required. – carlcs Oct 13 '14 at 14:45
  • But that's the exact problem I'm having: how to use it across locales while keeping it as required! (cf. last paragraph of my question) – Nick F Oct 13 '14 at 16:04
  • Yeah I know, but I was thinking you could do an exception for that one matrix field ;) – carlcs Oct 13 '14 at 16:26
1

Why don't you leave the entries enabled in all locales and just don't load them in the templates.

{% if craft.locale == 'fr' %}
    {% set entries = craft.entries.section('news-fr') %}
{% elseif craft.locale == 'en' %}
    {% set entries = craft.entries.section('news-en') %}
{% elseif craft.locale == 'de' %}
    {% set entries = craft.entries.section('news-de') %}
{% endif %}
  • I'm not sure I quite follow this. Is there something special about the '-lang' suffix on a section? Or are you suggesting multiple channels? I'm keen to have them all in the same multilingual section if possible, because nowhere else on the site has different sections for different locales. – Nick F Oct 13 '14 at 14:12
  • Yes, I actually thought that this is what you're doing, different channels for your locales. But yeah, if you have them all in one channel, then this doesn't work, of course. :D – carlcs Oct 13 '14 at 14:40
0

The solution that ended up working for me was to just turn off all default locales for the section in question.

The problem was that if a locale is on by default, then it seems it's impossible to turn it off until you've filled in all the required fields. But if no locale is active by default, you can just create only the one(s) that you need, and you don't run into the problem of trying to deactivate any of the others (since their status is off by default).

I'd thought that having a default locale would save admins time when posting, but actually with all locales off, no extra steps are added to the process of creating a post, and you actually avoid the step of (and potential problems with) turning off non-required locales.

  • Quick note for anyone looking for these settings. They are not in the config file, but in the admin. – Martin Jan 16 '15 at 9:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.