<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.1.2" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>

<channel>
	<title>php-developers.net</title>
	<link>http://www.php-developers.net</link>
	<description>php and mysql web development services</description>
	<pubDate>Sun, 20 Apr 2008 13:05:23 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.1.2</generator>
	<language>en</language>
			<item>
		<title>Create a multilingual site with php and gettext</title>
		<link>http://www.php-developers.net/2007/06/25/create-a-multilingual-site-with-php-and-gettext/</link>
		<comments>http://www.php-developers.net/2007/06/25/create-a-multilingual-site-with-php-and-gettext/#comments</comments>
		<pubDate>Mon, 25 Jun 2007 10:13:15 +0000</pubDate>
		<dc:creator>Peter Damianov</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.php-developers.net/2007/06/25/create-a-multilingual-site-with-php-and-gettext/</guid>
		<description><![CDATA[Creating a multilingual site is a common task that can be simplified to a considerable amount if the right tools are used. One of the common ways to create a website in several languages is by using a set of GNU tools called Gettext. This article deals with the usage of Gettext and solves common [...]]]></description>
			<content:encoded><![CDATA[<p>Creating a multilingual site is a common task that can be simplified to a considerable amount if the right tools are used. One of the common ways to create a website in several languages is by using a set of GNU tools called Gettext. This article deals with the usage of Gettext and solves common multilingual tasks.</p>
<p><strong>Requirements</strong></p>
<p>You must have the Gettext extension enabled in php.ini</p>
<p><strong>Using Gettext</strong></p>
<p><em>1. Set up the Gettext environment</em><br />
1.1. Define what language to use (in our case &#8216;bg&#8217; stands for Bulgarian)</p>
<blockquote><p>$language = &#8216;bg&#8217;;</p></blockquote>
<p>1.2. Save it in the LANG environment variable</p>
<blockquote><p>putenv(&#8221;LANG=$language&#8221;);</p></blockquote>
<p>1.3. Set the current locale</p>
<blockquote><p>setlocale(LC_ALL, $language);</p></blockquote>
<p>1.4. Set the default domain</p>
<blockquote><p>textdomain(&#8217;messages&#8217;);</p></blockquote>
<p>1.5. Set the path for the domain &#8216;messages&#8217;</p>
<blockquote><p>bindtextdomain(&#8217;messages&#8217;, &#8216;/path/to/locale/directory&#8217;);</p></blockquote>
<p>1.6. Specify the character encoding in which the messages from the DOMAIN message catalog will be returned. For multilingual sites you would most likely use UTF-8</p>
<blockquote><p>bind_textdomain_codeset(&#8217;messages&#8217;, &#8216;UTF-8&#8242;);</p></blockquote>
<p><em>2. Usage in the php files is as simple as using the gettext function or the _()</em></p>
<blockquote><p> echo gettext(&#8221;I bought a new car yesterday&#8221;);</p></blockquote>
<p>&#8230; is same as &#8230;</p>
<blockquote><p> echo _(&#8221;I bought a new car yesterday&#8221;);</p></blockquote>
<p>&#8230; and the last step is to create the Gettext files.</p>
<p><em>3. Set up the Gettext files</em><br />
3.1. Directory structure - a locale directory is expected where you will keep the files containing the translated strings:</p>
<blockquote><p>
/locale<br />
&nbsp;&nbsp;&nbsp;&nbsp;/bg<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/LC_MESSAGES<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;messages.po<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;messages.mo
</p></blockquote>
<p>Adding an additional language files would result in creating its own set of directories. For example:</p>
<blockquote><p>
/locale<br />
&nbsp;&nbsp;&nbsp;&nbsp;/bg<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/LC_MESSAGES<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;messages.po<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;messages.mo<br />
&nbsp;&nbsp;&nbsp;&nbsp;/en<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/LC_MESSAGES<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;messages.po<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;messages.mo
</p></blockquote>
<p>3.2. The file with the &#8216;po&#8217; extension holds the human readable strings and their translation. Here is what it contains, broken to parts:<br />
3.2.1. Some header messages that give information about the file and the project:</p>
<blockquote><p> # SOME DESCRIPTIVE TITLE.<br />
# Copyright (C) YEAR Free Software Foundation, Inc.<br />
# FIRST AUTHOR <iail@address>, YEAR.</iail@address><br />
<iail@address> #</iail@address><br />
<iail@address> #, fuzzy</iail@address><br />
<iail@address> msgid &#8220;&#8221;</iail@address><br />
<iail@address> msgstr &#8220;&#8221;</iail@address><br />
<iail@address> &#8220;Project-Id-Version: PACKAGE VERSION\n&#8221;</iail@address><br />
<iail@address> &#8220;POT-Creation-Date: 2002-04-06 21:44-0500\n&#8221;</iail@address><br />
<iail@address> &#8220;PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n&#8221;</iail@address><br />
<iail@address> &#8220;Last-Translator: FULL NAME <iail@address>\n&#8221;</iail@address></iail@address><br />
<iail@address><iail@address> &#8220;Language-Team: LANGUAGE <ll@li.org>\n&#8221;</ll@li.org></iail@address></iail@address><br />
<iail@address><iail@address><ll@li.org> &#8220;MIME-Version: 1.0\n&#8221;</ll@li.org></iail@address></iail@address><br />
<iail@address><iail@address><ll@li.org> &#8220;Content-Type: text/plain; charset=CHARSET\n&#8221;</ll@li.org></iail@address></iail@address><br />
<iail@address><iail@address><ll@li.org> &#8220;Content-Transfer-Encoding: ENCODING\n&#8221;</ll@li.org></iail@address></iail@address></p></blockquote>
<p>3.2.2. The strings and their translation<br />
For the messages.po file in the &#8216;bg&#8217; directory</p>
<blockquote><p>#: products.php:3<br />
msgid &#8220;I bought a new car yesterday&#8221;<br />
msgstr &#8220;Купих си нова кола вчера&#8221;</p></blockquote>
<p>For the messages.po file in the &#8216;en&#8217; directory</p>
<blockquote><p>#: products.php:3<br />
msgid &#8220;I bought a new car yesterday&#8221;<br />
msgstr &#8220;I bought a new car yesterday&#8221;</p></blockquote>
<p>Here are the explanations of these lines:</p>
<blockquote><p>#: products.php:3 -&gt; shows the file and the line number that contains the string<br />
msgid &#8220;I bought a new car yesterday&#8221; -&gt; this is the string to be translated<br />
msgstr &#8220;Купих си нова кола вчера&#8221; -&gt; this is the translation of the string</p></blockquote>
<p>3.3. The file with the &#8216;mo&#8217; extension is the binary format. We will talk about the generation of this file later on in this article.</p>
<p><em>4. Creating po files</em><br />
Obviously adding by hand the strings to be translated is not very convenient. Gettext offers a convenient way to automatically extract the Gettext strings from the php files using the xgettext command</p>
<blockquote><p>$ xgettext -n *.php</p></blockquote>
<p>This would create a po file with the headers explained above and includes the strings to be translated.</p>
<p><em>5. Translate the strings in the po files. Convenient tools for doing this are:</em><br />
For Linux - <a href="http://kbabel.kde.org/" target="_blank">KBabel</a><br />
For Windows - <a href="http://www.poedit.net/" target="_blank">poEdit</a></p>
<p><em>6. Converting po files to mo files</em><br />
Once you translated the files you need to turn them to binary files (&#8217;mo&#8217; files) and copy them to the appropriate language directories. To do the conversion run the following command:</p>
<blockquote><p>$ msgfmt messages.po</p></blockquote>
<p><em>7. What do we do if you need to add some more strings to the pot files and if we need to update some strings?</em> The most logical way is to merge the current pot file with the new pot file that contains the new strings. To do this in Gettext use the msgmerge command.</p>
<blockquote><p>$ msgmerge products1.po products2.po &#8211;output-file=merged_products.po</p></blockquote>
<p><em>8. Advanced usage of gettext</em><br />
8.1. Using dynamic variables. What about if you want to use dynamic variables within the translated strings? The printf function comes in hand.</p>
<blockquote><p>printf(gettext(&#8221;Hello, %s&#8221;), &#8220;Peter&#8221;);</p></blockquote>
<p>And the po file will look like this:</p>
<blockquote><p>#: products.php:7<br />
msgid &#8220;Hello, %s&#8221;<br />
msgstr &#8220;Здравей, %s&#8221;</p></blockquote>
<p>8.2. Another issue is the plural version of the strings. Printf comes in hand again together with ngettext:</p>
<blockquote><p>printf(ngettext(&#8221;%d car&#8221;, &#8220;%d cars&#8221;, 1), 1);<br />
printf(ngettext(&#8221;%d car&#8221;, &#8220;%d cars&#8221;, 2), 2);</p></blockquote>
<p>And the po file will look like this:</p>
<blockquote><p>msgid &#8220;%d car&#8221;<br />
msgid_plural &#8220;%d cars&#8221;<br />
msgstr[0] &#8220;%d кола&#8221;<br />
msgstr[1] &#8220;%d коли&#8221;</p></blockquote>
<p>An important factor here is to add a header in the po file that defines the plural format for the specified language. The following example is specific to the English language. For other languages check the Gettext documentation:</p>
<blockquote><p>&#8220;Plural-Forms: nplurals=2; plural=n != 1;\n&#8221;</p></blockquote>
<p><strong>Examples - source code</strong></p>
<p>Here is an example from a shopping cart application with fully functioning Gettext examples. To install and run it just unzip it to a subdirectory in htdocs and run items.php.<br />
<a href="http://www.php-developers.net/attach/gettext_example.zip">Click here to download the attachment</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.php-developers.net/2007/06/25/create-a-multilingual-site-with-php-and-gettext/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Setting up Windows/Linux environment for file upload progress meter</title>
		<link>http://www.php-developers.net/2007/04/20/setting-up-windows-linux-environment-for-file-upload-progress-meter/</link>
		<comments>http://www.php-developers.net/2007/04/20/setting-up-windows-linux-environment-for-file-upload-progress-meter/#comments</comments>
		<pubDate>Fri, 20 Apr 2007 17:44:17 +0000</pubDate>
		<dc:creator>Peter Damianov</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://php-developers.net/2007/04/20/setting-up-windows-environment-for-file-upload-progress-meter/</guid>
		<description><![CDATA[Windows
Prerequisites :
PHP 5.2
Step 1 :
Download the progress upload extension from the PECL respository http://pecl4win.php.net/ext.php/php_uploadprogress.dll
Step 2 :
Copy php_uploadprogress.dll to the extension directory
Step 3 :
Add to php.ini
extension=php_uploadprogress.dll
Step 4 :
Add to php.ini
[uploadprogress]
uploadprogress.file.filename_template=&#8221;\path\to\tmp\sometext_%s.txt&#8221;
 Step 5 :
Do not forget to restart your web server
 Linux
Prerequisites :
PHP 5.2
 Step 1 :
Download the uploadprogress extension from PECL: http://pecl.php.net/package/uploadprogress
Step 2 :
Enter in the [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Windows</strong></p>
<p><em>Prerequisites :</em></p>
<blockquote><p>PHP 5.2</p></blockquote>
<p><em>Step 1 :</em></p>
<blockquote><p>Download the progress upload extension from the PECL respository <a href="http://pecl4win.php.net/ext.php/php_uploadprogress.dll" title="http://pecl4win.php.net/ext.php/php_uploadprogress.dll" target="_blank">http://pecl4win.php.net/ext.php/php_uploadprogress.dll</a></p></blockquote>
<p><em>Step 2 :</em></p>
<blockquote><p>Copy php_uploadprogress.dll to the extension directory</p></blockquote>
<p><em>Step 3 :</em></p>
<blockquote><p>Add to php.ini<br />
extension=php_uploadprogress.dll</p></blockquote>
<p><em>Step 4 </em>:</p>
<blockquote><p>Add to php.ini<br />
[uploadprogress]<br />
uploadprogress.file.filename_template=&#8221;\path\to\tmp\sometext_%s.txt&#8221;</p></blockquote>
<p><em> Step 5 </em>:</p>
<blockquote><p>Do not forget to restart your web server</p></blockquote>
<p><strong> Linux</strong></p>
<p><em>Prerequisites </em>:</p>
<blockquote><p>PHP 5.2</p></blockquote>
<p><em> Step 1</em> :</p>
<blockquote><p>Download the uploadprogress extension from PECL: <a href="http://pecl.php.net/package/uploadprogress" title="http://pecl.php.net/package/uploadprogress" target="_blank">http://pecl.php.net/package/uploadprogress</a></p></blockquote>
<p><em>Step 2</em> :</p>
<blockquote><p>Enter in the directory you downloaded the extension to and run these commands as root:<br />
phpize<br />
./configure &#8211;enable-uploadprogress<br />
make<br />
make install</p></blockquote>
<p><em>Step 3</em> :</p>
<blockquote><p>Add this to php.ini:<br />
extension=uploadprogress.so</p></blockquote>
<p><em>Step 4</em> :</p>
<blockquote><p>Restart your web server</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.php-developers.net/2007/04/20/setting-up-windows-linux-environment-for-file-upload-progress-meter/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Fatal error: Class &#8216;MDB2&#8242; not found</title>
		<link>http://www.php-developers.net/2007/03/19/fatal-error-class-mdb2-not-found/</link>
		<comments>http://www.php-developers.net/2007/03/19/fatal-error-class-mdb2-not-found/#comments</comments>
		<pubDate>Mon, 19 Mar 2007 09:22:37 +0000</pubDate>
		<dc:creator>Peter Damianov</dc:creator>
		
		<category><![CDATA[Errors Help]]></category>

		<guid isPermaLink="false">http://php-developers.net/archives/5</guid>
		<description><![CDATA[SOLUTION
1) Make sure that PEAR is listed in the include_path in php.ini. To include dynamically the pear package use the following code substituting &#8216;pear_location&#8217; with the actual location of your PEAR installation.
set_include_path(get_include_path() . PATH_SEPARATOR . &#8216;pear_location&#8217;);
2) Make sure that you have INSTALLED MDB2 and the driver for the database you are going to use. For [...]]]></description>
			<content:encoded><![CDATA[<p><strong>SOLUTION</strong></p>
<p>1) Make sure that PEAR is listed in the include_path in php.ini. To include dynamically the pear package use the following code substituting &#8216;pear_location&#8217; with the actual location of your PEAR installation.</p>
<blockquote><p>set_include_path(get_include_path() . PATH_SEPARATOR . &#8216;pear_location&#8217;);</p></blockquote>
<p>2) Make sure that you have INSTALLED MDB2 and the driver for the database you are going to use. For example if you are working with MySQL then you need the MDB2_driver_mysql.</p>
<p><em>2.1.) To get information about all PEAR packages use the following command:</em></p>
<blockquote><p>pear list</p></blockquote>
<p><em>2.2.) To install a package use:</em></p>
<blockquote><p>pear install packageName</p></blockquote>
<p><em>2.3.) To upgrade a package use:</em></p>
<blockquote><p>pear upgrade packageName</p></blockquote>
<p><em>2.4.) Make sure that the dependence packages are upgraded also. To view the information about the package and its dependancies use:</em></p>
<blockquote><p>pear info packageName</p></blockquote>
<p>3)  If you are developing under Windows make sure that the file name of your application is not called mdb2.php since it would be mixed up with the PEAR/MDB2.php file.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.php-developers.net/2007/03/19/fatal-error-class-mdb2-not-found/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
