PHP - Adding More Languages For Php Localization For Cms
Hello there,
I have a CMS which I've trying to create localization for. The idea is in the admin area you check a radio button and it changes the language of the entire admin interface. There is a mysql database with a table called nb_settings that has a column called lang. Up to this point I've gotten it to work but am having problems adding additional languages. The localization files have names like lang.nl.php,lang.en.php and so on.. The original code that works is this in a file called settings.php: ... <?php if($row['lang'] == nl) { echo '<input name="lang" type="radio" value="nl" checked="checked" /> '.($_CONSTANTS['NL']).' <input name="lang" type="radio" value="en" /> '.($_CONSTANTS['EN']).' <input name="lang" type="radio" value="de" /> '.($_CONSTANTS['DE']).''; } elseif($row['lang'] == en) { echo '<input name="lang" type="radio" value="nl" /> '.($_CONSTANTS['NL']).' <input name="lang" type="radio" value="en" checked="checked" /> '.($_CONSTANTS['EN']).' <input name="lang" type="radio" value="de" /> '.($_CONSTANTS['DE']).''; } elseif($row['lang'] == de) { echo '<input name="lang" type="radio" value="nl" /> '.($_CONSTANTS['NL']).' <input name="lang" type="radio" value="en" /> '.($_CONSTANTS['EN']).' <input name="lang" type="radio" value="de" checked="checked" /> '.($_CONSTANTS['DE']).''; } ?> ... Another file called common.php is used as well and has the following: <?php session_start(); header('Cache-control: private'); // IE 6 FIX $sql = "SELECT * FROM nb_settings"; $query = mysql_query($sql); $row = mysql_fetch_assoc($query); if($row['lang'] == nl) { include('languages/lang.nl.php'); } elseif($row['lang'] == en) { include('languages/lang.en.php'); } elseif($row['lang'] == de) { include('languages/lang.de.php'); } ?> But I am havng trouble adding more languages and expanding this. There is a folder called languages into which I put the individual localization files. Just adding similar lines of code as shown below in both common and settings files doesn't do it: ie: 1)modifying settings.php to become: <?php if($row['lang'] == nl) { echo '<input name="lang" type="radio" value="nl" checked="checked" /> '.($_CONSTANTS['NL']).' <input name="lang" type="radio" value="en" /> '.($_CONSTANTS['EN']).' <input name="lang" type="radio" value="de" /> '.($_CONSTANTS['DE']).' <input name="lang" type="radio" value="fra" /> '.($_CONSTANTS['FRA']).''; } elseif($row['lang'] == en) { echo '<input name="lang" type="radio" value="nl" /> '.($_CONSTANTS['NL']).' <input name="lang" type="radio" value="en" checked="checked" /> '.($_CONSTANTS['EN']).' <input name="lang" type="radio" value="de" /> '.($_CONSTANTS['DE']).' <input name="lang" type="radio" value="fra" /> '.($_CONSTANTS['FRA']).''; } elseif($row['lang'] == de) { echo '<input name="lang" type="radio" value="nl" /> '.($_CONSTANTS['NL']).' <input name="lang" type="radio" value="en" /> '.($_CONSTANTS['EN']).' <input name="lang" type="radio" value="de" checked="checked" /> '.($_CONSTANTS['DE']).' <input name="lang" type="radio" value="fra" /> '.($_CONSTANTS['FRA']).''; } elseif($row['lang'] == fra) { echo '<input name="lang" type="radio" value="nl" /> '.($_CONSTANTS['NL']).' <input name="lang" type="radio" value="en" /> '.($_CONSTANTS['EN']).' <input name="lang" type="radio" value="de" /> '.($_CONSTANTS['DE']).' <input name="lang" type="radio" value="fra" checked="checked" /> '.($_CONSTANTS['FRA']).''; } ?> 2)and adding in common.php: elseif($row['lang'] == fra) { include('languages/lang.fra.php'); } Both don't work. The php is obviously not correctly parse and the syntax may have issues. Can anyone help me out with how to add additional languages? Similar TutorialsHi guys, i was wondering.. Languages? How does that excactly work? Where do you save the different language strings, and that stuff? Do you have php files' for each language, and just includes them? Or,.. Anyone who can explain me? thanks =) The first thing I learned after HTML and CSS is PHP. Its my primary language now, but I also use SQL and javascript and XML regularly, and since I use linux, I use bash scripting. The cool thing is they all work hand in hand. I recently learned how to use SQLite too, which is good because it can be accessed directly by javascript. Are there any other languages which would enable me to make new things and combine them with PHP scripts? I was looking into java but the security restrictions on applets make it pointless. Flash actionscript looks good. What about perl? Or ruby? Would they enable me to do things I can't easily do with PHP? I've heard about node.js recently a lot so I'm looking into that. Bash scripting is great, but the only issue is I could only use it on a server owned by myself, commercial servers won't let you execute commands like that. I'm interested in perl, python and java but I'll only learn them if they enable me to do things I can't do (easily) with PHP.
Hi how can I have the same website in a different language? So for the visitor, they would click on the appropriate flag and the site would then be displayed in their language. Hi guys. This is my first post here - so HELLO. I am a very experienced software developer, but new to web work. I am building a software tool using PHP (primarily). As such, many of my questions will concern optimum solutions (in so far as they may be determined), best practices, and the unwritten standards that will surely have evolved through the PHP community over time. My first question concerns the mixing of HTML and PHP. My efforts so far contain a mix, but it doesn't "feel" right. I am using straight XHTML, PHP echo, and also heredoc. I can post the code if folk think it may help. But what is the general view as to whether "mixing" like this is a good and accepted practice, or is another approach preferred? Many thanks in advance for any replies. S I'm developing an arabic site...but also want to view it in English...I'm thinking of using windows translating service (depending on good it is). Now I was thinking of having columns in my table like so...english title, arabic title, english description, arabic description As it can charge for words to be translated...when translating arabic to english I can store the results in the column so they would no longer have to be translated again My question is...is it good practice to have separate columns for different languages?...thank you...any input would be great I have a time and date using the code echo date("l jS \of F Y H:i:s."); Now I need to show this in several different languages, including French German and Dutch I have tried setlocale(); and echo strftime The date shows but still in English. Any idea how to show the day date and time in Php for the languages suggested. I am looking to add Spanish to a website and would like the users to be able to click a button to switch between english and Spanish. Is this something that php would be good for or should I look into another language? Would there be a benefit to doing this on the client side versus the server, hence the use of javascript versus php? I would appreciate any help in this area; samples, websites, and such. I am looking to learn, and not for someone to do all the work for me. Thank you in advance for your help. Hi everyone this is my first post so I'm sorry if I've posted it in the wrong section! Before I begin I'd like to point out that I'm not just here to get someone to produce what I want for me! I have a genuine interest in this forum and I'm slightly surprised and disappointed in myself that I hadn't took the time to join sooner! Anyway to the point of this post: (Please bare with me I think I'll need to justify the use of SQLite) I am currently undergoing a University gorup project that uses wireless sensors to collect environmental data such as, Temperature, Humidity, Light levels and Dew point. This application is programmed in Python and it collects these pieces of data (every 30 seconds) and places them into an SQLite database. My job is to now graphically plot/show the data that the Python program collects and stores in the SQLite database on a web page. I'm using Ubuntu and have successfully installed LAMP, SQLite3 and the SQLite PD0 driver. I have also successfully established a connection to the SQLite database as well as displaying the data on a web page (locally - thats all I need!) in the form of a simple HTML table through the use of the following PHP script: Code: [Select] <?php try { //open the database $db = new PDO('sqlite:/var/databases/307Code/python/readings.db'); //now output the data to a simple html table... print "<table border=1>"; print "<tr><td>Date & Time Recieved</td><td>Node</td><td>Temp</td><td>Hum</td><td>Light</td><td>Dew</td></tr>"; $result = $db->query('SELECT * FROM readingstable'); foreach($result as $row) { print "<tr><td>".$row['Recieved']."</td>"; print "<td>".$row['Node']."</td>"; print "<td>".$row['Temp']."</td>"; print "<td>".$row['Hum']."</td>"; print "<td>".$row['Light']."</td>"; print "<td>".$row['Dew']."</td></tr>"; } print "</table>"; // close the database connection $db = NULL; } catch(PDOException $e) { print 'Exception : '.$e->getMessage(); } ?> What I'm now looking to do is the following: 1. Display the data from the SQLite database in the form of line graphs (I've seen that I may need to convert the data to XML?) 2. Make the application asynchronous, preferably every time a new entry is added to the SQLite database the line graph(s) update without a user needing to refresh the browser. 3. The SQLite database is storing a ridiculous floating point number for the time field in the database, for example: "2012-03-23 16:49:42.440818" is a entry in the SQLite database. Is there any way to omit the .440818 through the use of PHP? Or will I need to edit the Python script? Also one thing to note: The person in my group who built the Python script didn't build it to make the SQLite database give each database entry a unique ID/Primary key. Any tips/advice/help would be massively appreciated! Regards, Rich hi i been working on this code witch will add what ever text i want to my database all is working great but what i am having problems with is inserting a url in the same field as vidID it will look like this in the database hxxp://xxx.mysitehere.com/index.php?vid=vidID hope you guys know what im talking about im having a hard time explaining it sorry. Code: [Select] <?php $host="xxxxx"; $username="xxxxxxx"; $password="xxxxxxx"; $db_name="xxxxxxx"; $tbl_name="xxxxxxx"; $message = strtoupper(trim($_REQUEST['message'])); $sender = strtoupper(trim($_REQUEST['sender'])); $email = strtolower(trim($_REQUEST['email'])); $vidID =$_REQUEST['vidID']; mysql_connect("$host", "$username", "$password")or die("cannot connect server "); mysql_select_db("$db_name")or die("cannot select DB"); $sql="INSERT INTO $tbl_name(message,sender,email,vidID)VALUES('$message','$sender', '$email', '$vidID')"; $result=mysql_query($sql); ?> This might be more of a mySQL question or a PHP question, I'm not exactly sure. I have a field in my table (Deals) called "Price". All I want is the sum of that field. I tried using something like: $price += $row['Price']; This ended up as one long string, even though the database is set as a decimal number field. Then I tried doing it from mySQL like this (from what I read), but I don't think I have the full answer: foreach($stmt->query('SELECT SUM(Price) FROM Deals') as $row) { echo "<tr>"; echo "<td>Total</td>"; echo "<td> ->".$row['SUM(Price)']."</td>"; echo "</tr>"; } Anyway, if someone could just show me how to get that sum, I would greatly appreciate it because I am missing something here. Hi can someone please show me how I should include a Code: [Select] <div id="css"></div> in this line Code: [Select] echo $AB_LANGS['CalendarInstructions']; I have tried several attempts with no joy. Many thanks I have seen somewhere that you can add to a string like so $var = "text"; or $string ="var"; &$var = "text"; it is the latter that I am wanting to know more about. This is my current script <?php $iFile = "accounts.txt"; //Put your list lagger's info in this txt file in the same directory as this script. Format is UserID(space)AuthKey $login = file($iFile, FILE_SKIP_EMPTY_LINES); if(!is_file($iFile)) echo "The logins file couldn't be found...".sleep(999999); foreach($login as $line_num => $line) { $login = explode(" ", htmlspecialchars(str_replace(" "," ",$line))); //////////////// ////////////// /////////// ///////// if(stristr($login[1], "\n")) $login[1] = substr($login[1], 0, strlen($login[1])-2); $MobLink = "http://mobsters-fb-apache-dynamic-lb.playdom.com/mob_fb/"; $RefreshStat = file_get_contents($MobLink."refresh_stat?user_id=".$login[1]."&auth_key=".$login[0]); $Mob_Name = explode("<mob_name>", $RefreshStat); $Mob_Name = explode("<", $Mob_Name[1]); $Name = $Mob_Name[0]; $Cash = explode("<cash>", $RefreshStat); $Cash = explode("<", $Cash[1]); $CurrentCash = $Cash[0]; echo $Name."-$".number_format($CurrentCash)." - ".$login[1]."\n"; } sleep(99999); ?> The Script runs through for 100 different accounts, is it possible to add all the Cash values that get echo'd? Hi again guys, Right, I have two times being output from a database... The first time is the time something is booked in for (eg: 16:30:00) and the second time is the duration that thing is booked in for (eg an hour and a half - 01:30:00) Now, I want to figure out when that thing will be finished, so using the two examples above, it will be finished at 18:00:00, I've tried a few things with no success Please help Cheers hello, i have created a table that desplays perticulars, price per person and number of people. the fees is then calculated by multiplying price per person with number of people. till now everything is good. but the problem is when i try to calculate the total fees. here is an example to explain you better: Perticulars Price Per Person Number of people Amount something 10 100 1000 something else 20 100 2000 Total 3000 Code: [Select] $pert_query = mysql_query ("SELECT * FROM `perticulars` WHERE `invoice` =$invoice") or die(mysql_error()); $i = 1; $sum = 0 + $_SESSION['sum']; while($perticulars = mysql_fetch_array($pert_query, MYSQL_ASSOC)) { ?> <tr> <td style="border-collapse: collapse"><div align="center"><?php echo $i; $i++; ?></div></td> <td style="border-collapse: collapse"><div align="center"><?php echo $perticulars['perticulars']; ?></div></td> <td style="border-collapse: collapse"><div align="center"><?php echo $perticulars['ppc']; ?></div></td> <td style="border-collapse: collapse"><div align="center"><?php echo $perticulars['nop']; ?></div></td> <td style="border-collapse: collapse"><div align="center"> <?php $amount = $perticulars['ppc'] * $perticulars['nop']; echo $amount; $_SESSION['sum'] = $sum+$amount;?> </div></td> </tr><?php } ?> <tr> <td colspan="4" style="border-collapse: collapse"><div align="center">Total</div></td> <td style="border-collapse: collapse"><div align="center"><?php echo $sum; ?></div></td> </tr> </table> From the above code you can see that i am getting the amount form $amount = $perticulars['ppc'] * $perticulars['nop']; by this each row has its own amount which i got by multiplying the data from mysql. the problem is how do i find out the Total. i know i am suppose to add up $amount but how? i even tired using sessions to store the amount and add the new amount to get total but the problem in using sessions is it messes up my next page, no using session is a very bad idea. nevermind. i need help with adding an integer into an array something like this $Loaded[count($Loaded)+1] = $To; Is it possible to add onto the value of a $_SESSION, rather replacing it? $_SESSION['order']['cartcontenttext'] += echo 'Small: "'.$content['sizes'].'"'; $_SESSION['order']['cartcontenttext'] += echo 'Medium: "'.$content['sizem'].'"'; $_SESSION['order']['cartcontenttext'] += echo 'Large: "'.$content['sizel'].'"'; ... so the result would be something like this: echo $_SESSION['order']['cartcontenttext']; Quote Small: 1Medium: 3Large: 2 what is the propper way to write Code: [Select] $payrollweek="10"; date('Y-m-d', strtotime("+($payrollweek - 2) week $payrollend") ), "<br />"; its the ("+($payrollweek - 2) that isnt working i think |