0

Hi i have been struggling since 3 days to fix the issue but its not working at all.

However this works perfectly fine on my web server which is HostGator. But not in my local XAMPP installation. i have read everything online available but no success.

Here is my Code.

<?php
    if(!defined('ROOT_DIR')) {
        exit();
    }

    $codeset    = "UTF8";  // warning ! not UTF-8 with dash '-'
    $lang       = "es_ES";   
    $secondary  = "es";
    // for windows compatibility (e.g. xampp) : theses 3 lines are useless for linux systems

    putenv('LANG='.$lang.'.'.$codeset);
    putenv('LANGUAGE='.$lang.'.'.$codeset);
    bind_textdomain_codeset('login_script', $codeset);

    // set locale
    bindtextdomain('login_script', ROOT_DIR.'/locale');
    setlocale(LC_ALL, array($lang.'.'.$codeset, $lang, $secondary)) or die('Locale not installed');
    textdomain('login_script');


    echo gettext("Welcome to Dashboard");

ROOT_DIR.'/locale' produces correct path to the language files.

My language folder structure.

  • locale > es_ES > LC_MESSAGES > login_script.po
  • locale > es_ES > LC_MESSAGES > login_script.mo
  • locale > es > LC_MESSAGES > login_script.po
  • locale > es > LC_MESSAGES > login_script.mo

It's working perfectly fine on my hosting or web server. But in XAMPP it's not working at all. If someone can give me a hint how to solve this problem i would be very thankful.

My .po file view.

    msgid ""
msgstr ""
"Project-Id-Version: Login Script V 4.0\n"
"POT-Creation-Date: 2020-01-28 01:36+0500\n"
"PO-Revision-Date: 2020-01-28 23:35+0500\n"
"Language-Team: Webful Creations <ateeq@webfulcreations.com>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 2.2.4\n"
"X-Poedit-Basepath: ..\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Poedit-KeywordsList: _;_e\n"
"X-Poedit-SourceCharset: UTF-8\n"
"Last-Translator: \n"
"Language: es_ES\n"
"X-Poedit-SearchPath-0: .\n"

#: all.php:7
msgid "Accessible only loged in users All types"
msgstr "Accesible sólo ha publicado en usuarios Todos los tipos"

One thing would like to mention. My XAMPP is installed in C: Drive but i have kept htdocs in F:/ drive.

I already have enabled extension=intl

So what is the wrong thing i am doing?

If i echo

echo (setlocale(LC_ALL, $lang.'.'.$codeset));

on Web server this returns >> es_ES.UTF8

And if i echo it on XAMPP localhost. It returns empty or null.

Also if i try setlocale(LC_ALL, 'es'.'.'.$codeset)

Then it returns TRUE but translation is not happening.

What is the problem with it?

If we follow answers of this question. PHP setlocale has no effect

That makes sense the locale isn't installed. Then the question how to install in XAMPP? How to run commands in Shell for XAMPP which i tried in Shell from XAMPP control panel also tried in php directory php.exe. No command worked.

  • This Answer tells that Locale for es_ES isn't installed. Then how to install it? They say if you have shell access. My Question is specefic to XAMPP where XAMPP shell is not accepting the commands that answer shared. I also tried with php.exe from php folder. No success. – Ateeq Rafeeq Jan 28 '20 at 19:39
  • UTF8 is not a supported Windows locale: https://stackoverflow.com/questions/9489339/setlocalelc-all-en-gb-utf8-not-working-on-windows – Olivier Jan 28 '20 at 19:57
  • 1
    setlocale(LC_ALL, "es_ES.utf8") returns NULL, setlocale(LC_ALL, "es_ES") returns NULL, setlocale(LC_ALL, "es") Returns correct but translation doesn't proceed. – Ateeq Rafeeq Jan 28 '20 at 20:40
  • On Windows you want something like `esn`. See [Microsoft reference](https://learn.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-2010/39cwe7zf(v=vs.100)?redirectedfrom=MSDN) for further info. – Álvaro González Jan 29 '20 at 17:29

0 Answers0