2

I am setting up a localized site that defaults to English (en_us). Alternate locales will have URLs such as example.com/fr

I would like to ensure that users browsing the French website don't accidentally end up back on the default locale. My problem is that some sections will not target the French locale but I would still like the URL to display the default, English content with the /fr/ URL.

If I uncheck targeting for that locale in my section settings, then browse to the entry (example.com/fr/section/entry) I get a 404. How can I display the default English entry content at that URL?

  • When you create entries in the default locale (english), that content will automatically be copied to all other locales (i.e. french). So you really shouldn't need to do anything, except to make sure that sections are targeted to the locales you wish to display them in (even if not translated). – Douglas McDonald Nov 3 '14 at 0:10
  • There's one problem with that approach, @Douglas. The copying only happens on the very first save. So in case you do edits on those entries, and you probably will, you have to make sure to do it exactly the same on all your locales. – carlcs Nov 3 '14 at 8:03
4

One solution (without needing to create a custom plugin) would be to add a lightswitch or checkbox field called useDefaultLocale, and add it to the field layout of any sections that you want to default to english. In your template you can test for the value of this field and display the default locale version of the content. You would of course need to target 'fr' locales for any sections that included this functionality.

{% if not craft.locale == 'en' and entry.useDefaultLocale %}
    {% set entry = craft.entries.section(entry.section).locale('en') %}
{% endif %}

Any content that is defined directly in the template using the translate filter (i.e. {{ 'Date'|t }} ) would still get translated of course, but maybe that's a good thing. There also may be a way to manually set the locale so as not to translate these as well, that I don't know about. If anyone knows, please leave a comment, and I'll add it to the answer.

Update: carlcs brings up a good point regarding SEO and duplicate content. To solve this you could define a canonical link using: (placed in the if clause above)

{% set canonical %}
    <link rel="canonical" href="{{ entry.url }} />
{% endset %}`

and then in the _layout template head:

{% if canonical is defined %}{{ canonical }}{% endif %}

The side effect is that some French users might get directed to the english url from search engines. Pick your poison I guess.

  • That's a solid approach, Douglas. You should probably add a canonical link to the entry in it's default locale to avoid down rating with search engines because of duplicate content?! – carlcs Nov 3 '14 at 21:15
  • @carlcs Good point. I added an update. The side affect is some French users may end up on the english site — but what do they expect for searching in 'frenglish'. ;) – Douglas McDonald Nov 3 '14 at 22:04

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.