[trick] Membuat Aplikasi Multi Bahasa dengan php mysql Bag-1

Ok Langsung Saja >>

siapkan databases Y >>

Table Menu :

menu

Table Identitas :

identitas

Entri Kodingnya :

1. index.php


<?php
include_once 'common.php';
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title><?php echo $lang['PAGE_TITLE']; ?></title>
<link href="css/style.css" rel="stylesheet" type="text/css" media="all">

</head><body>

<div id="OuterFrmDl"><!-- OuterFrmDl BEGIN -->

<div id="HeadSectionDl">

<!-- HeadSectionDl BEGIN -->
<div id="languages">
<a href="index.php?lang=en"><img src="images/en.png" /></a>
<a href="index.php?lang=de"><img src="images/de.png" /></a>
<a href="index.php?lang=es"><img src="images/es.png" /></a>
</div>

<div id="WSTitleDL"><?php echo $lang['HEADER_TITLE']; ?></div>
<div id="WSubTitleDL"><?php echo $lang['SLOGAN']; ?></div>
</div>
<!-- HeadSectionDl END -->

<div id="TopHzNavSectionDl">
<!-- HeadSectionDl BEGIN -->
<div>
<ul>
<li><a href="#"><?php echo $lang['MENU_HOME']; ?></a></li>
<li><a href="#"><?php echo $lang['MENU_ABOUT_US']; ?></a></li>
<li><a href="#"><?php echo $lang['MENU_OUR_PRODUCTS']; ?></a></li>
<li><a href="#"><?php echo $lang['MENU_CONTACT_US']; ?></a></li>
<li><a href="#"><?php echo $lang['MENU_ADVERTISE']; ?></a></li>
<li><a href="#"><?php echo $lang['MENU_SITE_MAP']; ?></a></li>
</ul>
</div>
</div>
<!-- HeadSectionDl END -->
<div id="CntSectionDlDiv"><!-- CntSectionDlDiv BEGIN -->

<table id="CntSectionDlTbl" cellpadding="0" cellspacing="0"><!-- CntSectionDlTbl -->
<tbody><tr>
<td valign="top">
<div>
<ul>
<li><a href="#" title="Link 1 Title">Sample Side Link 1</a></li>
<li><a href="#" title="Link 2 Title">Sample Side Link 2</a></li>
<li><a href="#" title="Link 3 Title">Sample Side Link 3</a></li>
<li><a href="#" title="Link 4 Title">Sample Side Link 4</a></li>
<li><a href="#" title="Link 5 Title">Sample Side Link 5</a></li>
</ul>
</div>
<div>
<h3><?php echo $lang['HEADING']; ?> 3 </h3>
<p>
Lorem ipsum dolor sit amet eget nunc. Donec ultricies fermentum justo.
Sed ultrices. Praesent scelerisque rutrum nibh. Quisque quam. Aenean
posuere bibendum lectus. Donec <a href="#" title="The Link Title">congue</a>
nisi non nulla. In hac habitasse platea dictumst. Vivamus pretium. Ut
consequat fringilla tellus. Vivamus semper sodales libero. Ut in ligula
in massa elementum condimentum. Proin pulvinar neque et pede. Donec at
quam ut lectus molestie lacinia. Sed sapien. Mauris venenatis leo quis
mauris. </p>
</div></td>
<td valign="top">

<div>
<h1><?php echo $lang['HEADING']; ?> 1 </h1>
<p> Lorem ipsum dolor sit amet, <a href="#" title="The Link Title">consectetuer</a>
adipiscing elit. Pellentesque at libero. In turpis ante, pretium id,
consectetuer nec, porta a, nibh. Quisque malesuada massa elementum
tortor. Sed nulla dui, faucibus ac, euismod ac, elementum non, lorem.
Sed nec nibh. Vivamus malesuada neque vel velit. Vivamus tempus dolor
non mi mollis dapibus. Pellentesque habitant morbi tristique senectus
et netus et malesuada fames ac turpis egestas. Praesent neque ante,
rutrum eget, sodales vitae, facilisis gravida, ligula. Curabitur sed
felis. </p>
<p>&nbsp;</p>
<h2><?php echo $lang['HEADING']; ?> 2 </h2>
<p>Nulla suscipit magna suscipit eros. Ut aliquam viverra   quam. Etiam vel ipsum et massa tincidunt tempus. <a href="#" title="The Link Title">Nullam</a>
feugiat velit id neque. Nunc nec felis. Sed vitae nibh vitae nisi
ultricies pretium. Vestibulum tincidunt. Aenean dapibus mollis libero.
Duis lacus urna, varius vel, molestie varius, imperdiet at, orci.
Maecenas eu nisl. Vestibulum ante ipsum primis in faucibus orci luctus
et ultrices posuere cubilia Curae; Nam laoreet justo. Cras et ante nec
tellus vestibulum fringilla. Pellentesque sem. In fermentum, elit vel
condimentum dignissim, magna nulla aliquam nisi, eu hendrerit eros
turpis rhoncus sapien. Mauris laoreet lacinia elit. Quisque tristique
turpis a nibh. Phasellus consequat nunc et felis. Suspendisse ut lorem
et velit volutpat consectetuer. </p>
<p>&nbsp;</p>
<p>Duis molestie sem eget nunc. Donec ultricies
fermentum justo. Sed ultrices. Praesent scelerisque rutrum nibh.
Quisque quam. Aenean posuere bibendum lectus. Donec congue nisi non
nulla. In hac habitasse platea dictumst. Vivamus pretium. Ut consequat
fringilla tellus. Vivamus semper sodales libero. Ut in ligula in massa
elementum condimentum. Proin pulvinar neque et pede. Donec at quam ut
lectus molestie lacinia. Sed sapien. Mauris venenatis leo quis mauris. </p>
</div>
</td>

<td valign="top"><div>
<ul>
<li><a href="#" title="Link 1 Title">Sample Side Link 1</a></li>
<li><a href="#" title="Link 2 Title">Sample Side Link 2</a></li>
<li><a href="#" title="Link 3 Title">Sample Side Link 3</a></li>
<li><a href="#" title="Link 4 Title">Sample Side Link 4</a></li>
<li><a href="#" title="Link 5 Title">Sample Side Link 5</a></li>
</ul>
</div>
<div>
<h3><?php echo $lang['HEADING']; ?> 3 </h3>
<p>
Lorem ipsum dolor sit amet eget nunc. Donec ultricies fermentum justo.
Sed ultrices. Praesent scelerisque rutrum nibh. Quisque quam. Aenean
posuere bibendum lectus. Donec <a href="#" title="The Link Title">congue</a>
nisi non nulla. In hac habitasse platea dictumst. Vivamus pretium. Ut
consequat fringilla tellus. Vivamus semper sodales libero. Ut in ligula
in massa elementum condimentum. Proin pulvinar neque et pede. Donec at
quam ut lectus molestie lacinia. Sed sapien. Mauris venenatis leo quis
mauris. </p>
</div></td>
</tr>
</tbody></table><!-- CntSectionDlTbl -->

</div><!-- CntSectionDlDiv END -->

</div><!-- OuterFrmDl END -->
<div id="FooterBxDL">
<p>Copyright © YourCompany </p>
</div>
</body></html>

2. common.php


<?php

session_start();

header('Cache-control: private'); // IE 6 FIX

if(isSet($_GET['lang']))
 {
 $lang = $_GET['lang'];

$_SESSION['lang'] = $lang;

setcookie("lang", $lang, time() + (3600 * 24 * 30));
 }
 else if(isSet($_SESSION['lang']))
 {
 $lang = $_SESSION['lang'];
 }
 else if(isSet($_COOKIE['lang']))
 {
 $lang = $_COOKIE['lang'];
 }
 else
 {
 $lang = 'en';
 }

switch ($lang) {
 case 'en':
 $lang_file = 'lang.en.php';
 break;

case 'de':
 $lang_file = 'lang.de.php';
 break;

case 'es':
 $lang_file = 'lang.es.php';
 break;

default:
 $lang_file = 'lang.en.php';

}

include_once 'languages/'.$lang_file;

?>

3. bahasa/lang.php


<?php

mysql_connect("localhost","root","");
mysql_select_db("multibahasa");

/*
------------------
Language: English
------------------
*/

$lang = array();

$data=mysql_fetch_array(mysql_query("select * from menu left join identitas on menu.ID=identitas.ID where menu.ID='2'"));

$lang['PAGE_TITLE'] = "$data[PAGE_TITLE]";
$lang['HEADER_TITLE'] = "$data[HEADER_TITLE]";
$lang['SITE_NAME'] = "$data[SITE_NAME]";
$lang['SLOGAN'] = "$data[SLOGAN]";
$lang['HEADING'] = "$data[HEADING]";

// Menu

$lang['MENU_HOME'] = "$data[MENU_HOME]";
$lang['MENU_ABOUT_US'] = "$data[MENU_ABOUT_US]";
$lang['MENU_OUR_PRODUCTS'] = "$data[MENU_OUR_PRODUCTS]";
$lang['MENU_CONTACT_US'] = "$data[MENU_CONTACT_US]";
$lang['MENU_ADVERTISE'] = "$data[MENU_ADVERTISE]";
$lang['MENU_SITE_MAP'] = "$data[MENU_SITE_MAP]";

?>

dan hasil sebagai berikut :

tampilan

selesai

ctt : ini hanya pada menu dan identitas web, kalau untuk kontent tunggu bagian kedua y..

silahkan dicoba saja rubah bahasanya setelah didownload y.

untuk menambah bahasa silah buat database dan tambah code bahasanya y, gampang kok..

download sourcecode : http://www.4shared.com/zip/ETWBUPaR/multibahasa.html

Leave a comment

2 Comments

  1. htc

     /  16/03/2013

    uda, berarti ini mah bahasanya udah di simpen di Database! lah kalo kondisinya gak perlu di database? kayak translate.google.com getuh,… but, keren – keren uda, wah… udah dewa banget lu uda, cepet berkembangnya…

    Reply
    • ada referensinya kok kalau buat kyk google translate bisa dilihat disitusnya rosihanari.net (membuat aplikasi google translate) . makasih atas postan nya..

      Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: