[eluser]StaMiNa[/eluser]
Hello,
I wrote a MY_Language class, and a share to us. Propably it isn't a good code, but works.
Store your translations in mysql database. I'm using only hungarian translations, so the language switcher not correct!
MY_Language.php
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* Kiegészítő az adatbázisban tároláshoz. Új szó/kifejezése felvétele stb...
*
* @package CodeIgniter
* @author Sztreha Balázs
* @since Version 0.5b
* @filesource
*/
// ------------------------------------------------------------------------
class MY_Language extends CI_Language {
public $dictionary_table = "dict";
/* CREATE TABLE `dict` (
`dict_id` bigint(20) NOT NULL auto_increment,
`name` varchar(255) NOT NULL,
`english` text NOT NULL,
`hungarian` text NOT NULL,
PRIMARY KEY (`dict_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
*/
function insertWord($word, $name='', $lang='')
{
$this->CI = & get_instance();
if($lang=='') $lang = $this->CI->config->item('language'); /* swicth current language */
$this->load('global', $lang);
if($name=='') $u_word = $this->correctUniqueText($word);
else $u_word = $this->correctUniqueText($name);
$insert['name']=$u_word;
$insert[$lang]=$word;
$this->CI->db->set($insert);
// Check that the insert did not fail
if ($this->CI->db->insert($this->dictionary_table) === FALSE)
{
return FALSE;
}
return $u_word;
}
function updateWord($word, $name, $lang='')
{
$this->CI = & get_instance();
if($lang=='') $lang = $this->CI->config->item('language'); /* swicth current language */
if($name!=''){
$update[$lang]=$word;
$this->CI->db->where('name', $name);
// Check that the update did not fail
if ($this->CI->db->update($this->dictionary_table, $update) === FALSE)
{
return FALSE;
}
} else return FALSE;
return TRUE;
}
function deleteWordName($name){
// ha véletlenül kettő ugyanolyan nevű (name) szó lenne akkor nem törli le, de elvileg ilyen nemn lehet, mert egyedi a name
$this->CI = & get_instance();
if(is_array($name)){
$this->CI->db->where_in('name', $name);
if($this->CI->db->delete($this->dictionary_table)) return TRUE;
else return FALSE;
} else {
$this->CI->db->where('name', $name);
$query = $this->CI->db->get($this->dictionary_table);
if($query->num_rows() == 1){
$row=$query->result();
$this->CI->db->where("dict_id", $row[0]->dict_id);
if($this->CI->db->delete($this->dictionary_table)) return TRUE;
else return FALSE;
} else {
return FALSE;
}
}
}
function correctUniqueText($word)
{
$this->CI = & get_instance();
$this->CI->load->helper('text');
$u_word = correct_text_accent($word); /* ékezetek eltűntetése */
$nem_ok=true;
$new_u_word = $u_word;
while($nem_ok){
if($this->line($new_u_word)){
$new_u_word = $u_word."_".rand(0,999);
} else {
$nem_ok=false;
}
}
return $new_u_word;
}
function getWords($array)
{
$this->CI = & get_instance();
//if($lang=='') $lang = $this->CI->config->item('language'); /* swicth current language */
$this->CI->db->select('name, hungarian'); /* 'hungarian' -> $lang */
$query = $this->CI->db->get($this->dictionary_table);
foreach($query->result() as $row){
$array[$row->name]=$row->hungarian;
}
}
function getWord($name){
$this->CI = & get_instance();
$this->CI->db->where('name', $name);
$query = $this->CI->db->get($this->dictionary_table);
if($query->num_rows()){
$word = $query->result();
return $word[0];
} else {
return false;
}
}
}
// END MY_Language Class
/* End of file MY_Language.php */
/* Location: ./system/application/libraries/MY_Language.php */