Categories
main mozilla tech

Using Common Pool – Tutorial

In this post I’m going to show you how to make your extension localizable via Common Pool and how it can be localized.

early adopter warning: It’s the first attempt, it’s a new concept, things may brake, things may be a little rough, stay calm. It’s not a replacement for a well known solutions yet, but it may be one day. Play with it, hack the service and the library, suggest improvements, report the issues, but stay calm whatever happens – there may be dragons.

Using the library

Since Common Pool is currently implemented in Addon SDK, I assume you’re using it for writing your extension. First thing is to add my localization module to your extension. It’s available at http://builder.addons.mozilla.org.

Once you have it in your dependencies, you can just include it into your code.

Let’s take an example Hello World code:

var notifications = require("notifications");

var menuItem = contextMenu.Item({
  label: "Hello World",
  contentScript: 'on("click", function (node, data) {' +
    '  postMessage(node.src);' +
  '});',
  onMessage: function (imgSrc) {
    notifications.notify({
      title: "Hello World",
      text: "Welcome to the new, wonderful world!",
    });
  }
}

Now, in order to make it localizable, all we need to do is to add one require, and change the string initialization:

var notifications = require("notifications");
var _ = require("localization").get;

var menuItem = contextMenu.Item({
  label: _("Hello World"),
  contentScript: 'on("click", function (node, data) {' +
    '  postMessage(node.src);' +
  '});',
  onMessage: function (imgSrc) {
    notifications.notify({
      title: _("Hello World"),
      text: _("Welcome to the new, wonderful world!"),
    });
  }
}

Done! That’s what I meant when I wrote that Common Pool is asking as little attention from the developer as possible. If it reminds you of common patterns used by GetText, you’re right on spot. We like this notation, we reuse it.

With such code, you’re ready to go 🙂 As a developer, you can move along, do your work, deploy your extension on AMO and never ever bother about this again, while we will make sure that the localizers can localize, and users will receive the localized version dynamically. 🙂

Early adopter warning: For the time of the field testing of this library, we do not actually have any integration with AMO, so when you want your addon to be localized, you need to “cfx xpi” it, or if you’re using the builder just click on “Download” and upload the result xpi here: https://l10n.mozillalabs.com/projects/p/mozilla-jetpacks/upload/. This is a temporary step

Using the web service

Once a developer uploaded his addon and his job is done, the camera shifts onto another hero – a localizer. This brave soul, can just go to https://l10n.mozillalabs.com, log in and start localizing. As a localizer, you can just select your locale and start localizing. You can filter by an extension and you can view how other locales localized it.

You can also select overrides and add one for a given jetpack or occurrence. When you finish localizing your jetpack, you’re done. We will spread your translation to all users of the jetpack who use your locale. If you later update your translation, all users will receive an update on the next day. Isn’t that awesome? 🙂

Early adopter warning: Until we fix bug 10, we refer to jetpacks by their unique ID, instead of the human readable name. It should be fixed soon 🙂

The beauty of early adopting

Well, that being said, you know you would not be happy to receive a complete, ready to use, bug free solution. That’s not what hackers life is about. In fact, we decided to blow quite a big hole through the middle of the road that’s called “First Run Experience“.

As we were working on the library, and the webservice, and how nicely they’re tied, and we enjoyed the experience of a user staying up to date with localization of his extensions, and being able to download an extension in en-US and then see it localized on the day when a localizer finishes localizing it… we actually did not solve a pretty important case. Here’s the issue:

When a user installs an extension it contains no translation resources bundled with it. On the first run, we asynchronously ask the localization web service for the entities used by the extension. So far so good.

The server asynchronously sends the user all the entities and they’re cached. From that moment every request for a string will work by providing a translation of the string. But what happens before we cache?

Well, for now, nothing. Bummer 🙁 Basically, until we cache the strings, all we have is an empty cache and the localization library will just return the english strings which is the default fall back.

The bug for that is reported, bug 619807, and we’re working on a solution for that. We may decide to bundle entities that we have available for the extension together with it at the time of download, but that will be just a workaround. An ideal solution would be to pull the localizations together with the addon (as a part of addon installation experience) and then check if there are any localization updates on a normal daily routine.

If you have any ideas, suggestions or code snippets that solves it – feel free to jump in and help! 🙂

Real Life Example

Take a look at this example extension, Translate Selection with l10n. Now, go to l10n.mozillalabs.com to see its localization and localize it live.

Next time you run this extension you should be able to see it working with localization (assuming your browser is using your locale and minus the First Run Experience bug).

That’s all. 🙂

Summary

Common Pool is a simple, yet very powerful solution. It solves a lot of issues that we’ve been struggling with since the beginning of times. It makes internationalization easier than ever, localization easier than ever and synchronization easier than ever. Bare in mind, it’s intended as a solution for simple strings, for developers who don’t have much time to think through their UI’s and plan it for localization, and for massive localization of tons of thousands of extensions.

We believe it nails it perfectly (with the few early adopters hiccups that we’re working on right now, and an unlimited number of issues that are awaiting to be discovered by you!), and we want to improve it until we feel it to be the right one.

At the same time, please, remember that for a more complex and sophisticated UI’s, the ones where a developer has to think about entities, and the localizer wants to fine tune each and every sentence – we’re going to work on a complementary, L20n based solution.

Now, it’s your turn to play with it, hack on it, give us feedback and help us evaluate the solution. We’re available at irc.mozilla.org #l10n and #jetpack channels, and we use mozilla-labs-jetpack group that you can use. For bugs in the l10n web service, please, use its bitbucket issue reporting system. Thanks! 🙂

Categories
main mozilla po polsku tech

Samoświadomość przeglądarkowa – living on the edge

Są takie dni kiedy człowiek musi spojrzeć sobie prosto w oczy i przyznać się, sam przed sobą, jak używa przeglądarek.

browser geek

taka już pewnie natura tego co robię, ale mam… sporo… przeglądarek. Ile pytasz? No… jakby to…

iCab, Opera 10a, Amaya 11.1, Camino 2.0b2, Seamonkey 2.0 nightly, Flock 2.1 nightly, Firefox trunk nightly, Fennec nightly, WebKit nightly, Shiira, Arora nightly, Chromium nightly, Safari 4 alpha…Czy to normalne panie doktorze?

Co ciekawe, właściwe wszystkie obsługują nowoczesne standardy (tylko Amaya jakoś tak inaczej  ;)), wszystkie są szybkie rozwijają się dynamicznie i każda posiada jakieś unikalne cechy, których nie ma inna.

rozszerzenia

Podstawową przeglądarką jest dla mnie Firefox, aktualnie używam czegoś co nazywa się Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.2a1pre) Gecko/20090306 Minefield/3.2a1pre ale pewnie zmieni nazwę w związku z planowaną zmianą Fx 3.1 na 3.5.

Powyższe daje mi dużo miłych udogodnień i powodów do dumy (jak ostatnie nowości w TraceMonkey, interfejsy do <video/>, acid3 na 94% etc.) , ale skutkiem ubocznym jest ograniczona możliwość korzystania z rozszerzeń.

To czyni mnie mało aktywnym ich użytkownikiem, i jak na browser geeka, plasuję się pewnie na dość dalekiej pozycji z moimi 4 rozszerzeniami:

  • Ubiquity – na razie to dla mnie troche jak gesty myszy. Wiem, że są przydatne, ale ciągle zapominam korzystać. Jak sobie przypomne, to pomaga 🙂
  • Weave – długo używałem jedynie eksperymentalnie ale od powrotu do domu mam desktop i laptop (i na obu różne systemy) więc zacząłem korzystać masowo.
  • Firebug – zmienia sposób tworzenia stron
  • About:tab – najnowsze nabytek. Eksperyment w stronę rozwiązań z Opery, Chrome i Safari ale w połączeniu z podejściem znanym z Ubiquity

Dużo? Mało? Nie wiem… oczywiście wszystkie w wersji nightly.

Jednym z ciekawych efektów takiego używania przeglądarek (i nie tylko, testuje MacOS Snow Leopard, KDE4.3, Android nightly, Thunderbirda 3 nightly, Ubuntu 9.04, Windows 7…) jest to, że wszystko wydaje mi się stare. Kumpela używa “najnowszej” wersji? heh… Firefox 3? Heh… Ubuntu 8.10? Heh… wszystko jakieś takie

stare? 🙂

Ten typ tak ma. Ale jakby ktoś szukał czegoś do potestowania to polecam eksperyment z About:Tab.