Translating Tutorial

Note: This tutorial refers mainly to the nightly build/svn version of Zenphoto since localization/translation is a work in progress. Zenphoto includes a file “zp-core/functions-l18n.php” that contains a prefdefined list of languages and their related locales. Check this list to be sure your language is included. If it is not there, let us know and we will add it.

  1. What should I know before starting a translation
  2. How does Zenphoto’s translation work?
  3. Language files and naming conventions
  4. Starting a new translation
  5. Updating/modifying an existing translation
  6. Separate plugin translation
  7. Separate theme translation (post Zenphoto 1.2)

What should I know before starting a translation?

Before you start check out the translations page to see which languages are available or look at the translation tickets on the trac to see on which worked is in progress or help is needed. Also check the nightly builds to see if perhaps work is completed and a language files released.

If you don’t find any ticket for your language (ask on the forum if unsure), open one for it. If you want to do the translation yourself, assign the ticket to yourself and accept it. You can later attach your language files to it. We can only accept files that are submitted via the ticket system.

Keep in mind that if you volunteer to make translations there will be the need of updating the languages files at least for every official release since Zenphoto is a work in progress. You may make your translation based on the current release of zenphoto. Then it can be provided to most Zenphoto users.

You should join the Google Zenphoto translator’s group. There you will find other like-minded people and be able to ask questions and share experiences. Also the developers post pre-announcements of up-coming Zenphoto releases to this group to give you a heads up so you can get your translations into that release.

Alternatively, you may choose to make your translation against the nightly builds. This way it will be ready for and matched up to the next release of Zenphoto. Currently there are over 1090 strings that need to be translated. Some are only single words though, some are doubled for specific reasons. Since we change strings here and there all the time we recommend doing updates frequently at least once a week, so it will be much easier to match a given release date of the next version. You simply will have less that way than doing all at once. So better think twice before your volunteer…:-) More on that in detail later.

It would be good if you were quite secure in written english and quite comfortable with Zenphoto itself and with web developement terms in general, even if you no coding is required when making a translation.

Just to note: Since a translation falls under copyright, your translation should be provided under a open licence compatible to Zenphoto’s GPL licence. If no special licence note is attached, we will assume GPL.

How does Zenphoto’s translation work?

Zenphoto uses the gettext technology to provide translation and localization capability. Currently this requires native gettext support, meaning gettext needs to be installed as a PHP extension on your server. But there are plans to provide a replacement for servers without native support some time in the future.

Zenphoto uses the message-level for translation. We use the standard gettext function gettext() to translate strings. If you are working with Zenphoto you might have spotted strings that look like this in the code:

<?php echo gettext("some text"); ?>

If a translation is found, “some text” will be replaced by the translation string. If no translation is found, simply “some text” is used.

Additionally Zenphoto uses translatable format strings rather than gettext fragments only (post Zenphoto 1.2).  You will also see strings that look like:

<?php echo sprintf(gettext('Album %1$u of %2$u'),$var1,$var2); ?>
<?php printf(gettext('Album %1$u of %2$u'),$var1,$var2); ?>

The things which begin with % are parameters that get filled in at runtime. We are using sprintf/printf to format the output. If you are not familiar with these functions you can review the format variables here: http://us3.php.net/manual/en/function.sprintf.php.

The quick lesson is that the above example has two numbers that will be filled in at runtime. %1$u is the first in the list and %2$u is the second. So the output from this would look like:

Album 5 of 10

If you wish to reverse the order of the elements you just change their place in the string while translating:

‘Of %2$u albums this is number %1$u’

would yield

Of 10 albums this is number 5

Which language translation to use you can be set within the admin options of Zenphoto. There is a separate option for setting the date-format, too.
The translation is provided then for the admin interface, setup.php and the standard themes and plugins included in the distribution. Month and day names do not need to be translated manually, these will be done automatically by your server, assuming that your server operates on your (chosen) country’s locale.

Third party themes and plugins will have

Language files and naming conventions

Zenphoto gets the translation terms itself from a .mo-file (machine object file). This file is binary and contains either the original text and the translation. But the actual file to translate is a .po-file (portable object file).

Both files are stored within zp-core/locale with the following standard folder structure:

de_DE/
de_DE/LC_MESSAGES
de_DE/LC_MESSAGES/zenphoto.po
de_DE/LC_MESSAGES/zenphoto.mo

The folder structure and the filenames are mandatory. You would have to provide an archive of exactly this structure for your language. If you finished your translation (at least 90%) and think it is ready for release, please zip the entire folder setup described abovel and rename it like this:

<locale>-<zenphoto version>.zip (example: de_DE-1.1.7.zip for the zenphoto 1.1.7 release)

Then attach it to your translaton ticket. We will than see that this file is ready to release and will link to it for download from the translation page of our extensions section that we will setup soon.

If you just want others to test or help with a svn/nightly translation, please rename the attached zip-file like

<locale>-nightly<date of nightly> (example: de_DE-nightly2008-06-30)
<locale>-svn<svnnumber> (example: de_DE-svn1822).

In the above examples the German locale “de_DE” is used. Here are two lists with some locales for example:

Since the .mo-file is binary, you can’t work directly with it, so you have to work with the .po-file instead. This is a normal text file, that looks like this:

msgid ""
msgstr ""
"Project-Id-Version: zenphoto 1.1.5 svn\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2008-04-09 17:50+0100\n"
"PO-Revision-Date: 2008-04-09 17:56+0100\n"
"Last-Translator: john smith <john@smith.net>\n"
"Language-Team: john smith\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Poedit-Language: German\n"
"X-Poedit-Country: GERMANY\n"
"X-Poedit-SourceCharset: utf-8\n"
"X-Poedit-Basepath: /Applications/MAMP/htdocs/zenphoto-svn/\n"
"X-Poedit-SearchPath-0: zp-core\n"
"X-Poedit-SearchPath-1: themes\n"

#: zp-core/admin-functions.php:169>
msgid "A reset request has been sent."
msgstr "Eine Reset-Anfrage wurde gesendet."

(...)

You can edit this file with any text editor. But you have to transform it into a .mo-file to be used for translation. There are several tools that can do that for you:
The official GNU gettext package includes command-line tools, but you might prefer a real editor with a GUI. For Linux based systems there are for example LaunchPad or KBabel and others, but considered the standard tool for this is Poedit which is available for Windows, Mac and Linux. We would recommend Poedit (well, we don’t really know the others..:-)) and the description in the next section uses it. But probably the setup for another editor will be not that different.

Starting a new translation

There are basically two ways to start on a translation: You could use the in the Zenphoto distribution included German translation file and change it to your language. Or you can parse the Zenphoto package yourself using Poedit.
The second is the way we would recommend, because you then can be sure that you don’t miss any string since we update and change all the time. And it saves workload if you update the file more often than just once when a new version comes out.

  1. Download and install Poedit.
  2. Download the latest nightly build of zenphoto and extract the files the same folder where Poedit is or a folder level below. Poedit needs a absolute path to work correctly. This does not need to be within a localhost server setup like WAMP, LAMP or MAMP, but of course this would be very useful to test your translation.
  3. On Mac OS X the folder to parse is best localed on the same level or below Poedit’s location in the Applications folder, since the paths to are relative from Poedit’s location:
    Zenphoto folder: <harddrive>/Applications/MAMP/htdocs/zenphoto
    Poedit: <harddrive>/Applications/Poedit
    Also working is simply the folder (as used on 6.):
    Zenphoto install: <harddrive>/Applications/zenphoto
    Poedit: <harddrive>/Applications/Poedit
    On Windows that folder setup seems not to be that important.
  4. Do not install any additional plugins or themes besides the already included ones as some may included additional gettext calls (and separate translation files) that are not necessary for Zenphoto’s own translation file and bloat the file unnessecarily.
    Then open zenphoto/zp-core/locale in your zenphoto installation, duplicate the de_DE folder or any other folder and rename it to match your locale.
  5. Now open Poedit and select “New Catalog”:
    1-4-new-catalog.jpg
  6. In the appearing setttings window enter your data. Most are pretty obvious, only language, country and charset are mandatory. Set the charset to UTF-8. The last field “Plural forms” does not matter since Zenphoto does not use gettext plural forms.1-5-general-data.jpg
  7. Next you need to set the path of the zenphoto folder to parse. (See also 2.) Remember that it is important to divide a path like this C:\Programs\zenphoto into the base path C:\Programs\ and the relative path zenphoto (Mac OS X example shown below).
    1-6-folder-path.jpgYou can ignore the keywords tab, because Zenphoto uses the default gettext keyword.
  8. In the appearing save window change the name of the file from default.po to zenphoto.po and save/overwrite it within your new zenphoto/zp-core/locale/<your locale>/LC_MESSAGES/ folder (in the image the German locale is used as example).
    1-7-saving-the-file.jpg
  9. You will now see that Poedit searches the zenphoto folder for gettext calls.
    1-8-building-the-file.jpg

    When finished, simply hit “Ok”. Don’t get confused if Poedit notes a “Poedit Error”. It’s actually a display bug (at least in the Mac version), there is a “done” on the right. Everything is fine, no strings harmed.
    1-8b-no-poedit-error.jpg
  10. Now you see on the left the original english strings. Klick on an line and you can enter the translation for it below. The two field on the right bottom can be used for comments to the translation, but are not really important now.1-9-translation-window.jpg

  11. Sometimes you will encounter HTML markup within the strings to translate. We have included them because some languages have a very different syntax that might require changing the order within a string. These markup needs to be included within your translation, too.Also you might think that some strings are completly useless like a lonely “)” or the double point in “View image:” for example. It’s not forgotton, but on purpose. There are languages that use not only differenty syntax but completly different characters, too. And some even write from right to left, so these characters need to be changeable, too.Sometimes you might see a string that you don’t need or want to translate. Something like “SpamAssassin” is most likely a fixed term for example. You can leave that field empty, but it’s recommend to fill in the same term, so simply use the context menu to copy the original string to the translation field.
    1-9b-context-menu.jpg
  12. Some sentences are hard to translate without knowing the context. Poedit’s context menu will show you were in Zenphoto the referring string is used.
    1-9c-copy-original.jpg
  13. When you are done with translation just hit save and Poedit automatically generates a .mo-file that is used for the translation called zenphoto.mo. Now you should check your translation with Zenphoto.
    It’s recommended to use your zenphoto folder as a base for future translation updates, so that you don’t have to change the parsing path for Poedit all the time.
  14. To submitt your translation to the zenphoto team generate an archive of your locale folder with all its subfolders. Since we probably will provide the files as a additional downloads, a common type like .zip or .tar would be good.

Updating or modifying an existing translation

  1. If you choose to update or modify your own translation or a translation someone else had provided, you can just open the .po-file of that locale with Poedit. IMPORTANT: If that file was not generated by you, you would have to check and change the path to parse to match your zenphoto folder in Poedit’s settings!
    2-1-adjusting-settings.jpg
  2. If you have done that, hit “Update” and Poedit will now compare the translation file with the zenphoto folder to check if and what strings have changed.If Poedit finds untranslated strings, they will be listed in the window below you already know. The second tab then will show strings that are not used anymore. These will be deleted from the file. (None found in this example)
    .2-2-new-strings.jpg
  3. If you have worked in that language before, Poedit might have collected some terms in its internal dictionary and will try to autotranslate some strings. These strings are then marked in a dark yellow as “fuzzy”. Most of the time Poedit is fairly wrong with its guesses though, so don’t count on that.2-3-auto-translate.jpg
    Blue strings are apparently empty, while successfully translated are printed in black (freshly translated ones are marked with a little star). Poedit lists the percentage of translation, the total number of strings plus the fuzzy strings (autotransation attempts), the bad ones and the untranslated in the bottom left footer.
    2-3b-poedit-statistic.jpg
  4. When you are finished with you update, hit “Save” again and the .mo-file gets automatically updated.

Plugin translations

Plugins which are included with the Zenphoto distribution are handled by the normal processing as described above. The process for third-party-plugins is slightly different.

The difference is that you have to parse the plugin file itself. Just create a folder and place your plugin and, if it exists, the plugin’s subfolder (like some plugins have) within it. Now setup Poedit as described above to parse this special folder.

Important: The plugin translation files must be placed within zp-core/plugins/<plugin name>/locale/<language locale>/LC_MESSAGES/ and must have the name of the plugin (<plugin name>.po <plugin name>.mo)

Theme translations (post Zenphoto 1.2)

Themes which are included with the Zenphoto distribution are also handled by the normal processing as described above. The process for third-party-themes is similar than for plugins.

Again you have to parse the theme folder itself. Now setup Poedit as described above to parse your theme folder.

Important: The theme translation files must be placed within themes/<theme name>/locale/<language locale>/LC_MESSAGES/ and must have the name of the plugin (<theme name>.po <theme name>.mo)