How to use po / pot files with php?

I have a .po and .mo file in a folder with the address / locale / nld_nld / LC_MESSAGES / . Both file names are messages. I tried to use the following code:

try.php:

<?php
require_once("Localization.php");
echo _("Hello World!");
?>

Localization of .php goes here:

<?php
$locale = "nld_nld";
if (isSet($_GET["locale"])) $locale = $_GET["locale"];
putenv("LC_ALL=$locale");
setlocale(LC_ALL, $locale);
bindtextdomain("messages", "./locale");
bind_textdomain_codeset("messages", 'UTF-8');
textdomain("messages");
?>

try.php Localization . , xampp. phpinfo();. , "GetText Support", . messages.po messages.mo , poEdit. Windows. , try.php, Hello World! ( . , .po 100% ( poEdit). , . .

!

+5
3

, , , , , ? :

<?php
putenv('LC_MESSAGES=es_ES');
setlocale(LC_MESSAGES, 'es_ES.utf8');
bindtextdomain('es','/full/path/here/application/locale');
textdomain('messages-es');
bind_textdomain_codeset('messages-es', 'UTF-8');
?>

, , .mo /full/path/here/application/locale/es_ES.utf8.

, , , :

<?php
function TestLang( $langCode ) {
  echo( '<b>TESTING LANG CODE: ' . strtolower( $langCode ) . '</b><br />' );
  putenv( 'LC_MESSAGES=' . strtolower( $langCode ) . '_' . strtoupper( $langCode ));
  echo( 'LC_MESSAGES: ' . getenv( 'LC_MESSAGES' ) . '<br />' );
  $localeResult = setlocale( LC_MESSAGES, strtolower( $langCode ) . '_' . strtoupper( $langCode ) . '.utf8' );
  echo( 'Locale: ' . $localeResult . '<br />' );
  $textDomain = bindtextdomain( strtolower( $langCode ), ROOT . '/' . APP_DIR . '/locale' );
  echo( 'Text Domain: ' . $textDomain . '<br />' );
  textdomain( strtolower( $langCode ));
  $codeSet = bind_textdomain_codeset( strtolower( $langCode ), 'UTF-8' );
  echo( 'Code Set: ' . $codeSet . '<br />' );
  echo( '.mo File: ' . $textDomain . '/' . $localeResult . '/LC_MESSAGES/' . $langCode . '.mo<br />' );
  echo( '<br />-- ' . _( 'Hello World!' ) . ' --<br />' );
}

TestLang( 'en' );
TestLang( 'de' );
TestLang( 'es' );
TestLang( 'fr' );
// etc..
?>
+2

$result=bindtextdomain($domain,$path), , . , ( ) www. - . /locale/LC _MESSAGES/nld_nld/

textdomain($domain) ( gettext). bindtextdomain textdomain ( ) mo .

, php , "require_once".

BTW, , ( ) nld_nld , ( , "en" ).

0

All Articles