Solved

gettext doesnt read mo/po files

Posted on 2014-09-29
9
122 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
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…

696 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