Simple Translations with Oxid eSales

PHP 
Simple Translations with Oxid eSales

You may already be all over this one, but if you’re new to Oxid eSales or new to website internationalization, then today’s tip is one not to miss.


You may already be all over this one, but if you’re new to Oxid eSales or new to website internationalization, then today’s tip is one not to miss.

When you’re wanting to provide language translations across multiple languages, such as German, English, French, Polish (or whatever), there’s one tag you need to know: oxmultilang.

It’s a simple tag that requires next to no effort to use. So here’s how to get your content internationalized.

Step 1. Add Language Terms

Under out/ you’ll find directories for the languages that your site supports. In the default, you’ll see ‘de‘ and ‘en‘, for German and English respectively. In these directories, you’ll see a file called** lang.php**. That’s the default set of Oxid translations.

What you need to do is, essentially, copy that file, naming it** cust_lang.php** and empty it out. After that, follow the original format, adding your translation tags that you’re going to use. For example, below is a sample of what an English version of cust_lang.php could look like when I want to use a tag called PLUS_SHIPPING2.

$sLangName  = “English”;
$aLang = array(
  ‘PLUS_SHIPPING2′ => “Accessories”,
  // the rest of the translations…
);

Once you’ve created them for your default language, copy and translate them (if you’re multilingual) or add the translations that someone’s provided to you in your other language files.

Do a double check to make sure that they’re all correct and then move on to step 2.

Step 2. Use oxmutilang tags (instead of normal text)

With the translation tags ready, open up your templates that you’ll be adding internationalized content to and start using the oxmultilang tag.

It’s a wonderful tag that’s painfully simple to use. Remembering the sample that we added in step one, in your template, start using it as in the following example:

[{ oxmultilang ident="PLUS_SHIPPING2" }]<br />

ident is the tag name that will be used, to pull text from your translation file and put it in the generated template when it’s rendered. See, nothing could be simpler.

Step 3. Clear the /tmp Directory

Now that you’ve setup translations so that you can use them in your templates and you’ve added the oxmultilang tag to your templates, so that you are using the translations you’ve setup, there’s one step that remains.

Under the application root, you’ll see a directory called /tmp. It’s the base cache directory. It’s also, by default, the directory that the Smarty template system uses to cache it’s generated templates to.

So, delete all the files in that directory and reload your browser (on the page that you’ve added your translation too).

This time, you’ll see your internationalized string being displayed, not normal text. Of course, we need to fully test it.

This time, change to one of the other languages of your shop, which you’ve provided a translation for and check that the text changes to the translation in the translation file of your other language.

Something went wrong?

If you don’t see the text from your translation file displayed when you change languages firstly double check that you did clear out all the files in your /tmp directory.

Then check that you saved the translation files. This will sort out 99% of the issues. If you’ve done all this and it’s still not working, feel free to chat with me in the comments.


You might also be interested in these tutorials too...

Tue, Oct 1, 2013

Using Traits for Code Reuse in Zend Framework 2

This is a post I’ve been meaning to write for a feels weeks now after I first started using Traits for simple reuse, as it solved a need I had at the time. After a while it seemed to be not too bad of a solution also. What Are Traits? If you’re not familiar with Traits the PHP manual describes them as: Traits are a mechanism for code reuse in single inheritance languages such as PHP.

Thu, Jul 11, 2013

Zend Framework 2 - The New HTML5 Form Fields - Part 2

In today’s post, we look at more HTML5 Form fields in Zend Framework 2: Month, Range, Color, Week and Number, as well as element properties and attributes. Come look around more of the great new elements available.


Want more tutorials like this?

If so, enter your email address in the field below and click subscribe.

You can unsubscribe at any time by clicking the link in the footer of the emails you'll receive. Here's my privacy policy, if you'd like to know more. I use Mailchimp to send emails. You can learn more about their privacy practices here.

Join the discussion

comments powered by Disqus