IT Community - Software Programming, Web Development and Technical Support

Gettext in php

This is a discussion on Gettext in php within the PHP Programming forums, part of the Web Development category; Hi, This is new and very interesting topic. The gettext functions implement an NLS (Native Language Support) API which can ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > PHP Programming

Register FAQ Members List Calendar Mark Forums Read

Reply
 
Thread Tools Display Modes
  #1  
Old 05-06-2008, 09:33 PM
senraj senraj is offline
D-Web Master
 
Join Date: Jul 2007
Posts: 418
senraj is on a distinguished road
Post Gettext in php

Hi,

This is new and very interesting topic.
The gettext functions implement an NLS (Native Language Support) API which can be used to internationalize your PHP applications.
__________________
Regards,
Senraj.A
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2  
Old 05-06-2008, 09:55 PM
Jeyaseelansarc Jeyaseelansarc is offline
D-Web Genius
 
Join Date: Mar 2007
Location: Chennai
Posts: 1,165
Jeyaseelansarc is on a distinguished road
Send a message via AIM to Jeyaseelansarc
Default Re: Gettext in php

Hi,
I am very new to this topic. can you give me in brief?
__________________
With,
J. Jeyaseelan

Everything Possible
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3  
Old 05-06-2008, 10:18 PM
senraj senraj is offline
D-Web Master
 
Join Date: Jul 2007
Posts: 418
senraj is on a distinguished road
Post Re: Gettext in php

Hi,

If want use gettext mean you must install gettext.please read below.

To include GNU gettext support in your PHP build you must add the option --with-gettext[=DIR] where DIR is the gettext install directory, defaults to /usr/local.
__________________
Regards,
Senraj.A

Last edited by senraj : 05-06-2008 at 11:04 PM.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4  
Old 05-06-2008, 10:52 PM
senraj senraj is offline
D-Web Master
 
Join Date: Jul 2007
Posts: 418
senraj is on a distinguished road
Post Re: Gettext in php

Hi,

Localizing PHP web sites using gettext

Developing multi language web sites using PHP is actually very easy. A common approach is having an include file for every supported language which contains an array that maps string ids to localized text (for example "WelcomeText" => "Welcome to our homepage." would be included using something like <?= $strings["WelcomeText"] >). However there are several problems with this approach. First of all, when the application is updated and additional strings are added, there is no way to determine which new strings were added and if they are present in every language (unless you write a script for it). What happens if a newly added string is not yet translated into a specific language?
__________________
Regards,
Senraj.A
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5  
Old 05-06-2008, 10:54 PM
senraj senraj is offline
D-Web Master
 
Join Date: Jul 2007
Posts: 418
senraj is on a distinguished road
Post Re: Gettext in php

Hi,

Using gettext with PHP

A widely used framework for internationalization is gettext. It can be used with a variety of programming languages, including PHP. There are basically two ways to use gettext in your PHP applications. You can use the native gettext PHP extension or you can use a library implemented in PHP that does not need any extension, such as php-gettext.
__________________
Regards,
Senraj.A
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6  
Old 05-06-2008, 10:55 PM
senraj senraj is offline
D-Web Master
 
Join Date: Jul 2007
Posts: 418
senraj is on a distinguished road
Post Re: Gettext in php

Hi,

Using gettext in your application

Using gettext to get translated strings couldn't be easier. Just call gettext("Text to be translated") and you get a localized version of "Text to be translated" if available, or "Text to be translated" otherwise. If you're lazy, you can use _() instead of gettext().
Let's try this out. Create a new PHP file (we'll call it test.php), and insert the following code:
PHP Code:
<?php
echo _("Hello World!");
?>
When you open that page in your browser, you will see "Hello World!".
__________________
Regards,
Senraj.A
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7  
Old 05-08-2008, 03:45 AM
senraj senraj is offline
D-Web Master
 
Join Date: Jul 2007
Posts: 418
senraj is on a distinguished road
Post Re: Gettext in php

Hi,

I think this extension has no configuration directives defined in php.ini and this extension has no resource types defined and this extension has no constants defined.
__________________
Regards,
Senraj.A
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8  
Old 05-08-2008, 03:47 AM
senraj senraj is offline
D-Web Master
 
Join Date: Jul 2007
Posts: 418
senraj is on a distinguished road
Post Re: Gettext in php

Hi,

bind_textdomain_codeset

Specify the character encoding in which the messages from the DOMAIN

message catalog will be returned. This bind_textdomain_codeset used to

PHP 4 >= 4.2.0, PHP 5
__________________
Regards,
Senraj.A
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9  
Old 05-09-2008, 03:36 AM
senraj senraj is offline
D-Web Master
 
Join Date: Jul 2007
Posts: 418
senraj is on a distinguished road
Post Re: Gettext in php

Hi,

The bindtextdomain() function sets the path for a domain. It returns the full pathname for the domain currently being set.

bindtextdomain() example

PHP Code:
<?php

$domain 
'myapp';
echo 
bindtextdomain($domain'/usr/share/myapp/locale'); 

?>
This will output:

/usr/share/myapp/locale
__________________
Regards,
Senraj.A
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10  
Old 05-09-2008, 03:55 AM
senraj senraj is offline
D-Web Master
 
Join Date: Jul 2007
Posts: 418
senraj is on a distinguished road
Post Re: Gettext in php

Hi,

ngettext() returns correct plural form of message identified by msgid1 and msgid2 for count n. Some languages have more than one form for plural messages dependent on the count.

ngettext() example

PHP Code:
<?php

setlocale
(LC_ALL'cs_CZ');
printf(ngettext("%d window""%d windows"1), 1); 
printf(ngettext("%d window""%d windows"2), 2); 
printf(ngettext("%d window""%d windows"5), 5); 

?>
This will output
1
2
5
__________________
Regards,
Senraj.A
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


All times are GMT -7. The time now is 09:55 AM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.
Our Partners
One Way Moving Companies | Stamford Dentist | Euro Millions Lottery | Home Loans| Furniture

SEO by vBSEO 3.0.0