Translation Component

Translation Component

Released 7 years ago , Last update 7 years ago

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

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!


14 day 14-day money-back guarantee


Personal License

  • Perpetual license

  • 1 site, unlimited servers

  • No distribution (hosted use only)

  • Commercial use

  • 6 months support

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:

  ft_stopword_file = ''
  ft_min_word_len = 3

The first variable ftstopwordfile 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 ( )

The next variable ftminword_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

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!

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 ).

2 licenses, starting from From » $4.99 View Licenses

Get A Quote

What do you need?
  • Custom development
  • Integration
  • Customization / Reskinning
  • Consultation
When do you need it?
  • Soon
  • Next week
  • Next month
  • Anytime

Thanks for getting in touch!

Your quote details have been received and we'll get back to you soon.

Or enter your name and Email