Tuesday, 18 August 2015 00:00

Playing with utf8 urls

Playing with utf8 urls

If you ever had an experience of developing website for a language except English and you wish to use utf8 URLs you saw the problem. The problem is that you can not compare incoming URLs with the value in your language. What you see is % + characters that do not mean anything. To retrieve the value of meaningless URL you should decode it. In PHP this can be done using urldecode() function. If you ever wish to convert the language phrase to what eventually ends up in user browser you can use urlencode(). The result of this function is those % + chars .

Published in PHP

Create a Joomla multi language website

Several top-notch documents have been already written explaining how to build a Joomla Multi Language Website or how to convert your website to another language version in Joomla; a great example of such tutorials is this one. In this article the author does not intend to repeat those steps to create a multi language website from scratch but to complement required steps since the author feels that following those steps are not enough in some cases. This tutorial explains methods to build Second language modules and menus from existing modules, translate custom components, have a Kunena forum for two or more languages and finally to translate template specific texts for your multi language website in joomla.

Build multi language menus or modules from already existing ones

 To build your menu in second language you don’t need to define a separate menu for your language but just to define menu items for your second language to do that follow these steps:

  1. Select the menu from which you’re going to produce second language items

Create Multi language website from first language

  1. Select first menu item in the list

Joomla multi language website

  1. Press “Save as copy” button(Be sure that the menu item you selected is in first language like English and not All languages)

Change Menu Language to Make the website multi language

  1. In newly generated menu item from previous menu item fill related name and alias for the menu item in your second language. And select related article that is translation of your original menu or related “Data Source” in case your menu item is a custom type.
  2. The most important part is to Select you second language as its language

Create Multi language Components and Modules in Joomla

  1. Repeat steps “b” to “e” for other menu items in the Menu you selected in step ”a”

Steps for Modules is just similar to what you did for Menu but remember to have one module for your first language let’s say “English” and one for your second language e.g. “Persian” and not any for “All”.

Translate Joomla custom components(or other extensions)

Usually most of famous extensions in Joomla already have “language package” for your desired language and you just need to download and install them. For example for famous Kunena forum you can just go to this address and see if there is already a language package for your language. But if you’re not lucky and there is not still a language package for the component you’re looking for don’t worry you can do it on your own.

Every standard developed extension in Joomla puts its user interface's texts in a file in [Joomla-Root-Installation-Directory]\language\en-GB. For example if you have K2 component installed in a website named “test” on Apache there is a file: [path-to-htdocs]\htdocs\”test”\language\en-GB\en-GB.com_k2 that contains all the text K2 shows in news pages like “children categories” or “news” text. Copy the file that contains the English texts of the component you want to translate and paste it in [path-to-htdocs]\htdocs\”test”\language \[Your-language-tag] directory for example for Persian this "Your-language-tag" is “fa-IR”. If you don’t know what your language tag is you can go to Extensions->Language Manager and see what it is. After that all you need to do is to rename that file and replace the language tag of English which is “en-GB” with your language tag e.g. fa-IR.com_k2. Then open that file with text editor (my favorite in windows is notepad++ and in Linux gedit) and replace English texts with their equivalent in your language. For example find “Children categories” and replace it with “زیر شاخه ها”. Do this for all the texts if you don’t want to have problems in future and see English texts in your other language's pages.

Translate template texts to make the website multi language

Joomla Multi language Kunena forum

Some extensions are working fine with one language but not fully compatible with multi language websites. And that is, when you change the language just texts are being translated but Right-to-Left or Left-to-Right feature of the page does not change. Kunena has such problem and depending on the language you first time visit Kunena component, forums always being rendered to suit that language. For example if you have a website with two languages: English and Persian, and you first time visit Kunena forum in your English website the Kunena forum always are rendered Left-To-Right no matter what language you select. To resolve that problem you should add some custom CSS to your forum pages in one of the language.

For example I installed Kunena forum and its language package on my website and visit Kunena forum in Persian language and to resolve the problem that my Kunena forum is always Right-to-Left even when user change the language to English I added this CSS codes to forum menus in English:

                       #Kunena td.kprofileboxcnt {

                                    text-align: left !important;

                                    }

                        #Kunena .klist-markallcatsread {

                                    float: left !important;

                                    }

                        #Kunena .kheader h2 a {

                                    text-align: left !important;

                                    float: left !important;

                                    }

                        #Kunena .kheader h2  {

                                    text-align: left !important;

                                    }                                 

                        #Kunena div.kthead-title a {

                                    float: none !important;

                                    }

                        #Kunena table.kblocktable {

                                    text-align: left !important;

                                    }

                        #Kunena div.ktopic-title-cover {

                                    text-align: left;

                                    }

 

To add custom CSS to a menu(English Kunena forum in this case) I used hd-customcss3 module.

Translate other unfamiliar texts in a Joomla multi language website

After translating everything, you’re surfing your website and you may still run into texts in English or awkward texts with “-“between them. Linux geeks know how to handle this problem using grep but this may seem a little unknown for windows users. Well, it is simple just download grepWin from this address, Install it, right click on your website folder for example …\htdocs\test, search for the unfamiliar text you see on your page and change it to whatever you want. If you want to translate (not just change) that text follow previous sections' procedures

Published in Tutorials

How to upload a symfony website to a shared host in 7 steps

For a beginner, uploading a symfony website to a shared host like Cpanel, Plesk, Kloxo, Direct Admin or etc is a frustrating task. Some may give up on using the host and just purchase a VPS instead of using a shared hosting solution. In my case, just an answer regarding the feasibility of using a shared host with symfony was enough but I couldn’t find one; well the good news is, I uploaded symfony websites to all mentioned control panels' shared hosts successfully, even on a windows shared hosting (Plesk control panel) with IIS server installed. Ok, there may be a lot of questions that occupy developer’s mind such as are pear packages or SSH access requirement on the shared hosting required in order to do such task? You don't need any further access except the control panel's access! Just follow the mentioned steps and you are good to go but remember that these steps worked and tested for symfony 1.4.

What is symfony?

Symfony is a PHP framework and a very good solution to implement enterprise level applications. Currently the symfony is in its 2 version.

What is shared hosting?

Shared hosting provides a web space and databases on a shared web server for you. On a shared hosting server your website is not the only one on the server; as a matter of fact sometimes thousands of websites are hosted on a single server. 

Which shared hosting companies support symfony ?

Some shared hosting companies may claim that they support "symfony shared hosting"; although this is not a false claim, all mentioned control panels at the beginning of this article support "symfony".

Step by step guid to upload a symfony website to a shared host

  1. A symfony built website has all of its needed files and you need nothing more than the required PHP version and configurations on the shared host (I tested on a host having PHP version of 5.2.17) so to check this requirement just upload the check_configuration.php .to your shared host and run it by putting the address pointing to this file in browser. For example if you upload it to your shared host's root and your host address is example.com then you should go to the address: http://www.example.com/check_configuration.php .
  2. If you passed previous step then you are good to perform following steps. Clear your cache either using symfony cc command or just simply deleting all the files in the cache folder.  It is also recommended that you delete files in your log folder.
  3. Create a database in your shared host and set a username and password. Put these database name, username and password in your Config/database.yml file. Export your tables and data into a file from your localhost and import it to the created database.
  4. Zip your symfony web site folder and files. Typically the zip should contain these 10 folder and files: apps, cache, config, data, lib, log, plugins, test, web, symfony. Upload and extract this zip to your shared host let’s say public or httpdocs folder.
  5. Change permissions of cache and log folder (in your host) to full control or 777.
  6. Change directory root of your shared host to point to the web folder
    1. If you’re using other folder name rather than web then you need to introduce it to symfony by putting this line $this->setWebDir($this->getRootDir(‘[whatever name you gave]’)) in your config/ProjectConfiguration.Class.php and setting host's document root to point to that folder.
  7. If you are uploading your website to a windows shared host with IIS installed as web server --let’s say plesk control panel—then you have a problem to access other links of your site except the home. The problem originates from the fact that IIS can’t process .htaccess file and you need to introduce it someway that IIS recognize. Ok IIS uses url rewrite module to process user friendly urls and you can follow this article to learn how to convert an .htaccess file to equivalent web.config file but in symfony 1.4 case you can simply download and use this web.config file and upload it to your web folder.
Published in Tutorials
Advanced Programming Concepts
News Letter

Subscribe our Email News Letter to get Instant Update at anytime