Gettext会产生很多错误(页面完全坏了)

时间:2017-04-06 13:37:58

标签: php internationalization localhost loading gettext

我想将我的网站国际化,所以我下载了gettext librairie(我在我的localhost上工作,我已经禁用了gettext模块)。

我遵循的教程是翻译工作:

但是当我使用/?lang=en_US时,我的所有网站都完全被破坏了。

Google Chrome错误:

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 <

这是我的本地化文件:

<?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");
?>

这是我索引文件的一部分:

<?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>

你能帮我解决这个问题吗?

谢谢

1 个答案:

答案 0 :(得分:0)

您指向css的链接有错误。我认为页面 index.php 的名称会导致此错误:

http://localhost/mysite/index.php/assets/stylesheets/dataTables.bootstrap.min.css