views:

264

answers:

1

I'm using Zymic, its a great hosting but it doesn't support the php gettext extension. I'm planning to buy some hosting in the future, but from now I want the simplest solution in order to replace the function of gettext, in this case I want to display different text (English, Spanish, Chinese, etc...) without modyfing the file too much (at least not having to create seaprated files for each language).

I tried something like this:

  <?php

    $lang = "";
    switch ($lang) {
        case "en":
            $lang = "Hello World";
            break;
        case "es":
            $lang = 'Hola Mundo';
            break;
    }

    ?>

    <div>
    <p><?php echo $lang;?></p>
    </div>

When I change the $lang variable it works. I'm a PHP beginner and I can't think of a way to make it change in the browser (by clicking a link).

Or is there a better way of doing this?

+2  A: 

I would say Zend_translate is the very best bet for internationalization these days. It's even better than gettext. See this SO Question for a number of arguments. This question was how I myself learned of Zend_translate.

It is a bit much for the simple task you show in your question, and it may be take a bit of work to get used to it in the beginning, but the Zend components promise very good solutions to all kinds of internationalization issues - which are more than just translating words. There are also different numbering formats, time formats, currency formats, time zones... all to be taken care of when internationalizing an application.

It doesn't require any specific extensions, and you can use parts of the Zend Framework as a simple library, there is no need to adhere to a specific application structure or anything.

Pekka