开发者

How to use compiled gettext .mo files without the gettext module?

开发者 https://www.devze.com 2023-02-24 03:34 出处:网络
I\'m trying to find a way to use 开发者_运维技巧gettext and friends without depending on the official gettext module, which I\'ve found to not be installed everywhere and sometimes yields different re

I'm trying to find a way to use 开发者_运维技巧gettext and friends without depending on the official gettext module, which I've found to not be installed everywhere and sometimes yields different results depending on the OS and server configuration.


I just make a library which can auto load the po file, change languages and translate all text between {t} and {/t} in the view, I posted here in case some one want to use it instead calling the gettext function in the view:

http://www.chuongduong.net/page/15/codeigniter-gettext-with-smarty-or-parser-template-without-php-code-in-view.html

The view code might be:

<html>
<head>
<title>{blog_title}</title>
</head>
<body>

<h3>{blog_heading}</h3>
{blog_entries}

<h5>{t}Title is{/t}  {title}</h5>

<p>{t 1="<b>" 2="</b>"}Click here %1to see%2 me{/t}{body}</p>

<p>{t 1="{id}" 2="author"}The id is: %1 wrote by %2{/t}</p>

<p>{t 1="<a href=\"link here\">" 2="</a>"}Please lick on me%2{/t}</p>

{/blog_entries}

</body>

</html>


There are a few userland php implementations of the gettext functions.

  • One is gettext.php (I wrote that, PD, but not very well tested)
  • And the other one php-gettext (GNU GPL, quite widespread)
  • The Zend Framework also provides an adapter for gettext. Not sure if it relies on the native PHP functions; but it might very well come with its own reimplementation.


I ended up forked PHP-gettext (not the GNU GPL one) and modifying it to work as a transparent drop in. It creates a very simple one line fix for a missing gettext module.

require( "PHP-Gettext/Autoload.php" );
0

精彩评论

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

关注公众号