Solved

gettext doesnt read mo/po files

Posted on 2014-09-29
9
118 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
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…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

776 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