3

I'm working on a bilingual site (en and cy) and have a news channel with entry urls news/{slug} and the translated cy/newyddion/{slug}. Everything is working well with entries and if the url is accessed without the slug then a list of entries is displayed.

However, when accessing without the slug the translation of news is cy/news not cy/newyddion as required. If I attempt to access cy/newyddion I get a 404 not found error. I have tried different solutions such as adding files in templates/cy/newyddion but still get 404s.

The only way I've got it to work is by adding a new single section named news which has no content and loads the news index template and renaming the news section handle to avoid conflicts.

What I would like to know is if there is a better way of accomplishing this as it seems like a cumbersome way of doing it.

2 Answers 2

3

In my experience, the easiest and best to maintain way to do this is to use entries only. If you make that news index page an entry (e.g. structure or single section) it is as easy as entering your translated slug in that entry's CP.

Another advantage is that you can add fields to that entry (e.g. to edit the meta description or some copy), so this can make sense in many cases, not just for multilingual routing.

5
  • Ohh... and this works nicely with the language switch I use.
    – carlcs
    Commented Oct 23, 2014 at 9:15
  • That's the only way I've got it to work properly too, I can see the benefits of using entries in this way (adding/editing fields) and it does no harm in this case, but it seems a bit cumbersome just to provide a translated url, especially considering how well all the other multilingual aspects of Craft work. I now have a single "news" and a channel "club news" to cover one area of the site. If this is indeed the best way of tackling the problem it would be good if Craft could provide an "index" single automatically (or at least the option) to keep everything together.
    – Gogster
    Commented Oct 23, 2014 at 9:40
  • In fact I'd recommend to not use a single but a structure section, containing entries not just for index pages but also other "single" pages.
    – carlcs
    Commented Oct 23, 2014 at 9:58
  • @Gogster when I first encountered this "limitation" with translating slugs I too didn't like it. But now I don't see it as one any more, because I use a structure (with multiple entry types) anyways for the navigation and "single" cotent pages.
    – carlcs
    Commented Oct 23, 2014 at 10:02
  • 1
    These Q/A might be of interest for you, if you start using this approach: "Multi-lingual site navigation made of singles, channels and structure" and "Add home page to a structure?". Slightly different approach but also worth looking into: "Would you use a Structure as navigation over multiple sections (channel entries, indexes and singles)?".
    – carlcs
    Commented Oct 23, 2014 at 10:27
1

You can create routes in the CP in settings>routes and set the locale to which that route applies. For example in the settings window:

If the URI looks like this: newyddion (with locale dropdown set to 'cy')
Load this template: news (or 'news/index.html')

For more information have a look at the dynamic routes documentation.

5
  • Thanks for your reply. I'd already tried that too and it didn't work so after your reply I started suspecting that the routing wasn't working as it should. On testing though I found that I should be entering the uri without the locale so just 'newyddion' not 'cy/newyddion' as the latter was matching the url 'cy/cy/newyddion'. Cool, much better!
    – Gogster
    Commented Oct 23, 2014 at 7:34
  • The only snag I have now is that my language switcher provides the url 'newyddion' as the translation of 'cy/newyddion' instead of 'news'
    – Gogster
    Commented Oct 23, 2014 at 7:42
  • @Gogster I tried to solve this exact problem of translated routes some days ago, see my answer in this Q/A. Not nice, but it did work! :)
    – carlcs
    Commented Oct 23, 2014 at 9:01
  • I didn't know about not needing the cy. Makes sense. I have updated the answer, so as not to confuse others. Commented Oct 23, 2014 at 13:44
  • To be honest though, I think I prefer carlcs' answer better. Seems like a much more useful approach in general. Commented Oct 23, 2014 at 13:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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