Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 930661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:22:25+00:00 2026-05-15T20:22:25+00:00

I have a little trouble getting gettext to work. I made a simple test

  • 0

I have a little trouble getting gettext to work. I made a simple test file where I call the translate.php and echo T_(“XXXXX”) and It get translated, but when I try to use echo T_ in a function it doesn’t work..

translate.php:

    <?php

error_reporting(E_ALL | E_STRICT);

// define constants
define('PROJECT_DIR', realpath('./functions/'));
//define('LOCALE_DIR', PROJECT_DIR .'/functions/locale');
define('LOCALE_DIR', PROJECT_DIR .'locale');
define('DEFAULT_LOCALE', 'en_US');

require_once('gettext.inc');

$supported_locales = array('en_US', 'sr_CS', 'de_CH');
$encoding = 'UTF-8';

$locale = (isset($_GET['lang']))? $_GET['lang'] : DEFAULT_LOCALE;

// gettext setup
T_setlocale(LC_MESSAGES, $locale);
// Set the text domain as 'messages'
$domain = 'messages';
T_bindtextdomain($domain, LOCALE_DIR);
T_bind_textdomain_codeset($domain, $encoding);
T_textdomain($domain);

//header("Content-type: text/html; charset=$encoding");
?>

working test file:

<?php
require("translate.php"); 

echo T_("test"); 

?>

That was just a test to see if it worked and the “test” word got translated as I was hoping to achieve. It gets a little bit more complicated with actual php files.

info.php

<?php

    require("functions\info_functions.php");

    (...)

    class infopage extends Page
    {
        public function display()
        {
        (...)

        displayInfo();

        (...)
        }
    }   


    $homepage = new infopage(); 
    $homepage->display();   

?>

info_functions.php – Here the echo doesn’t get translated!

<?php

require("translate.php"); 

echo T_("test"); 

            function displayInfo()
            {

            (...)

            echo T_("test"); 

            (...)

            }

?>  
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T20:22:25+00:00Added an answer on May 15, 2026 at 8:22 pm

    Check if your LOCALE_DIR environment variable is actually pointing to the correct place within displayInfo(). From:

    // define constants
    define('PROJECT_DIR', realpath('./functions/'));
    //define('LOCALE_DIR', PROJECT_DIR .'/functions/locale');
    define('LOCALE_DIR', PROJECT_DIR .'locale');
    

    It looks like it may be a relative path which doesn’t work from within info_functions.php since it is in a different directory to your other (test) files.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having a little trouble getting this to work. I have several anchor
I have been wrestling with getting databinding to work in WPF for a little
I'm having a little trouble getting an animated loading spinner to work for a
I'm having a little trouble getting localized resources files to work on Windows Phone
Hey guys, I'm getting a little trouble here. I have a view that makes
Little trouble in using css, in the below code, i have used odd and
I a having a little trouble with vector or array operations. I have three
I'm having a trouble with this little problem. Let's say, I have an array,
I'm a jQuery newbie, and I have trouble with a little script I created.
I am having a little trouble getting my deployment task in ant to function.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.