OxyScripts.com
Menu spacer Home Tutorials Articles Code Forums irc.freenode.net #oxyscripts
Main (PHP)
Home Forums PHP News PHP Tutorials Articles PHP Code Snippets Contact Us Sysadmin Resources Books Template Shop
3rd Party Streams
SlashDot PHPDeveloper.org PHP.Net
Resources
PHP Manual MySQL Manual Smarty Manual PEAR Manual PHP-GTK Manual Symfony Manual
Code Snippets
Authentication Database Graphics HTTP Miscellaneous Time/Date
Affiliates
Scripts TutorialMan TutorialGuide CodingForums.com PHP Scripts Cheap Web Hosting Affordable Web Hosting Dreamweaver Templates

Search This Site :     PHP Function Reference :
 
Gettext

Gettext is a set of tools, guidelines, directory naming conventions and a runtime library. Together, they are the standard way to translate applications in the *nix environment. Don't be scared, you can use it on Windows as well. I don't want to describe the whole system here, just the things you need to translate your application - you can read the manual if you want more information.

The gettext system translates replaces whole strings with the translated equivalent in the target language. This means that you don't have to invent array keys but can keep the original string in the code, which makes it a lot more readable. The translations are written down in so-called .po-files, where "po" stands for "portable object". They contain the human-readable and human-editable translation of the strings to the target language. To speed up the live-translation process when the application is running, they are compiled to .mo-files, "machine object" files. These files are required to be in a certain directory structure:
locale
  -language-
    LC_MESSAGES
      -applicationname-.po
      -applicationname-.mo
  de
    LC_MESSAGES
      appwizard.po
      appwizard.mo
      tuxracer.mo
  es
    LC_MESSAGES
      appwizard.mo
      tuxracer.mo
   
Here you see, that there are 2 languages: german (de) and spanish (es). They contain both the machine object files for the applications AppWizard and TuxRacer. The original translation files are not required for running the program, and so only the german translation file for AppWizard is here. If you are on *nix, have a look at /usr/share/locale/. You will find the translations for many programs there.

A .mo translation file looks the following way:
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR Free Software Foundation, Inc.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2002-04-06 21:44-0500\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"
#: gettext_example.php:12
msgid "A string to be translated would go here"
msgstr "Ein string der übersetzt werden soll steht hier"

msgid "Really quit?"
msgstr "Wirklich beenden?"

msgid "This is a glade language test script"
msgstr "Dies ist ein Glade Sprach-test script"
The first 15 lines are a sort of header, which can be customized with dates and authors. After the header the translation begins: msgid tells what shall be translated, and msgstr is the translation. Special chars in strings can be escaped as usually with a backslash \.

After translating your strings, you have to compiles the .po to .mo files which is done by using the msgfmt tool. On *nix, you should have it somewhere; on Windows you can get it with mingw32. Go to the LC_MESSAGES directory and just call the compiler:
# msgfmt messages.po
which will result in a messages.mo file.

 
   Print this page

Top Sponsor
Symantec\'s Norton SystemWorks 2006
Sponsors
CA
Sponsors
AdWords Dominator 125*125
Advertisting


Affiliates
VertexTemplates PHPFreaks CodeWalkers StarGeek DevScripts CGI & PHP Scripts PHP CMS Free Templates

Shopping Rebates   Sell It 4 You   Flash Page Counters   Get Insured
GPS Tracking Service   Charity Donate Info   Web Site Hosting   VOIP Service

Privacy Policy | Links | Site Map | Advertising

All content on OxyScripts.com is (©)2002-2007

 
Powered by Adrastea - Version 1.0.0. Copyright © Rune Solutions, 2004-2005