/** * 快速获取语言包文件 * Enter description here ... * @param unknown_type $str */ function L($cStr, $lang = null) { if ($lang == null) { $lang = getBrowserLang(); } include "CleverPHP/Lang/" . C("Lang") . ".php"; $rows = $CleverLang; if (file_exists(AppDir . "/Lang/{$lang}.php")) { include AppDir . "/Lang/{$lang}.php"; if (isset($Lang) && isset($CleverLang)) { $rows = array_merge($CleverLang, $Lang); } } if (array_key_exists($cStr, $rows)) { return $rows[$cStr]; } else { return "找不到字段"; } }
<?php $lang = getBrowserLang(); $site = 'http://cisample.localhost/'; switch ($lang) { case 'jp': header('Location: ' . $site . 'jp/'); break; case 'en': header('Location: ' . $site . 'en/'); break; case 'th': default: header('Location: ' . $site . 'th/'); break; } function getBrowserLang($defaultLang = 'th') { $result = ''; if (!empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { $languages = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']); $languages = array_reverse($languages); foreach ($languages as $lang) { if (preg_match('/^ja/i', $lang)) { $result = 'jp'; } elseif (preg_match('/^en/i', $lang)) { $result = 'en'; } elseif (preg_match('/^th/i', $lang)) { $result = 'th'; } }
<?php //Website configuration file ini_set('display_errors', 1); error_reporting(E_ALL); setlocale(LC_ALL, 'fr_FR.utf8'); date_default_timezone_set('Europe/Paris'); mb_internal_encoding('UTF-8'); session_start(); define('SITE_NAME', 'Funky Time Traveler'); define('AUTHOR', 'The 5 stars'); define('VERSION', '1.1'); /* Set the language according to the browser */ $lang_accept = array('fr', 'en'); if (!isset($_SESSION['lang'])) { $_SESSION['lang'] = getBrowserLang(); if ($_SESSION['lang'] != 'fr') { $_SESSION['lang'] = 'en'; } } if (!isset($_SESSION['sound'])) { $_SESSION['sound'] = 'on'; } /** * Autoload class function * Search in model and view folders */ spl_autoload_register(function ($class) { if (is_file('./model/' . $class . '.php')) { require './model/' . $class . '.php'; } else {