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.