What's the simplest Php alternative to the Php

2019-01-28 06:23发布

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条回答
爷、活的狠高调
2楼-- · 2019-01-28 07:19

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.

查看更多
\"骚年 ilove
3楼-- · 2019-01-28 07:21

This must be one of the oldest answers I've ever supplied, but...

PHP-gettext at https://launchpad.net/php-gettext is by far the simplest workhose as gettext replacement.

I've used in some projects I've had troubles getting gettext working with PHP.

查看更多
登录 后发表回答