ducvux10
New Member
- Messages
- 2
- Reaction score
- 0
- Points
- 1
I am new to web development and I want to create a small site, but I need it has multi-language support that I can easy to manage later.
So I create my first template (yeah, i think it still doesn't break your terms of service).
This template is simple, but i don't know that it can work with big data or not?
If anyone has any suggestion, please help to design a greater template, thanks.
//require.php
//index.php
So I create my first template (yeah, i think it still doesn't break your terms of service).
This template is simple, but i don't know that it can work with big data or not?
If anyone has any suggestion, please help to design a greater template, thanks.
//require.php
PHP:
<?php
ini_set( "short_open_tag", 1 );//Try if can
$_FORCE_LANGUAGE = true; //If restriction
/*******************************************************************/
class Language{
private $table = array();
public function __construct($data_file = null){
if (!$data_file) return;
//Load all word from xml file, implement later :)
//Test some word
$this->setKeyValue("del_confirm", "Are you sure want to delete this file?");
$this->setKeyValue("error", "Sorry, some error here!");
}
public function setKeyValue($key, $value){
$this->table[$key] = $value;
}
public function getKeyValue($key){
if (!array_key_exists($key, $this->table)) return $key; //return null ???
return $this->table[$key];
}
}
$lang_code = "en";
if (!$_FORCE_LANGUAGE) {
if (isset($_COOKIE["preferedLang"]))
$lang_code = $_COOKIE["preferedLang"];
//Other condition to choose language here...$_SERVER['HTTP_ACCEPT_LANGUAGE']...
}
$lg = new Language($lang_code . ".xml");
//Short of GET key value from $lg
function g($key){
global $lg;
return $lg->getKeyValue($key);
}
//index.php
PHP:
<?php
require("require.php");//Do this for all php file on server ?
?>
<!DOCTYPE html>
<html>
<head>
<title>Test Multi-Language</title>
</head>
<body>
<h3><?=g("site_heading")?></h3>
<p><?=g("del_confirm")?></p>
<div><?=g("error")?></div>
</body>
</html>