Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
dev:l10n [2007/02/10 11:55]
prabath
dev:l10n [2009/07/06 20:36] (current)
Line 4: Line 4:
 "The gettext functions implement an NLS (Native Language Support)  "The gettext functions implement an NLS (Native Language Support) 
 API which can be used to internationalize your PHP applications" API which can be used to internationalize your PHP applications"
 +
 +
  
  
 ===== Usage ===== ===== Usage =====
-When using gettext we can use the gettext() or _() function. But we will be using the _() function for sahana.+gettext can use either the gettext() or _() function. In Sahana we use the _() function.
 (Even if you use gettext() it will still work) (Even if you use gettext() it will still work)
  
Line 16: Line 18:
  
 localization enabled localization enabled
-<title><?php print _("DVR Home"); ?></title>+  - <title><?php print _("DVR Home"); ?></title>
  
 </code> </code>
  
 +Please remember to localize all the strings. It's very easy to localize in Sahana.
 +example:
 +<code php>
 +<?=_("Organization Name")?>
 +</code>
 +
 +
 +
 +You **can't** use un-escaped double quotes ("" **inside** of the string. This usually happens when you use single quotes (``) to enclose a string. 
 +
 +**Try to always use double quotes to enclose strings and escape (\") any other double quotes inside the string**
 +
 +<code php>
 +e.g:
 +_('Home page "http://sahana.lk" ')
 +
 +this should be,
 +_("Home page \"http://sahana.lk\" ")
 +
 +</code>
 +
 +
 +**If there are a number of quotation marks inside the gettext function you can follow the following coding convention**
 +
 +<code php>
 +e.g:
 +_('To do this in the navigation bar click on "Multiple Incidents" followed by <a href="?mod=admin&act=ims_level1">
 +  "Manage Disaster"</a> and add the disaster name');
 +
 +this should be,
 +
 +_('To do this in the navigation bar click on ').'&#34;'._('Multiple Incidents').'&#34;'._(' followed by ').
 +'<a href="?mod=admin&act=ims_level1">'.'&#34;'._('Manage Disaster').'&#34;'.'</a> '._(' and add the disaster name.');
 +
 +</code>
 +
 +Above coding shows rather than using quotation marks you can use the html special character available for quotation mark, which is &#34; . Make sure to keep a space between words.
 +
 +Don't localize variables.
 +example: we don't want to see code similar to the following:
 +<code php>
 +<?=_($org)?>
 +</code>
 +
 +
 +
 +
 +
 +===== gettext Best Practices =====
 +
 +    * 1. Please make sure gettext contain only word phrases. 
 +
 +<code php>
 +e.g:
 +_('<h2>Welcome to the Sahana FOSS Disaster Management System</h2>');
 +
 +this should be,
 +echo "<h2>"._('Welcome to the Sahana FOSS Disaster Management System')."</h2>";
 +</code>
 +
 +    * 2. If there are html tags which we have to put within word phrase make sure to separate it from gettext. (see above example) 
 +
 +    * 3. When writing paragraph within gettext make sure line brakes are not there (In this case line breaks are behave in  different ways in different editors for instance Eclipse put line break when you press enter but Qunata won't put line break but it'll wrap it). 
 +
 +<code php>
 +e.g:
 +Eclipse behave as follows
 +_("The SAHANA Disaster Victim Registry is a central online repository " .
 +"where information on all the disaster victims can be stored. Information like name, age" .
 +", contact number, id card number, religion, race, displaced location, current location and other ")
 +
 +This paragraph appears in sahana.po file in separate lines,not in a paragraph.Solution for Eclipse IDE users is  
 +writing the paragraph in same line.
 + 
 +Quanta will wrap this paragraph and appears in sahana.po file as a paragraph,which is allright :-) .
 +
 +</code>
 +
 +    * 4. Html special characters should separate from gettext.
 +    * 5. Beware of quotation marks, please put html special characters for quotation marks(Quotation marks are always bother developers :-)) 
 +
 +
 +Rule of thumb is to keep contain of gettext as simple as possible
  
 ===== Database Localization ===== ===== Database Localization =====
Line 35: Line 120:
 === Database Localization Usage === === Database Localization Usage ===
  
-To display a value retrieved from the database in some other language, the developer has to use use the function _lc(). This function takes a single string as the paramiter and will return the translated value of that string. If a translation is not available this will return the same value.+To display a value retrieved from the database in some other language, the developer has to use use the function _lc(). This function takes a single string as the parameter and will return the translated value of that string. If a translation is not available this will return the same value.
  
 == _lc() function == == _lc() function ==
Line 90: Line 175:
  
 Sahana now has a web interface for the language translation using the GNU Gettext framework. Sahana now has a web interface for the language translation using the GNU Gettext framework.
-Currently using this interface the user can [ extract ] the strings that needs to be translated and create the template file for the translation, add the translation to the PO file and compile the PO file to create the MO file. Using this interface the user can also add strings manually (Database values etc..) to be translated. +Using this interface the user can [ extract ] the strings that needs to be translated and create the template file for the translation, add the translation to the PO file and compile the PO file to create the MO file. Using this interface the user can also add strings manually (Database values etc..) to be translated.
- +
-===== Configuration ===== +
- +
-For the web interface to work you have to give read write permission to the 'res/locale/' and all it's sub directories. +
-You also have to have gettext installed and have 'xgettext', 'msgfmt and 'msgmerge' available with in an accessible PATH (/usr/bin/) to get the full functionality of the system. +
-You have to have the gettext extension in php for the translation to work. Otherwise you will only see the strings in the base language, which is usually en_US (English). +
- +
-===== Translating Sahana ===== +
- +
-You can access the translation interface by going to 'System Administration' -> 'Language Translation'.  +
-Before doing the translation make sure you have selected the correct locale for your language. You can do that by going to 'System Administration' -> 'Set Locale' and selecting the language from the select box. +
- +
-The normal way of doing a translation would be, +
-  * Load the existing list  +
-  Should be loaded at the start. If not Click the 'Load Existing List' button. +
- +
-  * Do the translation. +
-  The translation is done by entering the translated string for the 'msgid' string in the 'msgstr'+
-e.g: +
- +
-  #: ../inc/lib_security/acl_action_form.inc:50 +
-  #: ../inc/lib_security/acl_action_form.inc:145 +
-  msgid "* Description:" +
-  msgstr "* විස්තර:" +
- +
- +
- +
-  * Save the translated list +
-  After doing the translation save the translated list. Press the 'save' button to save the list (Make sure you have permission to res/locale/ directory and it's sub directories) +
- +
-  * After saving the translated list you have to compile the translated PO file in to a MO file which is ultimately used in the localization of sahana. This can be done using the 'Compile Messages' button on the bottom right hand corner of the page. +
  
 +For details, see the User Docs on [[doc:localisation:english|Activating a Locale]] & [[doc:translation:english|Translation into a new language]].

Navigation
QR Code
QR Code dev:l10n (generated for current page)