2

I'm wondering if there's some build in function in Craft that can "translate" a URL the same as a string?

For example when I want to translate a static string I'll use the "t" Twig filer like so:

{{ "String"|t }}

Let's say I want to do the same, but with my localized URL's. Imaging this:

{{ url('a-url-slug')|t }}

Then in my translation file I can add different URL's that's localized (but loading the same template, I'm solving this using Routes).

2

Not sure if this is a good idea, but it does work. You simply got the syntax wrong, it should be:

{{ url('a-url-slug'|t) }}
  • Would you look at that. Wicked! I want to avoid having to run multiple IF-statements in my template for different URL's for different static localized links. – naboovalley Dec 4 '14 at 14:17
  • What about using macro or do it with a plugin? But can't you just avoid using static links at all and make all these URL become entries, that's what I would try to do, @naboovalley! – carlcs Dec 4 '14 at 14:19
  • Naa.. for example I have a button "Sign up" which is just inserted a little here and there in my templates. "/signup" for English and "/registrera-dig" for Swedish to keep SEO intact. Since I'm also translating the name of the button translating the link as well seems like a good approach. No? If I add a third language I can just update the translation-file. – naboovalley Dec 4 '14 at 14: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.