Jump to content


Photo

gettext problems


  • Please log in to reply
4 replies to this topic

#1 pedro84

pedro84
  • Members
  • PipPipPip
  • Advanced Member
  • 85 posts

Posted 28 October 2006 - 07:38 PM

Hello!

I try to make translate my site with gettext function.
I have reade thins manual: http://pl.php.net/ma...ion.gettext.php

But I have problem.

Languages on my main page changes with sessions, like this:
<?php
session_start();
require_once("langman.php");
if(!SelectLanguage($_SESSION["lang"]))
	die("Error selecting language!");
?>


Everything Works, but don't work in other scripts. So i tried to translate them with gettext.

In  main file of the script I put:
setlocale(LC_ALL, $_SESSION["lang"] );
bindtextdomain("news", "./lang");
textdomain("news");

Exapmle .MO file:
msgid "Football"
msgstr "Fussbal"

Path is corect as follow:
C:\usr\apache\httpd\html\news\lang\de_DE\LC_MESSAGES.

I call this by:
echo _("Football");

And don't work.

Anyoe know what I'm doing wrong?


#2 toplay

toplay
  • Staff Alumni
  • Advanced Member
  • 973 posts

Posted 28 October 2006 - 08:36 PM

Perhaps try calling the following in order (look at the manual on php.net for argument info):

putenv("LANG=" . $_SESSION["lang"]);

setlocale(LC_ALL, $_SESSION["lang"]);

bindtextdomain('domain', 'path');

bind_textdomain_codeset('domain', 'your char set');

textdomain('domain');

echo gettext('Football');  // or can use the shorter version: _('Football');


Source translation files should be the .po and the compiled/generated is .mo.

Try using something like poedit http://www.poedit.org to create your translations because it will tell you if you have an error (or duplicates), and it will generate the .mo files for you.


http://us3.php.net/m...ion.gettext.php



#3 pedro84

pedro84
  • Members
  • PipPipPip
  • Advanced Member
  • 85 posts

Posted 28 October 2006 - 08:59 PM

I have done it, but still doesn't work for me. I have reade this manual several times. Have anyone any suggestions.

#4 toplay

toplay
  • Staff Alumni
  • Advanced Member
  • 973 posts

Posted 28 October 2006 - 09:32 PM

What exactly do you mean by "I have done it..."?

Your original code example doesn't even use gettext() but just an echo.


#5 pedro84

pedro84
  • Members
  • PipPipPip
  • Advanced Member
  • 85 posts

Posted 28 October 2006 - 09:53 PM

My friend said me to try this:

mainfile
require 'lang/'.$_SESSION['lang'].'.php';


de.php
<php
$lang['HELO'] = 'NIEMIECKI';
?>


<?php
echo $lang['HELO'];
?>

But it shows me, only thi first letter oh lang, ex. d for de, p for pl

What is wrong here?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users