Wednesday, March 24, 2010

Multiple Languages - a “How-To” using PutYourLightsOn’s Multi-Language module

I’m building a dual-language website now that will feature English and Dutch, and I’ve been digging and culling information on this for a few weeks now. I’m putting my experiences down into this “How-To” help others stuck at 2am.

The focus on this is specifically using the Multi Language Module from PutYourLightOn but there are enough smaller tips in here that it’s worth putting in one place. There are also other means to do multiple languages that don’t require a commercial module, but this worked for me. YMMV. If this isn’t the right place, admins, let me know and I’ll move it.

Caveats:
• This was developed for the EE 1.6x but it should be very similar in 2.1x installations
• Requires the use of jQuery for the Control Panel extension and the commercial Multi-Language Module from PutYourLightsOn.net
• This presumes 2 languages, but more can be used following the guide
• We try for pure EE-solutions whenever possible - no hacking or php/js and exposing the security
• Since we’re describing EE tags, normally they can’t be displayed inline (because the system immediately processes them). Using the code tag will ruin the reading, so when you see something like [base_path] realize the parenthesis are replaced by brackets.

Start - Setting-up the different language paths and removing the index.php from the URL:

We’re presuming you have a default language (in my case English) set in your General Preferences > Site Language setting. All you need to do is add the module, add the extra languages and add some files to make sure the [base_url] starts out of the correct path.

• Install the module (follow the directions on that - easy enough)

• Add a additional language in the module using the correct ISO 639-1 code for your extra language (en = english, nl = dutch, es = spanish, etc)

• Add a directory to the root of your site for each additional language using the matching ISO 639-1 code. This is always lower-case.

• Modify your path.php file to add 2 new variables [base_url] & [user_language]. The important bit is at the bottom:

$global_vars = array(); // This array must be associative 

changes to point to your default language (replace “mysite” with your site and your particular base language)

// $global_vars = array(); // This array must be associative
    
$global_vars = array(
    
"base_url" => "http://www.mysite.com/"
    
"user_language" => "en"
    
); 

• Now add .htaccess to the root using the EXCLUDE LIST method of removing the index.php. You’re including only the directories you want the system to look into:

RewriteEngine on
RewriteCond 
$!^(nl|css|images|system|themes|index\.php[NC]
RewriteRule 
^(.*)$ /index.php/$1 [L] 

• The module comes with spanish and italian directory file example - use one of them and move the 3 files to the server
- index.php = you can leave alone
- .htaccess = modify the path in the Rewrite Rule to point to your desired language, in my case it’s Dutch

RewriteRule ^(.*)$ /nl/index.php/$1 [L] 

- path.php = modify the last lines like the above default language, but this time to add the new language path

$global_vars = array(
    
"base_url" => "http://www.mysite.com/nl/"
    
"user_language" => "nl"
); // This array must be associative 

There are enough folks out there having trouble with removing index.php - removing two of them is worth pointing out. This caught me a few times.

The module’s instructions are clear enough; there are 2 basic methods for language replacement: the tag method, where you add a tag via the module and it does the swapping:

{exp:multi_language:phrase index="hello"

and Conditionals based on your current [base_path]:

{exp:weblog:entries weblog="my_weblog"}
{if user_language 
== "en"}{title}{if:else}{title_{user_language}}{/if}
{
/exp:weblog:entries} 

You’ll note that it uses the default [title] but also an alternative [title_] field. In my custom fields, right after title I’ve added a title_nl field, keeping the lowercase iso convention. This is the method of doing dynamic content - each language element having its own field (I loop through using a FieldFrame set, for example).

Links are your first enemy in multiple languages, so you need to find an alternative to [permalink] and [auto_path]. Let’s re-write that example to add a link:

{exp:weblog:entries weblog="my_weblog"}
<a href="{base_url}template_dir/template/{url_title}">
  
{if user_language == "en"}{title}
  {if
:else}{title_{user_language}}
  {
/if}
</a>
{/exp:weblog:entries} 

So what happens here is that depending on your current [base_path], the link does away with the [title_permalink] and rebuilds the path from the root up to the article. If I had a templates directory called “site” and in there an article view page called “view”, it’d look like this:

<a href="{base_url}site/view/{url_title}">
  
{if user_language == "en"}{title}
  {if
:else}{title_{user_language}}
  {
/if}
</a

Pagination doesn’t use [title_permalink] but rather [auto_path]. Specifically for Pagination, you’d want to add a new [paginate_base] parameter to your [entries] tag:

{exp:weblog:entries weblog="workshops" limit="5" status="open" 
paginate_base="{if user_language != 'en'}{user_language}
{/if}/template_group/template"

This points the Pagination auto links used by [if next_page] [if previous_page] to the correct language.

The next time you’ll see [auto_path] is in a site search, and unfortunately there doesn’t seem to be a similar method for a search_base. What I’ve done in this situation is to use the weblog_id to point me to the correct category link:

{if weblog_id == "3"}
  
<td width="30%" valign="top"><b><a href="{base_url}site/static/{url_title}">{title}</a></b></td>
{if:elseif weblog_id == "4"}
  
<td width="30%" valign="top"><b><a href="{base_url}site/workshop/{url_title}">{title}</a></b></td>
{/if} 

and then just use different results pages for each language.

Calendars are a bugger too - I’m working on a solution here, but it looks to be one where you’ll have to check segment_1 and then use swapping method on days and months. When I have that sorted, I’ll add it here.

Anyway, that’s my solution. Remember that many conditionals can slow you down, so I built many blocks to reduce the number of queries and conditionals. Depending on your needs, it might make mode sense to just check once if you’re in a language, then spill all the right fields out, instead of doing it on a field-by-field basis. All said though, this system is quite robust and I’m really happy with it.

As I learn new things I’ll add them here. The developer Ben at PutYourLightsOn has been amazingly helpful, working out many problems in my particularly wonky situation. Hopefully this will reduce his support workload a little. 

If anyone has more ideas, solutions or questions concerning languages and working with this module, please add them below.  Cheers!

Posted by admin on 03/24 at 08:53 AM
Posted in: IT notes   Project 52  
Permalink

Wednesday, February 03, 2010

Podcasts not syncing - here’s the fix

Can’t sync your podcasts? Playlists with podcasts don’t show up on your iPhone? Here’s the fix..

Previously the Podcast bug affected only the playlist order, but in the current iTunes 9.0.3 and iPhone 3.1.3 firmware (for example) the bug will remove any Podcast in a playlist from the iPod section of the device. If the Playlist is comprised of only podcasts, the playlist will not even be visible on the device (it will show in the iTunes sync).

To return podcasts to a playlist, you have to use the iTunes 9 trick:

  • Right-click your particular playlist and choose EDIT SMART PLAYLIST
  • Turn off LIVE UPDATING
  • SYNC
  • Then your podcasts return in a playlist in the correct order, but you’ll have to toggle it on again to update the playlist list.

    This bug has existed since iTunes 9 and it seems to only be getting worse. Hopefully Apple will fix it soon - I can’t believe they don’t want us to listen to podcasts in a playlist! C’mon Apple - fix this already!

    Posted by admin on 02/03 at 02:18 PM
    Posted in: Gadgetry   IT notes   Project 52  
    Permalink

    Thursday, January 28, 2010

    Who Got What Wrong - After the Apple Event

    Guessing what Steve will pull out is a bit of a “mug’s game”. We all should know that by now.

    Part of the mystery is not in the device or service, but what fantastical future we see Apple providing for us. Apple doesn’t promote or market these events…in fact, they hardly say a word, sending out only a invitation. In watching the media frenzy, I wonder how many people understand this, because when the blog-o-sphere doesn’t get what “they” want, the collective hue and cry makes them seem like a slighted lover holding a padded bra.

    Not Apple’s fault you got your hopes up. You wanted to believe in every fantasy out there and so you did. That’s about your religion - not Apple.

    Then there’s the Whispers. About a sales rep speaking higher than his pay grade, he’s a “insider with exclusive access”. Some CEO who blabs for a bit of self-promotion on every front page (but he’s not at the event…hmmm).  Part of this is genuinely newsworthy - but for week’s we’ve seen fanboy renders and ridiculous articles that make the product everything from the Second Coming to the moment Apple lost it. Speculation, endless speculation, that drives traffic, that angers readers, that drives traffic, that engorges fanboys, that drive’s traffic, that also drives stock prices unnaturally high in expectation and hinders entire market segments. If you’re financially involved in Apple, in some commercial way, shape or form, I’d imagine you’d feel it almost your ouroborostic duty to create, conflate, regurgitate and re-gorge on every other bit of speculation out there.

    Not Apple’s fault your stock dropped after the launch. You wanted people to believe you knew something you didn’t, that you were something you were not. Makes writing easier if you get your own “Princess Diana” to promote/slate/reconcile, I guess. A proper journalistic source? Sorry - you don’t even appear relevant this morning - you’ve been caught with a sock in your pants.

    This is not a healthy ecosystem. Replace “the media” with “the banks” and We The People would have had them in front of Congress by now.

    If you’re disappointed in Apple this morning, I’d say you’re blaming the wrong people.

    Posted by admin on 01/28 at 08:35 AM
    Posted in: IT notes   Project 52  
    Permalink

    Thursday, January 21, 2010

    Best quote of the day:

    “Spiteful words can hurt your feelings but silence breaks your heart.” 
    Oooh, so true.

    Posted by admin on 01/21 at 03:57 PM
    Posted in: Idle Chatter   Personal   Project 52  
    Permalink

    Tuesday, January 19, 2010

    The 27th cometh for the last of a 1000 times

    Ever since my trusty Newton was cancelled by the just-returned Steve Jobs over a decade ago, people have been speculating about what to expect in a new Apple Tablet. What they mean to say is that mouse-based computing was even back then beginning to suck. So will does Jan 27th mean to computing? Let’s prognosticate!

    I think we can all agree - we’ve all had about enough of the Apple Tablet vapor/rumor-mill over the years. In some ways, I’m too nervous to even contemplate what the experience will be like on one. My experience with Sony smartphones never prepared me for an iPhone life; no-one saw it coming. It was new, fresh, a complete rethink of the phone experience, and while it’s not perfect, it’s a damn better world because of the iPhone.

    I say that because people today poo-poo the Mac and it’s graphic interface, and there are generations living now that have no idea what it’s like to boot up a tape-drive and wait 5 minutes for a text adventure to start. And rightly so: these were neanderthal systems and the more advanced graphic systems left this branch of early hominid-interface far, far behind. You have to know where you came from to appreciate where you’re going.

    For years, there was a constant howling about what the next steps should be. I genuinely missed my Newton (I still have one, a 2100, sitting on a shelf - near pristine and unused) but the downsides were too much to bear in this connected world. For years, at every coming of a MacWorld, the whispers that a new “tablet was coming” drove bloggers into a delicious madness.

    Such speculation considered the Tablet to be a small, light Mac. With Apple’s current success, desires morphed it into a big iPhone. Big iPhone = Dumb Tablet, at least to me. The core of the iPhone’s success is it’s ability to move small bits of information to and from you - a photo, a video, a web page, a tweet. Small screen, small consumption.

    Enter the Apple Invite for the 27th of January 2010:

    image

    Looks like whatever it is, it’s primarily a creative device. The Zapruderization of the invitation has already fueled another day’s speciousness and speculation. The truth is, as we always already know, not to be found on webpages anywhere. This is the age of the news we want, not the news we need.

    I know nothing other than what I’ve experienced with the iPhone (v1 & v3), my Newton, a decade of experience with Macs and my desire for a Star Trek slate handed to me by a pretty yeoman. But since blogs are a suckers game…I’m in.

    What I’d like to think is this:

  • It’ll have a new interface on a stable file system: It’s not going to be a big iPhone or a Half-Mac. It’s going to involve the immediacy you find in an iPhone and the depth of a real creative device. I can’t imagine a creative tool without a descending filing system, even with tags, too many visual clues would overwhelm selection, so I’d also expect the iPhone to upgrade its flat UI very soon too
  • Hardware: The card shows a thin, round-edged border, so there’s a good likelihood when closed that the Tablet will be similar in feel to a big phone; which is to say, very ergonomic. I have faith in Apple in this regard - say what you want about any of their products, they feel good to the touch.
  • I’m going to guess it’ll not have a removable battery but a moulded one like all their other products - we’re beyond throw-away batteries.
  • Yes, it’ll be wireless - it has to be these days. Will it be 3G? Only if there’s a way to have 2 devices on the same number, but without that I doubt Apple would niche the system by making you get a second phone account. With AT&T. Think about that a second and you’ll know I’m right.
  • The paint splatters everywhere give the impression of color, texture and density. Were I a betting man (and we know from past history it’s best I don’t) I would worry if I owned Wacom and PainterX stock. Possibly Adobe should worry too - this could be the cornerstone of an attack on the Creative Suite that could work if the apps were sold cheaply enough. You’d need the Tablet to use them; a reverse of the “Razor and Blades” theory, sure, but there’s plenty of other blades in the App Store, and it’s a way to get even with Adobe for the crap that CS4 and especially Flash have become.
  • But that’s all I can guess at, given what we all know; anything more is a mugs game. I’ve got the credit card warmed-up and parked in the garage, raring to go. I’ll let you know what happens to my bank balance in a bit over a week..

    Posted by admin on 01/19 at 10:07 AM
    Posted in: Gadgetry   IT notes   Malarkey   Project 52  
    Permalink
    Page 3 of 21 pages  <  1 2 3 4 5 >  Last »