Jump to content

gettext problems


pedro84

Recommended Posts

Hello!

I try to make translate my site with gettext function.
I have reade thins manual: [url=http://pl.php.net/manual/pl/function.gettext.php]http://pl.php.net/manual/pl/function.gettext.php[/url]

But I have problem.

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


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:
[code]setlocale(LC_ALL, $_SESSION["lang"] );
bindtextdomain("news", "./lang");
textdomain("news");[/code]

Exapmle .MO file:
[code]
msgid "Football"
msgstr "Fussbal"
[/code]

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

I call this by:
[code]echo _("Football");[/code]

And don't work.

Anyoe know what I'm doing wrong?
Link to comment
Share on other sites

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/manual/en/function.gettext.php

Link to comment
Share on other sites

My friend said me to try this:

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


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


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

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

What is wrong here?
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.