PHP Classes

File: example.php

Recommend this page to a friend!
  Classes of Ladislav Vondracek   Crutch Translate   example.php   Download  
File: example.php
Role: Example script
Content type: text/plain
Description: example
Class: Crutch Translate
Retrieve and manage text translations from MySQL
Author: By
Last change:
Date: 13 years ago
Size: 2,072 bytes
 

Contents

Class file image Download
<?php
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;


// translations for save
$data = Array
(
   
'you_have_x_message' => Array
        (
           
1 => 'Mate %s zpravu.',
           
2 => 'Mate %s zpravy.',
           
5 => 'Mate %s zprav.',
        ),
   
'you_get_x_point' => Array
        (
           
1 => 'Dostali jste %s bod.',
           
2 => 'Dostali jste %s body.',
           
5 => 'Dostali jste %s bodů.',
        ),
   
'found_x_error' => Array
        (
           
1 => 'Nalezena %s chyba.',
           
2 => 'Nalezeny %s chyby.',
           
5 => 'Nalezeno %s chyb.',
        ),
   
'msg_logout' => Array
        (
           
1 => 'Byli jste odhlaseni.',
        ),
);
$ct->save($data, 'cz');


// set language
$ct->lang = 'cz';

// set limits for plural (in any order)
$ct->limit[] = 2; #plural 2+
$ct->limit[] = 5; #plural 5+


echo $ct->translate('lorem_ipsum'); #error, translate for IDF 'lorem_ipsum' not exists
echo $ct->translate('you_have_x_message', 1);
echo
$ct->translate('you_get_x_point', 3);
echo
$ct->translate('found_x_error', 7);
echo
$ct->translate('msg_logout', 5); #error, translate for limit 5+ not exists
echo $ct->translate('msg_logout');

/**
 * OUTPUT
 *
 * lorem_ipsum
 * Mate 1 zpravu.
 * Dostali jste 3 body.
 * Nalezeno 7 chyb.
 * msg_logout
 * Byli jste odhlaseni.
 */


/**
 * Large number of translations can be divided into modules.
 */
$ct->module[] = 'color';

$data = Array
(
   
'blue' => Array
        (
           
1 => 'modra',
        ),
   
'red' => Array
        (
           
1 => 'cervena',
        ),
   
'green' => Array
        (
           
1 => 'zelena',
        ),
);
$ct->save($data, 'cz', 'color');