40 likes | 56 Views
Learn how to localize your code for different languages like Bengali (bn) using gettext functions in PHP. Initialize language, set locale, and bind text domains for seamless translation.
E N D
CS 297, Spring’08 Prepared By: Farzana Forhad Prepared For: Dr. Chris Pollett
gettext source code <?php $language = 'bn'; putenv("LANG=$language"); setlocale(LC_ALL, $language); $domain = 'messages'; bindtextdomain($domain, "\www\gettext-0.17\gettext-tools\examples\hello-php\po");//"/www/htdocs/site.com/locale"); textdomain($domain); echo _("I stood in the wind"); ?>
gettext source code • $language = 'bn'; here we are initializing the language variable with the language “bn” • putenv("LANG=$language"); the function putenv() sets an environmental variable here. Put the value of $language to LANG • setlocale(LC_ALL, $language); program must initialize for a specific language, and setlcale serves the purpose
gettext source code • bindtextdomain($domain, "\www\gettext-0.17\gettext-tools\examples\hello-php\po"); the full pathname for the domain currently being set • textdomain ("hello-php"); the function returns the current message domain