Warning: array_merge() [function.array-merge]: Argument #2 is not an array in /home/dvoyage/public_html/ult/ult.php on line 353

Warning: array_merge() [function.array-merge]: Argument #1 is not an array in /home/dvoyage/public_html/ult/ult.php on line 353

Warning: array_merge() [function.array-merge]: Argument #2 is not an array in /home/dvoyage/public_html/ult/ult.php on line 361

Warning: array_merge() [function.array-merge]: Argument #1 is not an array in /home/dvoyage/public_html/ult/ult.php on line 353

Warning: array_merge() [function.array-merge]: Argument #2 is not an array in /home/dvoyage/public_html/ult/ult.php on line 353

Warning: array_merge() [function.array-merge]: Argument #1 is not an array in /home/dvoyage/public_html/ult/ult.php on line 353

Warning: array_merge() [function.array-merge]: Argument #2 is not an array in /home/dvoyage/public_html/ult/ult.php on line 353

Warning: array_merge() [function.array-merge]: Argument #1 is not an array in /home/dvoyage/public_html/ult/ult.php on line 353

Warning: array_merge() [function.array-merge]: Argument #2 is not an array in /home/dvoyage/public_html/ult/ult.php on line 353

Warning: array_merge() [function.array-merge]: Argument #2 is not an array in /home/dvoyage/public_html/ult/ult.php on line 353

Warning: array_merge() [function.array-merge]: Argument #1 is not an array in /home/dvoyage/public_html/ult/ult.php on line 353

Warning: array_merge() [function.array-merge]: Argument #2 is not an array in /home/dvoyage/public_html/ult/ult.php on line 353

Warning: array_merge() [function.array-merge]: Argument #2 is not an array in /home/dvoyage/public_html/ult/ult.php on line 361

Warning: array_merge() [function.array-merge]: Argument #1 is not an array in /home/dvoyage/public_html/ult/ult.php on line 353

Warning: array_merge() [function.array-merge]: Argument #2 is not an array in /home/dvoyage/public_html/ult/ult.php on line 353
ULT - Universal Language Tool for PHP

##Universal Language Tool for PHP##

Recognizing the problem * The solution * Realization * Language definitions * Language dictionaries * Transliteration * Language families * How to prepare documents * Properties and methods * How to use library * Download * Support forum *Contact


This script is listed on HotScripts. If you use it and you like it, write a review please.

What is ULT

After looking for multilanguage solution we in DataVoyage realized that we need to write our own. Before you comment this as just another multi language support PHP library take a look for some specific usage this library offers.

Univeral Language Tool for PHP is library developed to introduce new concept in multilanguage application development for WEB. It offers functionality which covers unlimited number of languages on single site, but in literal manner. It does not support just widely recognized term of languages but also expands to support language variations. You are provided with tools to use language macros in your documents which are replaced with exact text according to language dictionaries. However, you also are provided with transliteration tool, which allows direct text replacement in document with no need for predefined macros. The replacement is done according to transliteration rules specific for each language.

If you ever developed site which is targeted to audience which uses the same language but with some variations (example: English and American English, or variations of Spanish language, or the same language that uses two scripts, like Serbian Latin and Serbian Cyrillic) you met this problem. Usual multi language solutions force you to treat all these variations as different languages, which makes, not just development, but administration and site maintenance quite complicated tasks. ULT treats all variations as the same language, but it introduces difference rules. This means you are entitled to update site in just one language, and if needed, ULT will alter original document to create its variation according to predefined language variation rules including transliteration.

Recognizing the problem

What is the goal we wanted to be accomplished? Well, most of the multi language libraries are basically simple. You have definitions for language macros for wanted languages, and loaded page knows which one to use to alter page contents. Libraries mostly differ in approaches but essence is the same.

We develop web sites for a long time, and since our clients are mostly in Serbia we are faced with multi language problem on many occasions. Surely we solved it in the same manner as described, but we always had problems with that way.

Serbian language presents specific problem - the language may use two scripts: Cyrillic an Latin. We usually treated this two scripts as two languages and got usable results but not satisfactory. Although two scripts do act as different languages, they are actually not. Differences among scripts are just that - different scripts are used, but everything else is the same (with some minor issues). It is against common sense to treat them as different languages, creating separate dictionaries or bitmap sets or whatever else on site is language dependable, just for minor differences. That would be a nightmare, not just to create but also to maintain.

Although Serbian language is probably unique about using two scripts, other languages do have their variations, take a look at variations of English or Spanish language.

After some thoughts we came to this conclusion: A language is complex and usually it has some variations, but those variations are different in minor ways and usually by following some definite rules and exceptions. Thus, we should not deal with language variations as language themselves, but as such - VARIATIONS of original language. This conclusion is the basic idea for ULT.

We recognized two ways language variations may differ: by dictionary (some words, phrases or spelling differences may be different) and by script (this may be literally as in Serbian that each letter has it's Cyril and Latin representation) or simply by using different code pages).

The solution

After trying several approaches we came to the final solution: to allow definition of language as such with one improvement - we allow language to be defined as child of another language. That allows us to have mechanism to provide basic language definitions and variations to them.

What the script does when language information is needed is to merge basic language with variation differences and thus produce complete language variation as new language. What we got is that you actually have to define and maintain just basic languages for your site and define variations through rules of differences. If you change something in definition of basic language it will reflect all it's variations. This means, if you have to define dictionary, you will have to do it just for basic language. Variation will only have definition for difference rules.

Let's see an example for English language:

There are few differences among English and American English in words spelling. For instance, English word colour is spelled color in American English. ULT allows you to have both variations on your site but there is no need to define whole dictionaries for both. You will have English language fully defined and for American English you will state that it is child of English language with spelling difference for word colour. And that is all. Whenever your page is loaded in American English, dictionary of English language would be used but with variation differences applied. So, resulting document will have all occurrences of word colour replaced with word color.

Realization

We have created ULT PHP class (stored in ult.php) which deals with the problem. It does most of the job automatically. Your job is to initialize object, set some parameters and, of course, define some languages.

Here is an simple example of it's usage.

##SOURCE_CODE##

<?php

//this code deals with passing parameters


if ($HTTP_POST_VARS) {
 foreach(array_keys($HTTP_POST_VARS) as $Var) {
   $$Var=$HTTP_POST_VARS[$Var];
 };
};
 
if ($HTTP_GET_VARS) {
 foreach(array_keys($HTTP_GET_VARS) as $Var) {
   $$Var=$HTTP_GET_VARS[$Var];
 };
};
 
 // include Universal Language Tool library in page code
include_once('ult.php');


// language id parameter is stored in $lang
// we have to initialize it if parameter value not passed
if (! $lang) $lang = 'en'; 


// create language object, this will also load all language
//definitions stored in -lang directory
$dvl = new ULT;


// now set source language (language that is used to design page)
// this is not necessary if you set [is_source_lng] property of rone of the language definitions $dvl->set_source_language ('en'); // set display language (language that is actualy used on page) $dvl->set_display_language ($lang); // start output buffering. This must be done to allow multilanguage processing $dvl->block_start(); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>ULT Test</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> </head> <body> <p> <?php // this will diplay list of all languages whose definitions are loaded foreach ($dvl->lang_defs as $m_lang) $m_lang_name = $m_lang['name']; $m_lang_id = $m_lang['id']; echo "<a href=\"index.php?lang=$m_lang_id\">$m_lang_name</a> " $m_lang = $dvl->lang_defs[$lang]; } ?> </p>

<p># #LANGUAGE_TEST# #</p>

<p># #Language# #:<?php echo "$m_lang[name] ($lang)" ?><p> <p># #Family# #: <img src="img/lngpic=%en=.gif" width="49" height="12">
<p># #OK# # # #CANCEL# # # #ABORT# # # #CONFIRM# # # #COLOUR# #<p>

</body>
</html>
<?php $dvl->block_end() ?>


##EXECUTION_RESULT##

english
Fatal error: Cannot access empty property in /home/dvoyage/public_html/ult/index.php on line 194