I am new to web development and I want my site to have a drop-down menu that will change the language of my site.I want a solu开发者_开发问答tion that will not require me to create a whole new html of the new site. I also want a way to make an input field that will ask users to add a number and then it will automatically add a word after the number.
Perhaps this maybe of some use to you - http://code.google.com/p/jquery-translate/.
Not sure what the second part of the sentence is but a somewhat easy way of doing this is server-side scripting. For example, if you are using PHP, I would recommend you echo the a variable instead of actually typing the contents in the place it belongs. Instead, store the content in a database and then load the content from a database depending on what language is selected (store this a session variable), store it in the variable and when the variable is echoed, bam.
Create in PHP by using $_GET[l];
<?php
if($_GET[l]=='en')
{
echo 'Welcome';
}
else if($_GET[l]=='sk')
{
echo 'Vítajte';
}
else if($_GET[l]=='de')
{
echo 'Wilkommen';
}
else
{
echo ''; //Here set your default language. For example if is not set- automatically to english
}
?>
Menu:
<?php
if(isset($_GET[topic]))
{
//This is code, if you use another $_GET[...]
//Without this, page will crash ,while it shows another thing
echo '<a href="'.$_SERVER[REQUEST_URI].'&l=en">English</a>';
echo '<a href="'.$_SERVER[REQUEST_URI].'&l=sk">Slovensky</a>';
echo '<a href="'.$_SERVER[REQUEST_URI].'&l=de">Deutsch</a>';
//?l=lang changes to &l=lang
}
else
{
//Link with normal ?l=lang, cause page does not use another $_GET[...]
echo '<a href="?l=en">English</a>';
echo '<a href="?l=sk">Slovensky</a>';
echo '<a href="?l=de">Deutsch</a>';
}
?>
精彩评论