Question

When using english the following URL should apply:

http://example.org/services/myservice/

When using another language, the following URL should apply:

http://example.org/sirvici/misirvice/

Any easy/standard way we should handle this withing Yii ?

Était-ce utile?

La solution

Yes you can do this in Yii but you will sacrifice:

  • Automatic Controller/Action mapping (depending how this works out)
  • A little speed due to the extra work load on every request.

If your still OK with that then you can go ahead with it. You need to create a custom URL rule and have it process every URL, this is well documented. Then you need to manually strip the URL apart (by also well documented methods) and translate each part from the users currently selected language ( you will need to know this unless you want to go through the hell of trying to guess a language O.o ). You now have the translations for each part of the URL. Congrats.

Heres the part that may or may not work
You can pass it back through the Yii URL parser to go through the automatic mapping of controllers and actions and parameters. This would mean your just doing a preparse on the URL and Yii continues from there.

If that can't work you'll have to build your own ( piggy back off Yii a little with CUrlRule etc. ) and do the mapping logic.

My Two Sense
For most Web Apps I wouldn't recommend this. It means you have multiple ways to access the same content, from very different URLs. This is bad thing in SEO terms and also in usability terms. It also doesn't provide you with a way of mapping those back to each other particularly easily to let google know not to index your content again. Plus I can't see that it gains you a whole lot. Most simpleton users won't pay attention to the URL bar, and even if it's in their native language most won't deduce much about the page and it's content from the wording of the URL.

Let me know if you proceed with this though, I'd like to know how it goes.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top