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
https://forums.phpfreaks.com/topic/25422-gettext-problems/
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
https://forums.phpfreaks.com/topic/25422-gettext-problems/#findComment-116031
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
https://forums.phpfreaks.com/topic/25422-gettext-problems/#findComment-116060
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.