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

  • Home
  • SEARCH
  • 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 8348139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:36:11+00:00 2026-06-09T07:36:11+00:00

test.php file echoes some greek letters for testing <head> <meta charset = UTF-8 />

  • 0

test.php file echoes some greek letters for testing

<head>
<meta charset = "UTF-8" />
</head>
<?php
$language = "en_US";
$lang_path = "language";
putenv("LC_ALL=$language");
setlocale(LC_ALL, $language);
bindtextdomain("lang", $lang_path);
bind_textdomain_codeset("lang","UTF-8");
textdomain("lang");
echo gettext("α");
echo gettext("β");
echo gettext("γ");
echo gettext("δ");
echo gettext("ε");
echo gettext("ζ");
?>

My folders and files are structured like

 language/en_US/LC_MESSAGES/lang.mo and lang.po

mo file is correctly compiled, and it must translate to abcdez. In poedit i have used utf-8 everywhere. The code produces αβcδεζ , so only letter c is translated! I have restarted my server, i have en_US encoding installed in my system and i can’t understand why only one letter is translated..

  • 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-06-09T07:36:13+00:00Added an answer on June 9, 2026 at 7:36 am

    A simple implementation i wrote reading zend and cakephp code. It does not support plurals, and it simply replaces words, so you can replace not only from one language.

    test.php file

    <head>
    <meta charset = "UTF-8" />
    </head>
    <?php
        require_once "gettext.php";
        echo __("something");
        echo __("α");
        echo __("β");
        echo __("γ");
        echo __("δ");
        echo __("ε");
        echo __("ζ");
    ?>
    

    gettext.php file

    <?php
    define('APPPATH','/opt/lampp/htdocs/test/');
    /* please change APPPATH to an ultimate directory of the language folder */
    
    /**
     * Loads the binary .mo file and returns array of translations
     *
     * @param string $filename Binary .mo file to load
     * @return mixed Array of translations on success or false on failure
     */
        function loadMo($filename) {
            $translations = false;
    
            // @codingStandardsIgnoreStart
            // Binary files extracted makes non-standard local variables
            if ($data = file_get_contents($filename)) {
                $translations = array();
                $header = substr($data, 0, 20);
                $header = unpack("L1magic/L1version/L1count/L1o_msg/L1o_trn", $header);
                extract($header);
    
                if ((dechex($magic) == '950412de' || dechex($magic) == 'ffffffff950412de') && $version == 0) {
                    for ($n = 0; $n < $count; $n++) {
                        $r = unpack("L1len/L1offs", substr($data, $o_msg + $n * 8, 8));
                        $msgid = substr($data, $r["offs"], $r["len"]);
                        unset($msgid_plural);
    
                        if (strpos($msgid, "\000")) {
                            list($msgid, $msgid_plural) = explode("\000", $msgid);
                        }
                        $r = unpack("L1len/L1offs", substr($data, $o_trn + $n * 8, 8));
                        $msgstr = substr($data, $r["offs"], $r["len"]);
    
                        if (strpos($msgstr, "\000")) {
                            $msgstr = explode("\000", $msgstr);
                        }
                        $translations[$msgid] = $msgstr;
    
                        if (isset($msgid_plural)) {
                            $translations[$msgid_plural] =& $translations[$msgid];
                        }
                    }
                }
            }
            // @codingStandardsIgnoreEnd
    
            return $translations;
        }   
    
        /*
            Your system folder must be ULTIMATE_PATH/language/$language
            where language is a parametre like en,el,fr or english or whatever
            domain is the name of the mo file without mo extension e.g. default
            You can pass this parameteres with the __ function below
        */
        function translate($singular, $language = null, $domain = null) {
            $directory = APPPATH."language/"; // your path to language folder
            if (strpos($singular, "\r\n") !== false) {
                $singular = str_replace("\r\n", "\n", $singular);
            }
    
            if (is_null($language) ) { // default el
                $language = "el";
            }
    
            if (is_null($domain)) {
                $domain = "default";
            }
    
            $localeDef = $directory . $language;
            $file = $localeDef."/".$domain;
            $translations = null;
    
                    if (is_file($file . '.mo')) {
                        $translations = loadMo($file . '.mo');
                    }
    
            if (!empty($translations[$singular])) {
    
                    $trans = $translations[$singular];
    
                    if (strlen($trans)) {
                        return $trans;
                    }
                }
    
            return $singular;
        }
        /*
        take language (must be in language folder) from $_GET["lang"];
        */
        function __($singular) {
            if (!$singular) {
                return;
            }
            if (isset($_GET["lang"]) ) // you can use cookie, session etc
                $translated = translate($singular,$_GET["lang"]);
            else 
                $translated = translate($singular);
            return $translated;
        }
    ?>
    

    In my code i have default language el, and you get the language with GET[‘lang’]. (You can change that to a COOKIE, SESSION etc. Also the mo files must be called default.mo. (You can change that also in the code). So you can have in your directory:

    test.php
    gettext.php
    language/el/deafult.mo
    language/en/default.mo
    

    default is el/default.mo and you can change to en with ?lang=en in your url.

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

Sidebar

Related Questions

I have a test.php file and this file contains some PHP code, HTML elements
My test.php file contains the following information that is sends list of information. while($row
I have a button on a file test.php <?php $url=http://.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; ?> <input type=button name=btn
I created an error500.php file in web/errors/ and would now like to test it.
Win7-HUN, UTF8 PHP file. function Test($Msg){ $Result = ; $ReplFrom = ő; $ReplTo =
Stupid question, this code: <?php $variable = system(cat /home/maxor/test.txt); echo $variable; ?> with file
I have a php file, for example www.example.com/folder/test.php The file above (test.php) has the
Let's say I have a php file, test.php with 2 functions: test1() and test2().
I tried to just send some information to a php file using Jquery Ajax.
I have a billboard.js script running on a simple php file and for some

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.