PHP - How To Organize Language Translations
I am developing a multilingual site. I use array to save translations in one file which I include it inside settings.php.
Code: [Select] //Example of english $LANG['welcome']="Welcome"; $LANG['status']="Status"; I am wondering about two things: 1. How would be the best option to print those arrays? a) Echo all html and inside html I use Code: [Select] echo " <body> <div> <p>{$LANG['welcome']}</p> </div> ";b) Close php and write html and inside html I open and close php for each time Code: [Select] <div><p><?php echo $LANG['welcome']; ?></p></div> Each one has own downsides. Option a) spends extra resources to print html. Option b) spends extra resources to close and open php each time (could means that single script needs to open and close php even 30 times per script). Is that bad or is the ammount of resources spend for this negligible? 2. Also how do you translate words inside javascript? I was thinking to put all translation that are need for javascript into $LANG['js'] array. Then I would use at the head of the script foreach $LANG['js'] to print html to assign javascript language variables. Code: [Select] <script type="javascript"> <?php foreach($LANG['js'] as $keyword => $translation){ echo "var ".$keyword."= ".$translation.";\n"; } ?> </script>Is there any better way? Thank you! Similar TutorialsI have a connection.php for connecting to my database and I have done it this way connection.php Code: [Select] function connect() { global $mysql; $mysql = new MySQLi('localhost','cybershot','pascal35','billPay') or die('couldn not connect'. mysql_error()); } I have another file where I want to perform a query so I included the connection.php at the top of that file which I will call results.php and in the body of my results.php I have this Code: [Select] $names = $mysql->query("select * from names") or die($mysql->error); if($names){ while($row = $names->fetch_assoc()){ $name = $row['firstName']; $lastName = $row['lastName']; $company = $row['companyName']; echo $name . " "; echo $lastName . " "; echo $company . " "; } } I had to make $mysql a global variable in the connection.php in order to get it to work in another page. is there a better way to pass that variable to the results.php page? or is there a better way period? Hello everyone For a multilingual website we have to be able to open 1 page in 4 different languages. For example, product 'A' is in Dutch, English, French and German. How can I open the right language file? At the moment I use Code: [Select] http://www.zinncosmetics.nl/shop/product_info.php?products_id=36?language=de but it doesn't work. It allways opens the default Dutch pages. What do I do wrong? I don't have very much php experience (newbie) so please don't make it too difficult for me. Thanks for all help! I am looking at making a photogallery system for an online community based site. I know that we need to have unique id's , photo names and albums. What i am looking for is: Would it be recommended to create a directory for each user once they are registerd? How would you go about naming and sorting photogralleries? How would you go about naming you photos? How would you do it? I was thinking about a uuid kind of code: ( from php.net) Code: [Select] class UUID { public static function v3($namespace, $name) { if(!self::is_valid($namespace)) return false; // Get hexadecimal components of namespace $nhex = str_replace(array('-','{','}'), '', $namespace); // Binary Value $nstr = ''; // Convert Namespace UUID to bits for($i = 0; $i < strlen($nhex); $i+=2) { $nstr .= chr(hexdec($nhex[$i].$nhex[$i+1])); } // Calculate hash value $hash = md5($nstr . $name); return sprintf('%08s-%04s-%04x-%04x-%12s', // 32 bits for "time_low" substr($hash, 0, 8), // 16 bits for "time_mid" substr($hash, 8, 4), // 16 bits for "time_hi_and_version", // four most significant bits holds version number 3 (hexdec(substr($hash, 12, 4)) & 0x0fff) | 0x3000, // 16 bits, 8 bits for "clk_seq_hi_res", // 8 bits for "clk_seq_low", // two most significant bits holds zero and one for variant DCE1.1 (hexdec(substr($hash, 16, 4)) & 0x3fff) | 0x8000, // 48 bits for "node" substr($hash, 20, 12) ); } public static function v4() { return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x', // 32 bits for "time_low" mt_rand(0, 0xffff), mt_rand(0, 0xffff), // 16 bits for "time_mid" mt_rand(0, 0xffff), // 16 bits for "time_hi_and_version", // four most significant bits holds version number 4 mt_rand(0, 0x0fff) | 0x4000, // 16 bits, 8 bits for "clk_seq_hi_res", // 8 bits for "clk_seq_low", // two most significant bits holds zero and one for variant DCE1.1 mt_rand(0, 0x3fff) | 0x8000, // 48 bits for "node" mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff) ); } public static function v5($namespace, $name) { if(!self::is_valid($namespace)) return false; // Get hexadecimal components of namespace $nhex = str_replace(array('-','{','}'), '', $namespace); // Binary Value $nstr = ''; // Convert Namespace UUID to bits for($i = 0; $i < strlen($nhex); $i+=2) { $nstr .= chr(hexdec($nhex[$i].$nhex[$i+1])); } // Calculate hash value $hash = sha1($nstr . $name); return sprintf('%08s-%04s-%04x-%04x-%12s', // 32 bits for "time_low" substr($hash, 0, 8), // 16 bits for "time_mid" substr($hash, 8, 4), // 16 bits for "time_hi_and_version", // four most significant bits holds version number 5 (hexdec(substr($hash, 12, 4)) & 0x0fff) | 0x5000, // 16 bits, 8 bits for "clk_seq_hi_res", // 8 bits for "clk_seq_low", // two most significant bits holds zero and one for variant DCE1.1 (hexdec(substr($hash, 16, 4)) & 0x3fff) | 0x8000, // 48 bits for "node" substr($hash, 20, 12) ); } public static function is_valid($uuid) { return preg_match('/^\{?[0-9a-f]{8}\-?[0-9a-f]{4}\-?[0-9a-f]{4}\-?'. '[0-9a-f]{4}\-?[0-9a-f]{12}\}?$/i', $uuid) === 1; } } // Usage // Named-based UUID. $v3uuid = UUID::v3('1546058f-5a25-4334-85ae-e68f2a44bbaf', 'SomeRandomString'); $v5uuid = UUID::v5('1546058f-5a25-4334-85ae-e68f2a44bbaf', 'SomeRandomString'); // Pseudo-random UUID $v4uuid = UUID::v4(); hello dear php-developer and fans
see the page http:www.literaturen.org
on wp version 4.0 i run several amazon-plugins that fetch data from amazon.
note; the side runs the responsive-pro-theme.
question -
is it possible to organize the first or the first and (!) the second posting as a two collum posting
in other words; i want to show some bookreviews - on the page - t
i want to add two books side by side in the first posting and i want to add two books side by side in the second posting is this doable: see - as a example the site: http://www.wittwer.de/ http://bookshop.pear...gabandon=AW; note : see the two collumn with the book-presentation - at the top site. love to hear from you greetings I'm trying to organize MySQL output in an HTML table based on individual states. Here is how the static HTML is currently displayed: http://www.u-s-s-a.org/breeders.html. Here is my working document: http://www.u-s-s-a.org/breeders.php. As you can see on the HTML page, each db row is organized into individual states. I'm only concerned about the US states, and not the countries outside of the US. Following is the code I've been working on (directoryoutput.php): Code: [Select] <?php require '/home/srob/public_html/u-s-s-a.org/config.php'; $connect = mysql_connect ($dbhost, $dbuser, $dbpass) or die ('Cannot connect: '.mysql_error()); mysql_select_db ($dbname); $query = "SELECT * FROM directory ORDER BY flockname"; $result = mysql_query($query) or die ('Error, query failed.'); echo "<tr><td width='33%' class='style9'><p align='left' class='style12'><a name='AR'></a>Arkansas</p></td><td width='34%'> </td><td width='33%' valign='top'><div align='right'><a href='#TOP'><img src='returnTOTOPGRAPHIC/RETURNTOTOP.gif' width='113' height='21' border='0' align='absmiddle'></a></div></td></tr>"; $cnt = 0; while($row = mysql_fetch_array($result, MYSQL_ASSOC)){ if ($cnt == 0){ echo "<tr><td valign='top' class='style9'><p align='center'><span class='style10'><strong>"; if($row['flockname']){ echo $row['flockname']; } echo "</strong></span><strong></br>"; if($row['firstname']){ echo $row['firstname']." ".$row['lastname']."</br>"; } if($row['address1']){ echo $row['address1']."</br>"; } if($row['address2']){ echo $row['address2']."</br>"; } if($row['city']){ echo $row['city'].", ".$row['state']." ".$row['zip']."</br>"; } if($row['email1']){ echo "<a href='mailto:".$row['email1']."'>".$row['email1']."</a></br>"; } if($row['email2']){ echo "<a href='mailto:".$row['email2']."'>".$row['email2']."</a></br>"; } if($row['website1']){ echo "<a target='_blank' href='http://".$row['website1']."'>".$row['website1']."</a></br>"; } if($row['website2']){ echo "<a target='_blank' href='http://".$row['website2']."'>".$row['website2']."</a></br>"; } echo "</br></p></td>"; $cnt++; } elseif ($cnt == 1){ echo "<td valign='top' class='style9'><p align='center'><span class='style10'><strong>"; if($row['flockname']){ echo $row['flockname']; } echo "</strong></span><strong></br>"; if($row['firstname']){ echo $row['firstname']." ".$row['lastname']."</br>"; } if($row['address1']){ echo $row['address1']."</br>"; } if($row['address2']){ echo $row['address2']."</br>"; } if($row['city']){ echo $row['city'].", ".$row['state']." ".$row['zip']."</br>"; } if($row['email1']){ echo "<a href='mailto:".$row['email1']."'>".$row['email1']."</a></br>"; } if($row['email2']){ echo "<a href='mailto:".$row['email2']."'>".$row['email2']."</a></br>"; } if($row['website1']){ echo "<a target='_blank' href='http://".$row['website1']."'>".$row['website1']."</a></br>"; } if($row['website2']){ echo "<a target='_blank' href='http://".$row['website2']."'>".$row['website2']."</a></br>"; } echo "</br></p></td>"; $cnt++; } elseif ($cnt == 2){ echo "<td valign='top' class='style9'><p align='center'><span class='style10'><strong>"; if($row['flockname']){ echo $row['flockname']; } echo "</strong></span><strong></br>"; if($row['firstname']){ echo $row['firstname']." ".$row['lastname']."</br>"; } if($row['address1']){ echo $row['address1']."</br>"; } if($row['address2']){ echo $row['address2']."</br>"; } if($row['city']){ echo $row['city'].", ".$row['state']." ".$row['zip']."</br>"; } if($row['email1']){ echo "<a href='mailto:".$row['email1']."'>".$row['email1']."</a></br>"; } if($row['email2']){ echo "<a href='mailto:".$row['email2']."'>".$row['email2']."</a></br>"; } if($row['website1']){ echo "<a target='_blank' href='http://".$row['website1']."'>".$row['website1']."</a></br>"; } if($row['website2']){ echo "<a target='_blank' href='http://".$row['website2']."'>".$row['website2']."</a></br>"; } echo "</br></p></td></tr>"; $cnt = $cnt - 2; } } mysql_close($connect); ?> I'd appreciate any help on this code, including a more efficient way to parse out the MySQL db rows into 3 columns in the HTML table. Thanks in advance! Ryan Hello, I'm new to the forum and I'm looking for advice. I use a bunch of classes in namespaces that are I'm attempting to organize for autoloading. In other words, a class called \Foo\Package\Class is loaded from the file at Foo\Package\Class.php. I'm using spl_autoload for this. (If I were on 5.2 I could be using underscore-delimited pseudo-namespaces just as well; the implementation detail isn't important) Now, I want to have multiple separate apps that use a single common library. Each app also has some classes that are local to it. How should I solve the autoloading problem? I thought of the following approach. Is it any good? Try autoloading from the common class library If it fails, try autoloading from the app's own local library Part 2 of the question: Within my apps, though, there are two types of classes: library ("vendor") classes that are only being used in that particular app so they don't need to be in the shared library, and app-specific classes that are the core of the app (so they, by definition, don't need to be in any shared library). I'd probably like to keep these two separate, so I'd need to add point #3 to the list above: search in the "core" class hierarchy of the local app. This gives 3 separate locations, and the problem is that they negate the advantages namespaces since there can be overlap. In which case one class will override the other during autoloading. So order of the above list would matter. And time would be wasted looking for a class in the first two places if it's more often in the third. A solution I was considering is sticking to just one central library of classes (and dumping all app-local libraries there). Then, the core classes that belong to one app would be under an \AppName namespace. I'm looking forward to some insights from the experts. How do you guys organize your class libraries? i created a insert php code which successfully submit to database but i was lost at some point because what i really wanted was a php code that will print on the next page after submission to db Hello, I am currently making a small website that requires two languages. This is the class I made: Code: [Select] <?php class languages { public function __construct() { if(!isset($_SESSION['language'])) { $_SESSION['language'] = 'nl'; } $lang = isset($_GET['lang']) ? $_GET['lang'] : ""; $languages = array('en', 'nl'); if(in_array($lang, $languages)) { $_SESSION['language'] = $lang; } } } $languages = new languages; $language = $_SESSION['language']; ?> Now as soon I use index.php?lang=en, the website will display it self in English but, as soon I remove the &lang=en from the URI, the language gets not stored in the session and it displays nl agian. Can somebody help me? Thank you! I came across usage of ^= in one the password hashing codes and am trying to find what this operator means in PHP. I have textfield for signature in my form, I m checking if the signature was sent ( if(!empty($_POST['signature'])) and if it's not empty I m putting it into the db. The problem is that, I have noticed a greek user has entered something in greek letters, and function could not deal with it and saved it as it is.( DB field supports greek charset ) I just want to allow english and german chars with special chars ( ",',< etc. ) , no other charset like greek. How can I do that? any function for this purpose ? Hi, I am trying to append a language session like this: Code: [Select] $ATC_itemWeight = floatval("".$row_productos_RS['capacidad_'.$_SESSION['session_idioma'].'']; but I get this error Code: [Select] Parse error: syntax error, unexpected ';' in /usr/home/mysite.com/web/productos_esp.php on line 121 what am I doing wrong? Thanks Hi again PHP Freaks.
So I would like to code something similar to the buy menu of Counter-strike: Global offensive in-game module, just in a browser and for a project of mine. I've made the design in photoshop to illustrate better.
I just don't know what I should look into to make this kind of menu, I would love if someone could explain me what languages that this would require. (I'm guessing HTML, CSS and jQuery but I am not sure) more specific help like which particular codes would be much appreciated.
Here is a picture of what I would like to create. (Also attached)
http://i1227.photobu...zps4195288a.png
Attached Files
CSGOKeyz.png 149.81KB
0 downloads I got site wirch I like tu turn to multilanguage. Code: [Select] <?=$home_jezik?>This is my variable for language code. So I wonna add it to Code: [Select] <?php echo $redak['novost_naslov_hr']; ?>so that "hr" change to "en" or any other language. I try with this but nothing happens Code: [Select] <?php echo $redak['novost_naslov_.$home_jezik']; ?> Hi! I want to have a first page on my website where you as visitor can choose the preferred language. No login at all. I want to save this choice in a cookie or something. The easiest way So next time he/she visits, the language choice is already made for he/she. Any good suggestions for a php code that works? are all languages possible to be inserted into database and be retrieved directly?? eg: write down the japanese words in the textbox and INSERT those into table and retrieve it using mysql_fetch_array() Is that as simple as that, or i have to modify certain script...for certain language? thanks what's the best way to have a website in 2 languages? I already have the website duplicated in the 2nd language but I'm thinking on the best way to do the language change. should I just append variables to the URL when clicking on the flag icon on each page to change to the 2nd language? any other ideas?? At the minute i am using variables in my tpl files in place of plain text so users can change the language the page is shown in. eg. the tpl file would include: $lang->hello; and the replacement would be $lang['hello'] = 'hello'; the php file would include the language class which replaces the variable in the language file with the array value in the relevant language file. but what happens when i have a phrase with a needed variable in the middle? $lang['msgs'] = 'you have '.$msgs.' messages'; i cant have 'you have' and 'messages' as seperate lang variables as phrases are constructed differently in other languages? so how do i accomplish this? hopefully i habe explained this ok. This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=321347.0 This topic has been moved to Other Libraries and Frameworks. http://www.phpfreaks.com/forums/index.php?topic=319523.0 |