开发者

php constant with gettext

I am using config file which contains: config.php

define('SYS_TITLE','My Application Title');

I load language local for gettext based on SESSION variable in another file included after the config file is loaded. how to make it something like:

echo _(SYS_TITLE);

What is the b开发者_开发百科est way to translate the SYS_TITLE without changing much of the code.


If I get you right you are looking for a way to import translated string into some php code.

How about loading all your strings in XL in the first column and generating the php code in the second column with a simple concatenate() call?

If you store "Something in English" in A1, you can setup B1 as follows:

=CONCATENATE("define('SYS_TITLE','",A1,"');")

You end up with

A1                      B1
Something in english    define('SYS_TITLE','Something in english');


You could just use:

echo _("SYS_TITLE");

and then create a .po file for all your translations. It wouldn't use the value of your constant, of course, but it's up to you to decide if that's acceptable. After all, you don't need the msgid to contain the default language's text literally.

You could also create some wrapper function for your gettext call:

function gt(string){
    if(defined(string)){
        echo constant(string);
    } else {
        echo _(string);
    }
}

Of course, accepting all the problems that this will bring along (like additional plural handling).


You should also be able to do this:

echo _(constant("SYS_TITLE"));

This should retrieve the value of your constant, which will then be passed into your function call. I haven't tested it though, so I may be wrong.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜