Solved

gettext doesnt read mo/po files

Posted on 2014-09-29
9
119 Views
Last Modified: 2014-09-30
Hello fellow experts. Long time no see. Looks like I'm too tired to see the error at the code.
I have a class which have this as a constructor:

public function __construct()
		{
			//some code before this part
			if (isset($_GET["lang"])) {
				$language = $_GET["lang"];
			}
			else if (defined('LANGUAGE')) {
				$language  = LANGUAGE;
			}
			else {
				$language = "sr";
			}
			$this->setLocalization($language);
		}

Open in new window


And the method setLocalization:

public function setLocalization($code) {
							   $langCodes = array(
								 "sr" => "sr_RS",
								 "de" => "de_DE",
								 "en" => "en_US"
							   );
			if(!isset($langCodes[strtolower($code)])) {
				return;
			}
			$baseLangDir = './locale';
			$appName     = "office";
			$lang = $langCodes[strtolower($code)];
			// Set language
			putenv('LC_ALL='.$lang);
			//putenv("LANG=" . $code); 
			setlocale(LC_ALL, $lang);
		  
			// Specify the location of the translation tables
			bindtextdomain($appName, realpath($baseLangDir));
			bind_textdomain_codeset($appName, 'UTF-8');
			// Choose domain
			textdomain($appName);
		}

Open in new window


Im getting proper language code in it, and a path in bindtextdomain is properly resolved.
My directory structure is:

root
|__locale
            |__en_US
                       |__LC_MESSAGES
            |__sr_RS
                       |__LC_MESSAGES
            |__de_DE
                       |__LC_MESSAGES

There is a pair of office.mo/office.po files in each LC_MESSAGES directory.
For some reason command like:

<?php echo _("Dashboard"); ?>

Open in new window


gives only Dashboard even if its translated in mo/po.
What is the problem here, what am I missing?

Thanks in advance.
0
Comment
Question by:R-Byter
  • 5
  • 4
9 Comments
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 40351235
There is nothing but the word "Dashboard" in your echo statement.  No file path or function to return anything else.
0
 
LVL 14

Author Comment

by:R-Byter
ID: 40351252
I dont see the problem there cause _() is the same as gettext(). Its the proper way to use it.

http://php.net/manual/en/function.gettext.php
0
 
LVL 14

Author Comment

by:R-Byter
ID: 40351254
As additional note, its Debian Linux and this is what I get when I type locale -a:

C
POSIX

Thanks
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 40351269
Except that it isn't working.  Try the simple example on the man page with the values hard coded and see what you get.
0
 
LVL 14

Author Comment

by:R-Byter
ID: 40351284
Still doesnt work.
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 40351327
I won't be able to look at this again until tomorrow.
0
 
LVL 83

Accepted Solution

by:
Dave Baldwin earned 500 total points
ID: 40351615
On my Ubuntu system, locale -a gives me:

C
en_AG
en_AU.utf8
en_BW.utf8
en_CA.utf8
en_DK.utf8
en_GB.utf8
en_HK.utf8
en_IE.utf8
en_IN
en_NG
en_NZ.utf8
en_PH.utf8
en_SG.utf8
en_US.utf8
en_ZA.utf8
en_ZW.utf8
POSIX

I don't know where it gets all that.
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 40351623
In my Package Manager, I found a package called 'locales' that supposedly installed all that.  Maybe this will help: https://wiki.debian.org/Locale
0
 
LVL 14

Author Closing Comment

by:R-Byter
ID: 40351889
That's it, missing locales on some strange custom debian installation.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
jQuery force form POST 7 52
Test if unique ID is in log file 5 22
PHP Mail error 3 28
Having trouble getting Imagick working with php on windows. 2 23
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question