Important facts about commercial licenses

  • Licenses are perpetual. They do not expire and do not need to be renewed.
  • Licenses can be upgraded. You can upgrade to a more expensive license later paying only the difference in cost.
  • Pay attention to the distribution type - Hosted (sites / servers), binary (applications) or source (includes all the others). Choose according to your needs (more below).
  • All licenses allow commercial use unless otherwise indicated.
  • Read the full license by clicking on the icon.
  • Read more about licenses in our handy license guide.
$4

Personal License

1 site, unlimited servers No source distribution 6 months support
$49

Developer License

Unlimited projects Source and binary distribution 6 months support
You need to log-in or create an account
  • Create an account
  • Log-in
  • Please use your real name.
  • Account activation link will be sent to this address.
  • Minimum 8 characters

Clicking this button confirms you read and agreed to the terms of use and privacy policy.

  • Released: Sep 21, 2011
    Last Update: Sep 20, 2011
  • Language: PHP
  • Category: Database

Translation Component

Translation Component
Developed by Horia Jurcut, Released Sep 21, 2011

A PHP component that allows you to quickly add multiple language support to your website. Bring in the international crowd today!

PHP

Tags: multi-language support , translation

A very fast, very small translation component that you can quickly add to your website and start offering multi-language support. Taking advantage of MySql's powerful FULLTEXT index this is truly a highly efficient add-on.

The component is built in an Object Oriented style so it is very easy to integrate it in any project.

And it is really simple to use:

 $t = new TC_Translation();
 $t->t("This is the string I want to translate!");

All it takes is just two lines of code!

Back to top

Installation Steps & User Guide

Installation Steps

Step 1 - Editing my.ini

Because the translation component has a built in admin interface where you can search for strings in your websites, add new languages or translation we want to take advantage of the FULLTEXT feature that MySQL offers:

You have to edit your my.ini configuration file and under [mysqld] add these two lines:

 [mysqld]
  port=3306
  ft_stopword_file = ''
  ft_min_word_len = 3

The first variable ft_stopword_file tell the MySQL Server not to use any stopwords file. By default MySQL has a list of words that won't return any results via FULLTEXT search ( http://dev.mysql.com/doc/refman/5.5/en/fulltext-stopwords.html )

The next variable ft_min_word_len tells MySQL the length of the words you want to index. The recommended value for this variable is 3.

Step 2 - Importing the table structure

Inside the package you have a file translation.sql. Just import the table structure using phpMyAdmin or any other application.

Step 3 - Configuring the translation component

Also, inside the package you have the class file called TC_Translation.php. If you open it you should see something like this:

//Database connection
const TR_HOST = 'localhost';
const TR_USER = 'root';
const TR_PASS = '';
const TR_DB = 'translation';

//Language options
const MIN_INDEX_LENGTH = 3;

Step 4 - Using the component

Just include it like this, and you are all set to go:

<?php include "lib/TC_Translate.php"; ?>

The paths are different depending on where you choose to add the component to your website.

print $t->t('I want to translate this string');

Step 5 - Using the admin panel

Under the admin/ folder you have a administration interface that helps you translate the strings you wrapped around the t() method. You have a screenshot of its features. You can easily add CSS to make it look nice (admin/css/admin.css is already included).

Features under development

  • Use of plurals
  • Import and export PO files, for editing outside the website
  • Ability to index strings in js files

Thank you for using this component!

Back to top

DOC Reference

TC_Translation class

public function __construct()

Creates a MySQL connection and stores it in a private variable ( the class constructor ).

/**
 * boolean_search()
 *
 * @param string $str Unprepared string
 * @return string Prepared string
 */
public function boolean_search($str)

/**
 * boolean_match()
 *
 * @param string $str Unprepared string
 * @return string Prepared string
 */
public function boolean_match($str)

Two methods that prepare the string for a FULLTEXT search in "BOOLEAN MODE"

/*
 * setLanguage()
 *
 * @param string $lang Language code - sets the translation language
 * @return boolean true - if language was succesfully set, false - otherwise
 */
public function setLanguage($lang = "")

You can easily switch through the languages you want the text to be translated in.

/**
 * getLanguages()
 *
 * @param string $format Data format for languages
 * @return mixed All the languages in the database
 */
public function getLanguages($format = "array")

Returns all languages in the database.

/**
 * getAvailableTranslation()
 *
 * @param int $sid Unique string id
 * @return array
 */
public function getAvailableTranslations($sid)

Get all available translations for a given string.

/**
 * addLanguage()
 *
 * @param array $lang Language and language code
 * @return boolean True is insertion was successful, False otherwhise
 */
public function addLanguage($lang = array())

Add another language to the database.

/**
 * addTranslation()
 *
 * @param array $trans Translation details
 * @return boolean
 */
public function addTranslation($trans = array())

Add translation for a given string.

/**
 * search()
 *
 * @param string $str The keywords that were searched
 * @return array The search results
 */
public function search($str)

Search for a given string.

/**
 * t()
 *
 * @param string $str The string that needs to be translated
 * @return string The translated string
 */
public function t($str = "")

Translate a given string.

public function _destruct()

Closes the MySQL connection ( the class destructor ).

User Reviews

No reviews have been submitted yet.
Read all 2 comments »

Questions & Comments


Or enter your name and Email
You must be logged-in to vote. Log-in to your account or register now.