Solved

gettext doesnt read mo/po files

Posted on 2014-09-29
9
117 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to dynamically set the form action using jQuery.
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…

911 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now