Labs/Ubiquity/Ubiquity 0.5 Command Localization Tutorial: Difference between revisions

Line 6: Line 6:


== Gettext and the <code>po</code> format ==
== Gettext and the <code>po</code> format ==
Ubiquity command localization follows the <code>po</code> (portable object) format of the [http://en.wikipedia.org/wiki/Gettext GNU gettext] system. <code>po</code> is a de facto standard in the world of localization, particularly in the UNIX world, and is supported by a variety of different tools and editors.
Like most types of localization, Ubiquity command localization works essentially by replacing strings. The original commands are written without regard for other languages, as long as they follow [[Labs/Ubiquity/Ubiquity_0.5_Making_Commands_Localizable|certain guidelines]] to keep the command localizable. The commands are written with strings in a set ''source language'' and, through the process of localization, Ubiquity will go through and replace those source language strings with the ''target language'' equivalents. In the case of Ubiquity's built-in commands, the source language is always English.
Here is one translation entry from a Ubiquity command's <code>po</code> file:
  msgctxt "twitter.execute"
  msgid "direct message sent"
  msgstr "ダイレクトメッセージを送信しました。"
Every* Ubiquity translation entry consists of these three parts:
# <code>msgctxt</code>, the message context. This is a structured string which tells you which command's string this is, and which aspect of the command's behavior it is related to. Here, this translation entry is from the <code>execute</code> code of the <code>twitter</code> command.
# <code>msgid</code>, the message id. This is the original text in the source language, so you know exactly what content needs to be translated. This must exactly match the localized string in the command code.
# <code>msgstr</code>, the message string. This is the localized string in the target language, here Japanese. As expected, the <code>msgstr</code> above says "direct message was sent" in Japanese.
<small>* almost every - see "shared keys" below.</small>
Ubiquity's localization files for built-in commands are all stored in a central directory, and are organized by command feed. For example, the localization of the <code>firefox.js</code> command feed must be called <code>firefox.po</code> and is placed in the directory <code>ubiquity/localization/XX/</code>, where <code>XX</code> is your language's language code. For example, the Danish localization file for <code>firefox.js</code> would be stored as <code>ubiquity/localization/da/firefox.po</code>.
<code>po</code> files may be translated in a text editor or in specialized localization software. Some free tools include [http://www.poedit.net/ poEdit] and [http://en.wikipedia.org/wiki/Translate_Toolkit Translate Toolkit]. All Ubiquity <code>po</code> files are in UTF8 encoding. Traditional Gettext also uses a binary format called <code>mo</code> (machine object) but Ubiquity only uses <code>po</code> files.


== Localization templates ==
== Localization templates ==
308

edits