2

I disabled translation for Spanish and it returned 404 page.

I set all my fields to translatable and By default craft translations are empty.

enter image description here

How can I return English by default? Using Spanish locale

enter image description here

Thanks! :)

2

By disabling a locale for an entry you are removing the automatically created route for this entry and locale (→ docs for routing).

But what you can do, is to diable the automatic routing (uncheck "Entries in this section have their own URLs" in the section settings) and add the same routes as custom dynamic routes manually.

news/{slug}news/_entry

Those manual routes won't 404 for disabled entries and you can have some logic in your _entry.html template.

{% set entry = craft.entries.section('news').slug(slug).first() %}

{% if not entry %}
    {% set entry = craft.entries.section('news').slug(slug).locale('en').first() %}
    {% set duplicateContent = true %}
{% endif %}

{% if not entry %}
    {% exit 404 %}
{% endif %}

I would also recommend to set your meta tags accordingly and make search engines aware of the duplicated content. I updated the code with a new variable definition, test if it is defined in your _layout main template.

| improve this answer | |
  • Thanks! But all I wanted to do is get English translations if the Spanish translation is empty. – user4236 Oct 26 '15 at 5:02
  • Yeah, so this is not what you want? I think it's the only way to get around the 404 for disabled entries. Manual routes and the exit 404 tag is no uncommon practice in Craft! – carlcs Oct 26 '15 at 5:17
  • You could also introduced a (non translated) lightswitch field, check its value in the template and if it's enabled load the default locale's content (or 404). – carlcs Oct 26 '15 at 5:23

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.