I want to Internationalize my website, so I have download gettext librairie (I work on my localhost and I have disable gettext module).
I followed a tutorial is the translation works :
- When I go to http://localhost/mysite/index.php is the default language
- When I go to http://localhost/mysite/index.php/?lang=en_US is the US language
But all my website is completely broken when I use /?lang=en_US
.
Google chrome errors :
Resource interpreted as Stylesheet but transferred with MIME type text/html: "http://localhost/mysite/index.php/assets/bootstrap/css/bootstrap.min.css".
localhost/:11 Resource interpreted as Stylesheet but transferred with MIME type text/html: "http://localhost/mysite/index.php/assets/fonts/font-awesome/css/font-awesome.min.css".
localhost/:12 Resource interpreted as Stylesheet but transferred with MIME type text/html: "http://localhost/mysite/index.php/assets/stylesheets/custom.css".
?lang=en_US:13 Resource interpreted as Stylesheet but transferred with MIME type text/html: "http://localhost/mysite/index.php/assets/stylesheets/media-queries.css".
jquery-1.11.3.min.js:2 Uncaught SyntaxError: Unexpected token <
bootstrap.min.js:2 Uncaught SyntaxError: Unexpected token <
?lang=en_US:97 Uncaught ReferenceError: $ is not defined
at ?lang=en_US:97
(anonymous) @ ?lang=en_US:97
?lang=en_US:142 Uncaught ReferenceError: $ is not defined
at ?lang=en_US:142
(anonymous) @ ?lang=en_US:142
?lang=en_US:138 Resource interpreted as Stylesheet but transferred with MIME type text/html: "http://localhost/mysite/index.php/assets/stylesheets/dataTables.bootstrap.min.css".
jquery.dataTables.min.js:2 Uncaught SyntaxError: Unexpected token <
dataTables.bootstrap.min.js:2 Uncaught SyntaxError: Unexpected token <
dataTables.datesorting.js:2 Uncaught SyntaxError: Unexpected token <
This is my localization file :
<?php
error_reporting(E_ALL | E_STRICT);
// define constants
define('PROJECT_DIR', realpath('./'));
define('LOCALE_DIR', PROJECT_DIR .'/locale');
define('DEFAULT_LOCALE', 'fr_FR');
require_once('./librairies/gettext/gettext.inc');
$supported_locales = array('en_US', 'fr_FR');
$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 = 'traduction';
bindtextdomain($domain, LOCALE_DIR);
// bind_textdomain_codeset is supported only in PHP 4.2.0+
if (function_exists('bind_textdomain_codeset'))
bind_textdomain_codeset($domain, $encoding);
textdomain($domain);
header("Content-type: text/html; charset=$encoding");
?>
And here is a part of my index file :
<?php require_once __DIR__.'/localization.php'; ?>
<!DOCTYPE html>
<html lang="fr" class="no-js">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<title><?php echo $title; ?> - Mysite</title>
<link rel="stylesheet" href="./assets/bootstrap/css/bootstrap.min.css">
....
<script src="./assets/javascripts/bootstrap/bootstrap.min.js"></script>
</head>
<body>
<h1><?php echo _("BIENVENUE !"); ?></h1>
<h1><?php echo _("maison"); ?></h1>
Can you help me to resolve this ?
Thank you