<?php
/**
* Large number of translations can be divided into modules.
* Perfect for MVC.
*/
include 'CrutchTranslate.php';
$database = array(
'server' => 'localhost',
'username' => 'root',
'password' => '',
'name' => 'crutchtext',
);
$connect = mysql_connect($database['server'], $database['username'], $database['password']);
mysql_select_db($database['name'], $connect);
$ct = new CrutchTranslate;
// set database connection
$ct->db_connect = $connect;
// or set access, connects automatically
$ct->db = $database;
// translated color for save
$data = Array
(
'x_blue' => Array
(
1 => '%s modra',
2 => '%s modre',
5 => '%s modrych',
),
'x_red' => Array
(
1 => '%s cervena',
2 => '%s cervene',
5 => '%s cervenych',
),
'x_green' => Array
(
1 => '%s zelena',
2 => '%s zelene',
5 => '%s zelenych',
),
);
$ct->save($data, 'cz', 'color');
// translated fruit for save
$data = Array
(
'x_banana' => Array
(
1 => '%s banan',
2 => '%s banany',
5 => '%s bananu',
),
'x_apple' => Array
(
1 => '%s jablko',
2 => '%s jablka',
5 => '%s jablek',
),
'x_pear' => Array
(
1 => '%s hruska',
2 => '%s hrusky',
5 => '%s hrusek',
),
);
$ct->save($data, 'cz', 'fruit');
// set language
$ct->lang = 'cz';
// set limits for plural (in any order)
$ct->limit[] = 2; #plural 2+
$ct->limit[] = 5; #plural 5+
// set module
$ct->module[] = 'fruit';
echo $ct->translate('x_banana', 1);
echo $ct->translate('x_apple', 3);
echo $ct->translate('x_pear', 7);
echo $ct->translate('x_red', 5); #error, this IDF not in 'fruit' module
/**
* OUTPUT
*
* 1 banan
* 3 jablka
* 7 hrusek
* x_red
*/
$ct->module[] = 'color';
echo $ct->translate('x_red', 5); #error, translations are loaded, are not loaded again
/**
* OUTPUT
*
* x_red
*/
|