Jump to content

Multilingual pages


Thomas.

Recommended Posts

There isn't a recommended way. I too have a multilingual site and have run into this roadblock (and mentioned it a few times here) since IPS4 was released.

Different approaches you could take and which I use (or have used):

1) Create language strings for your content and then call those language strings within your pages. The downside is that you have to know how to create language strings and there isn't a feature to do that, outside of meddling with the database or creating your own app or plugin.

2) Add the following style code to your templates and pages. (In this example I'm using Esperanto and other, where other happens to be English for my site but could be a range of languages.)

{{if \IPS\Member::loggedIn()->language()->short === 'eo_XX.UTF-8' }}
<p><em>HTML to display for Esperanto</em></p>
{{else}}
<p><em>HTML to display for another language, including English</em></p>
{{endif}}

3) Add a variable to your globalTemplate which will change its value depending on your language, and then append that variable to your blocks, images etc. In my case, I generate the first two letters of the language code (en and eo) using the variable, then have blocks, images etc stored with the variable name present, so "block-name-en" and "block-name-eo", and "my-image-en.jpg" and "my-image-eo.jpg", etc.

So, in my globalTemplate I have

{{\IPS\Settings::i()->lingvo = substr(\IPS\Member::loggedIn()->language()->short, 0, 2);}}

, which creates a variable called lingvo, which takes the values en and eo. And then in my templates I call

{block="block-name-{$lingvo}"}

and

<img src='path/to/my-image-{$lingvo}.jpg' >

Be warned, though, that this approach doesn't seem to work in other templates called into globalTemplate, ie in the footer or logo. In this environment approach 2 works, although I use a different approach which is a mix of 1 and 3:

4) As with 3, store your images with slightly different names. Then create a language string to reflect those differences. Your image addresses become something like

<img src='path/to/image-{lang="lang_code"}.jpg' />

The downside is that, again, you have to know how to create a language string. And for some reason this doesn't work with blocks.

Link to comment
Share on other sites

Well, creating multilingual pages seems such a trivial thing to do, I really feel IPS should address this. In my opinion, the ability to create custom language strings (perhaps tied to a particular page) would be the 'cleanest' method.

Thank you for pointing out the different approaches you ended up taking so extensively, great examples too! Looks like I'll be going with option 2 in this case (it would be kind of silly to create a new plugin just to create a few multilingual pages :p).

Link to comment
Share on other sites

52 minutes ago, Thomas. said:

Well, creating multilingual pages seems such a trivial thing to do, I really feel IPS should address this. In my opinion, the ability to create custom language strings (perhaps tied to a particular page) would be the 'cleanest' method.

We might be in luck regarding this. I had a chat with one of the IPS developers about something else and I mentioned this problem. He replied that they might look into creating some sort of interface for people to add their own custom language strings in the ACP in a future version. Might is better than won't ^_^

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...