Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
Thread: php language packs?
01-18-2005, 06:12 PM #1
- Join Date
- Dec 2003
- Carrot River, Saskatchewan
- Thanked 9 Times in 9 Posts
php language packs?
Just curious in how hard it would be to create and implement a language pack for my scripts. How would I go about doing this?Dawson Irvine
CEO - DNI Web Design
01-18-2005, 07:49 PM #2
- Join Date
- Sep 2002
- Saskatoon, Saskatchewan
- Thanked 2,650 Times in 2,619 Posts
Its not really difficult at all, but it depends completely on what you have. Instead of doing any word hardcoded, you would create say a phrase index. So you would take your database, add a phrase table that has say, a variable name, a language set (this I would do just an id for, and link it to another table for the languages), and a replacement set. Actually, it depends on how much replacement you want to do, you may want to add a pageset or something for it, like so:
// Pretend this is generated by a query, we just want to see what it would look like.
$lang['id'] = 1; // This is an auto incrementing number, not nessessary, but nice to have.
$lang['language'] = 2; // Lets say 2 is equal to english.
$lang['variable'] = 'replace_my_words_with_phrase';
$lang['replacement'] = 'I\'m being replaced by an English phrase.';
$lang['group'] = 'global';
$langroups = array('global', 'news'... etc.);
global $langroups, $userprefs, $defprefs, $langroups;
// We are assuming that $defprefs and $userprefs are already defined and usable.
if (isset($userprefs['languageset']) AND $userprefs['languageset'] != -1)
$langset = $userprefs['language'];
$langset = $defprefs['language'];
/* We have a language set, so default is english, but a user has stated spanish.
Good to go. If user has stated nothing, or set = -1, revert to default.
$languagebase = mysql_query("
SELECT lang.id, lang.charset, lang.title, words.id AS wordid, words.language, words.variable, words.replacement
FROM languages AS lang
LEFT JOIN words AS words
ON lang.id = words.language
WHERE lang.id='" . $langset . " AND words.group IN ('" . implode("', '", $langroups) . "')
// If you have a lot of words to replace, you may want to use two queries, as I find a join takes longer.
while ($conver = mysql_fetch_array($languagebase))
$langwords["$conver[variable]"] = $conver['replacement'];
$lang = language();
// To use:
// This should display the words, Welcome To My Site, in which ever language is now set.