1

I'm working on a multilingual website where I have one structure called Products. Currently, this structure's URI format is configured like this:

{parent.uri ?? section.handle}/{slug}

Which returns URLs like this:

/products/topLevelProduct1
/products/topLevelProduct1/nestedProduct1
/products/topLevelProduct1/nestedProduct2

/products/topLevelProduct2
/products/topLevelProduct2/nestedProduct1
/products/topLevelProduct2/nestedProduct2

etc

The main thing I'm struggling with now is: how do I translate the top-level part of the URI (i.e. /products)? I guess I could use the built-in t() function on section.handle (is that even a good idea?) but that would still be overwritten by parent.uri.

2

Since the URL is specific for each multisite, simply do not use section.handle in the structure's URI definition, but go for the term you want as a string instead, e.g.

  • English: {parent.uri ?? 'products'}/{slug}
  • German: {parent.uri ?? 'produkte'}/{slug}
  • French: {parent.uri ?? 'produits'}/{slug}

and so on...

3
  • But then won't parent.uri still overwrite whatever I put instead of section.handle? – idix Nov 22 '20 at 20:55
  • Yes, it does, but only from the second level of the section and deeper. And since the first level already contains the translated version, this will be inherited to all levels below. parent.uri ?? 'products' means: take parent.uri if defined and not empty, otherwise go for the the string after ??. In the 2nd level and deeper, parent.uri is defined and will contain the translated string you need. – Matthias Redl-Mann Nov 22 '20 at 21:36
  • Ah of course, that's actually embarrassingly simple. I was so confused as to how parent.uri would be generated but it makes complete sense now that I see your explanation. Thanks! – idix Nov 23 '20 at 7:11

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.