View Full Version : More than one interface language
Hi Simon!
Is there already a tutorial how to run a directory in more than one language? If not, how will I do so?
I could image to have the structur like this:
www.xxxx.com/de
www.xxxx.com/en
www.xxxx.com/hu
or cookie based language selection...
Greetings,
gb
Simon Gooffin
12-09-2005, 10:24 AM
Hello Gerwin,
I'm not sure about different URLs but I can advise how to make language selector by links or select field ;)
#1. place three links in any place of your design. example:
Deutsch ({$config.base}{$config.dir}?language=Deutsch) |
English ({$config.base}{$config.dir}?language=English) |
Hungarian ({$config.base}{$config.dir}?language=Hungarian )
#2. add the following code to your Dir.php class
if ($_GET['language'])
{
setcookie( "language", $_COOKIE['language'], time() - 3600, '/' );
setcookie( "language", $_GET['language'], 0, '/' );
}
$language = $_GET['language'] ? $_GET['language'] : $_COOKIE['language'];
$gDirConfig['lang'] = $language ? $language : $gDirConfig['lang'];
#3. Save changes
Now when you click on your links directory changes its language. Please try
somehow doesn't work.
I have replaced {$config.base}{$config.dir} with {$category.path} in order that the same page is just reloaded in the other language, but the pages show only in english.
I have uploaded a Deutsch.php Language file already. Hungarian not.
Please try it, does it work with you?
Greetings,
gb
Simon Gooffin
12-09-2005, 11:35 AM
it works in our demo :) please take a look. If you want you can send me your hungarian language file. I would appreciate it much
after a little chat it works also on our page...
the code you've posted for the cookie must be included in the dir.php before the line
require_once("language/{$gDirConfig['lang']}.php");
a fallback system would be nice.
version a.) if language doesn't exist (or not anymore) change to standard language
version b.) if translation in language file doesn't exist, use translation from standard language file
greetings,
gb
Simon Gooffin
12-09-2005, 11:46 AM
it was a quick advise to you :) with no time to think it over.. please check the code above. it's a bit modified. I would advise to use it.
language selector will be available in the next version also :)
Simon Gooffin
12-09-2005, 12:20 PM
you are welcome ;)
Today I have asked a lot from Simon and the guys, so i feel i need give something back...
I want to share my working language selection solution to the public. It supports the change of interface language on any page with staying on the same page.
1.) create a new file in the /smarty/plugins folder called modifier.add_url_param.php
it should have this content:
<?php
/**
* Smarty add_url_param modifier plugin
* ----------------------------------------
*
* This plugin adds parameters to existing URLs and is useful
* when you want to append or update a parameter without
* knowing anything about the contents of the existing
* URL.
*
* If any of the parameters passed to the modifier
* are already contained in the URL, their values
* are updated in the URL, rather than appending another
* parameter to the end.
*
* Examples:
*
* {$smarty.server.REQUEST_URI|add_url_param:'param=t est¶m2=test2'}
* {$smarty.server.REQUEST_URI|add_url_param:$paramAr ray}
* {$smarty.server.REQUEST_URI|add_url_param:'variabl e':$value}
*
*
* @author Mark Mitchenall <mark@standingwave.co.uk>
* @copyright Standingwave Ltd, 2005
*
* @param $url string URL to add the parameters to
* @param $parameter mixed Assoc. Array with param names and
* values or string contain the
* additional parameter(s)
* @param $paramValue string (optional) Parameter value when
* $parameter contains just a
* parameter name.
* @return string
*/
function smarty_modifier_add_url_param($url, $parameter, $paramValue = NULL)
{
if ($paramValue !== NULL) {
// we were passed the parameter and value as
// separate plug-in parameters, so just apply
// them to the URL.
$url = _addURLParameter ($url, $parameter, $paramValue) ;
} elseif (is_array($parameter)) {
// we were passed an assoc. array containing
// parameter names and parameter values, so
// apply them all to the URL.
foreach ($parameter as $paramName => $paramValue) {
$url = _addURLParameter ($url, $paramName, $paramValue) ;
}
} else {
// was passed a string containing at least one parameter
// so parse out those passed and apply them separately
// to the URL.
$numParams = preg_match_all('/([^=?&]+?)=([^&]*)/', $parameter, $matches, PREG_SET_ORDER) ;
foreach ($matches as $match) {
$url = _addURLParameter ($url, $match[1], $match[2]) ;
}
}
return $url ;
}
function _addURLParameter ($url, $paramName, $paramValue) {
// first check whether the parameter is already
// defined in the URL so that we can just update
// the value if that's the case.
if (preg_match('/[?&]('.$paramName.')=[^&]*/', $url)) {
// parameter is already defined in the URL, so
// replace the parameter value, rather than
// append it to the end.
$url = preg_replace('/([?&]'.$paramName.')=[^&]*/', '$1='.$paramValue, $url) ;
} else {
// can simply append to the end of the URL, once
// we know whether this is the only parameter in
// there or not.
$url .= strpos($url, '?') ? '&' : '?';
$url .= $paramName . '=' . $paramValue;
}
return $url ;
}
?>
2.) in /classes/Dir.php
find:
require_once("language/{$gDirConfig['lang']}.php");
replace with:
if ($_GET['language'])
{
setcookie( "language", $_COOKIE['language'], time() - 3600, '/' );
setcookie( "language", $_GET['language'], 0, '/' );
}
$language = $_GET['language'] ? $_GET['language'] : $_COOKIE['language'];
$gDirConfig['lang'] = $language ? $language : $gDirConfig['lang'];
require_once("language/{$gDirConfig['lang']}.php");
3.) in your template (for example header) include the language selection:
Deutsch ({$smarty.server.REQUEST_URI|add_url_param:'langua ge':Deutsch}) |
English ({$smarty.server.REQUEST_URI|add_url_param:'langua ge':English}) |
Hungarian ({$smarty.server.REQUEST_URI|add_url_param:'langua ge':Hungarian})
4.) add the language files to the language directory
Greetings,
gb
Simon Gooffin
12-10-2005, 03:27 AM
Respect... :shock:
echopulse
12-10-2005, 05:08 AM
That's pretty cool. But it looks like it doesn't work on the categories. Is this correct, or have you just not completed the language file yet?
echopulse,
that's correct. the language files only contain the text for the interface, not content like links or category names. To have also those in different languages it needs a much bigger mod.
I'm currently working on that, but I'm not sure if it wont be implemented anyway in the next version by Simon. He said something about...
Greetings,
gb
Simon Gooffin
12-10-2005, 09:00 AM
well, I can say.. this will not be implemented in future versions. to translate categories or links you should have version for every language - just imagin what work it is
we just offer translation for the interface(front-end)
echopulse
12-12-2005, 02:02 AM
That sure would be a lot of work. In fact, it would probably be impossible. You would have to have a dictionary. I wonder if there are some dictionaries already compiled that would have the information? It's possible. I know there are dictionaries that people use when making php spellcheckers. I wouldn't know where to look though.
Simon Gooffin
12-12-2005, 05:24 AM
hmm, there are some online services that offer pages online translation :) may be we should check if it is possible to use them for the script, but I'm pretty sure (as a person with linguistics degree) they will not translate content well.
pwaget
01-20-2006, 12:54 PM
Is it possible, with a single licence, to use on a same website different databases, one for each language :
Database1 --> French websites and french translation of common links
Database2 --> English websites and english translation of common links
Database3 --> German websites and german translation of common links
and when you click on language selection link on each page, to jump to the appropriate language database containing text translation of each link ??
Simon Gooffin
01-21-2006, 06:16 AM
welcome to our support forums
we have one domain license + you can modify the script as you wish. I do not see any problems with having three databases for a single domain name..
vBulletin® v3.7.0, Copyright ©2000-2008, Jelsoft Enterprises Ltd.