<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

  <title>Techno Barje</title>
  <link href="http://techno-barje.fr/feed/jetpack.xml" rel="self"/>
  <link href="http://techno-barje.fr"/>
  <updated>2012-09-19T07:00:00.000Z</updated>
  <id>http://techno-barje.fr/</id>
  <author>
    <name>Alexandre Poirot</name>
  </author>

  
  <entry>
    <title>Addon SDK 1.11 - the page-mod release</title>
    <link href="http://techno-barje.fr/post/2012/09/19/1.11-page-mod-release/"/>
    <updated>2012-09-19T07:00:00.000Z</updated>
    <id>http://techno-barje.fr/post/2012/09/19/1.11-page-mod-release</id>
    <content type="html">&lt;p&gt;&lt;a href=&quot;https://addons.mozilla.org/en-US/developers/docs/sdk/latest/packages/addon-kit/page-mod.html&quot;&gt;page-mod API&lt;/a&gt; is the most commonly used API in jetpack. It allows to execute Javascript piece of code against any given website. It is very similar to greasemonkey and userscripts.&lt;/p&gt;
&lt;p&gt;In Addon SDK version 1.11, which is due for October, 30th, we will bring various subtle but very important fixes, features and improvements to this API. In the meantime we will start releasing beta versions on tuesday (09/25) with 1.11b1.&lt;/p&gt;
&lt;p&gt;Here is an overview of these changes:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;p&gt;You will now be able to execute page-mod scripts to already opened tab, by using the new &lt;code&gt;attachTo&lt;/code&gt; option.
[&lt;a href=&quot;https://bugzilla.mozilla.org/show_bug.cgi?id=708190&quot;&gt;bug 708190&lt;/a&gt;]&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;With the same &lt;code&gt;attachTo&lt;/code&gt; option, you can execute page-mod scripts only on top-level tab documents, and so avoid being applied to iframes. 
The &lt;a href=&quot;https://blog.mozilla.org/addons/2012/09/12/introducing-page-mods-attachto/&quot;&gt;following blogpost&lt;/a&gt; goes into detail about this new option.
[&lt;a href=&quot;https://bugzilla.mozilla.org/show_bug.cgi?id=684047&quot;&gt;bug 684047&lt;/a&gt;]&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;page-mod now ignores non-tab documents like: panel, widget, sidebar, hidden document living in firefox&amp;#39;s hidden window, ...
[&lt;a href=&quot;https://bugzilla.mozilla.org/show_bug.cgi?id=777632&quot;&gt;bug 777632&lt;/a&gt;]&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Your addon will be more efficient as we removed some costly workaround: the Javascript proxies layer between your content script and the page. We are now relying directly on C++ wrappers, also known as Xraywrappers. We are expecting a major improvement in term of memory and CPU usage. As this change depends on modifications made in Firefox, it will only be enabled on Firefox 17 and greater.
[&lt;a href=&quot;https://bugzilla.mozilla.org/show_bug.cgi?id=786976&quot;&gt;bug 786976&lt;/a&gt;]&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Content scripts are now correctly frozen when you go back and forth in tab history. Before that, your content script was still alive and could throw some unexpected exception or modify an unexpected document.
[&lt;a href=&quot;https://bugzilla.mozilla.org/show_bug.cgi?id=766088&quot;&gt;bug 766088&lt;/a&gt;]&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Random fixes: window.top and window.parent will be correct for iframes [&lt;a href=&quot;https://bugzilla.mozilla.org/show_bug.cgi?id=784431&quot;&gt;bug 784431&lt;/a&gt;].&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Last but not least and still at risk for 1.11 release. You will be able to extend priviledges of your content script to extra domains. So that your script will now be able to execute some action on your own domain in addition to the current page domain, without facing cross domain limitations. This rely on some improvements being made to Firefox and will only be enabled on Firefox 17+.
[&lt;a href=&quot;https://bugzilla.mozilla.org/show_bug.cgi?id=786681&quot;&gt;bug 786681&lt;/a&gt;]&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;It is realy exciting to see our most used API receiving so many improvements and I hope that we fixed most of the long-living issues you may have faced with page-mod!!&lt;/p&gt;
&lt;p&gt;We would really like to get your feedback on these changes. If you find anything wrong, please, file bugs &lt;a href=&quot;https://bugzilla.mozilla.org/enter_bug.cgi?product=Add-on%20SDK&quot;&gt;here&lt;/a&gt; and do not hesitate to come discuss with our team in the &lt;a href=&quot;https://groups.google.com/forum/?fromgroups#!forum/mozilla-labs-jetpack&quot;&gt;mailing-list&lt;/a&gt; &lt;/p&gt;
</content>
  </entry>

  <entry>
    <title>Jetpack localization using YAML format</title>
    <link href="http://techno-barje.fr/post/2011/11/17/jetpack-localization-yaml/"/>
    <updated>2011-11-17T08:00:00.000Z</updated>
    <id>http://techno-barje.fr/post/2011/11/17/jetpack-localization-yaml</id>
    <content type="html">&lt;p&gt;In &lt;a href=&quot;/post/2011/10/31/jetpack-localization/&quot;&gt;a previous post&lt;/a&gt;, I&amp;#39;ve described my first proposal for localization support in jetpack addons. I&amp;#39;ve decided to change locale files format for &lt;a href=&quot;http://en.wikipedia.org/wiki/YAML&quot;&gt;YAML&lt;/a&gt; instead of JSON. During MozCamp event, folks helped me identifying some pitfalls with JSON:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;No multiline string support.&lt;/strong&gt; Firefox parser allows multiline but it is not officialy supported! So that it will disallow third party tools to work properly.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;No easy way to add comments.&lt;/strong&gt; It is mandatory for localizers to have context description in comments next to keys to translate. As there is no way to add comments in JSON, it will end up complexifying a lot locale format.&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id=&quot;example&quot;&gt;Example&lt;/h1&gt;
&lt;pre&gt;&lt;code class=&quot;language-yaml&quot;&gt;
# You can add comments with `#`...
Hello %s: Bonjour %s         # almost ...
hello_key: Bonjour %s        # wherever you want!

# For multiline, you need to indent your string with spaces
multiline:
  &amp;quot;Bonjour
   %s&amp;quot;

# Plural forms.
# we use a nested object with attributes that depends on the target language
# in english, we only have &amp;#39;one&amp;#39; (for 1) and &amp;#39;other&amp;#39; (for everything but 1)
# in french, it is the same except that &amp;#39;one&amp;#39; match 0 and 1
# in some language like Polish, there is 4 forms and 6 in arabic
#
# So that having a structured format like YAML,
# help us writing these translations!
pluralString:
  one: &amp;quot;%s telechargement&amp;quot;
  other: &amp;quot;%s telechargements&amp;quot;

# I need to enclode these strings with `&amp;quot;` because of %. See note after.
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;
// Get a reference to `_` gettext method with:
const _ = require(&amp;quot;l10n&amp;quot;).get;

// These three forms end up returning the same string.
// We can still use a locale string in code, or use a key.
// And multiline string gets its `\n` removed. (there is a way to keep them)
_(&amp;quot;Hello %s&amp;quot;, &amp;quot;alex&amp;quot;) == _(&amp;quot;hello_key&amp;quot;, &amp;quot;alex&amp;quot;) == _(&amp;quot;multiline&amp;quot;, &amp;quot;alex&amp;quot;)

// Example of non-naive l10n feature, plurals:
_(&amp;quot;pluralString&amp;quot;, 0) == &amp;quot;0 telechargement&amp;quot;
_(&amp;quot;pluralString&amp;quot;, 1) == &amp;quot;1 telechargement&amp;quot;
_(&amp;quot;pluralString&amp;quot;, 10) == &amp;quot;10 telechargements&amp;quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;h1 id=&quot;advantages-of-yaml&quot;&gt;Advantages of YAML&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Multiline strings are supported nicely / easy to read.&lt;/strong&gt; You do not need to add a final &lt;code&gt;\&lt;/code&gt; on all lines. As mulitiline is easier, localizers can use them more often and it will surely improve readability of locale files!&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Structured data format.&lt;/strong&gt; we can use this power whenever it is needed. For example, when we need to implement complex l10n features like plural forms or any feature that goes beyond simple 1-1 localization. The cool thing if we compare to JSON is that even if we define structures, we keep a really simple format with no noise (like {, }, &amp;quot;, ...).&lt;/li&gt;
&lt;/ul&gt;
&lt;br/&gt; 

&lt;p&gt;As nothing comes without any issues, here is what I&amp;#39;ve found around YAML:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;This format is not a Web standard. I don&amp;#39;t think it makes much sense to avoid using it because of that. We are clearly missing a standardized format for localization in the web world.&lt;/li&gt;
&lt;li&gt;You may hit some issues when you do not enclose your strings with &lt;code&gt;&amp;quot;&lt;/code&gt; or &lt;code&gt;&amp;#39;&lt;/code&gt;. For example, you can&amp;#39;t start a string with &lt;code&gt;%&lt;/code&gt;, nor having a &lt;code&gt;:&lt;/code&gt; in middle of your string without enclosing it.&lt;/li&gt;
&lt;li&gt;Even if YAML is not a web standard, it has been formaly specified. And unfortunately, a handy feature becomes a pitfall for our purpose! Some strings are automatically converted. &lt;code&gt;Yes&lt;/code&gt;, &lt;code&gt;True&lt;/code&gt;, &lt;code&gt;False&lt;/code&gt;, ... are automatically converted to a boolean value. We can work around this in multiple ways, either by documenting it, or modifying the parser. The same solution apply here, you need to enclose your string with quotes.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;br/&gt;&lt;br/&gt;&lt;/p&gt;
&lt;p&gt;Again, feedback is welcomed on &lt;a href=&quot;https://groups.google.com/group/mozilla-labs-jetpack/t/da50c6dac33b445b&quot;&gt;this group thread&lt;/a&gt; and you can follow this work in &lt;a href=&quot;https://bugzilla.mozilla.org/show_bug.cgi?id=691782&quot;&gt;bug 691782&lt;/a&gt;.&lt;/p&gt;
</content>
  </entry>

  <entry>
    <title>Jetpack localization</title>
    <link href="http://techno-barje.fr/post/2011/10/31/jetpack-localization/"/>
    <updated>2011-10-31T07:00:00.000Z</updated>
    <id>http://techno-barje.fr/post/2011/10/31/jetpack-localization</id>
    <content type="html">&lt;p&gt;I&amp;#39;m going to describe the first proposal of localization support for Jetpack. 
This approach uses gettext pattern and json files for locales.
It is the first step of multiple iterations. This one only allows retrieving localized string in javascript code.
We are going to give ways to translate files, mainly HTML files, through another iteration.
And we are about to offer an online tool to ease addon localization (like babelzilla website).&lt;/p&gt;
&lt;p&gt;Let&amp;#39;s start by looking at a concrete example, then I&amp;#39;ll justify our different choices.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;{
  &amp;quot;Hello %s&amp;quot;: &amp;quot;Bonjour %s&amp;quot;,
  &amp;quot;hello_user&amp;quot;: &amp;quot;Bonjour %s&amp;quot;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;// Retrieve a dynamic reference to `_` gettext method with:
const _ = require(&amp;quot;l10n&amp;quot;).get;

// Then print to the console a localized string:
console.log(_(&amp;quot;Hello %s&amp;quot;, &amp;quot;alex&amp;quot;));
// =&amp;gt; Prints &amp;quot;Bonjour alex&amp;quot; in french.

// Or, if we don&amp;#39;t want to use localized string in addon code:
console.log(_(&amp;quot;hello_user&amp;quot;, &amp;quot;alex&amp;quot;));
&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;why-gettext&quot;&gt;Why gettext?&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;It gives a way to automatically fetch localizable strings or ids from source code
by searching for &lt;code&gt;_(  )&lt;/code&gt; pattern. &lt;/li&gt;
&lt;li&gt;It allows to use either strings or IDs as value to translate. 
It is obviously better to use IDs. Because locales will broke
each time addon developer fix a typo in the main language hard coded in the code.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;But we should not forget that the high level APIs is trying to
simplify addon development. So that it has to be really easy to translate a simple
addon that has only 2 JS files and less than 50 lines of code!
And the simple fact to mandatory require a locale file for the default language
appears like a big burden for such small addon.&lt;/p&gt;
&lt;p&gt;Having said that, I&amp;#39;m really happy that gettext approach doesn&amp;#39;t discourage, nor
makes it harder to use IDs, and so, if an addon developer build a big addon
or just want to take more time to use better pratice, he still can do it, easily!&lt;/p&gt;
&lt;h2 id=&quot;why-json-for-locales&quot;&gt;Why JSON for locales?&lt;/h2&gt;
&lt;p&gt;We could have used properties files, like XUL addons. But this format has some 
limitations that are not compatible with gettext pattern. Keys can&amp;#39;t contain spaces
and are limited to ASCII or something alike, so that we can&amp;#39;t put text in a key.&lt;/p&gt;
&lt;p&gt;So instead of using yet another specific format, I&amp;#39;m suggesting here to use JSON.
JSON is really easy to parse and generate from both client and server side,
and I&amp;#39;m convinced that it is simple enough to be edited with a text editor.
On top of that we can build a small web application to ease localization.&lt;/p&gt;
&lt;p&gt;In my very first proposal, I used a complex JSON object with nested attributes.
But it ends up complexifying the whole story without real advantage.
So I&amp;#39;m suggesting now to use the most simple JSON file we can require: 
one big object with keys being strings or id to translate and values being translated strings.
Then we will be able to use JSON features to implement complex localization features,
like plurals handling. So that values may be an array of plurals forms.&lt;/p&gt;
&lt;h2 id=&quot;the-big-picture&quot;&gt;The big picture&lt;/h2&gt;
&lt;p&gt;Everything starts with one addon developer or one of its contributor.
If one of them want to make the addon localizable, they have to use this new localization module.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;const _ = require(&amp;quot;l10n&amp;quot;).get;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;There is already multiple choices that has been made here:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;_&lt;/code&gt; is not a &lt;em&gt;magic global&lt;/em&gt;. We need to explicitely require it. 
This choice will simplify compatibility with other CommonJS environnements, like NodeJS.&lt;/li&gt;
&lt;li&gt;The name of the module itself is &lt;code&gt;l10n&lt;/code&gt; instead of &lt;code&gt;localization&lt;/code&gt; in order to ease the use of it.&lt;/li&gt;
&lt;li&gt;This module expose &lt;code&gt;_&lt;/code&gt; function on &lt;code&gt;get&lt;/code&gt; attribute in order to be able to 
expose another methods. I&amp;#39;m quite confident we will need some functions for plurals or files localization.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Then, they need to use &lt;code&gt;_&lt;/code&gt; on localizable strings:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;var cm = require(&amp;quot;context-menu&amp;quot;);
cm.Item({
  label: _(&amp;quot;My Menu Item&amp;quot;),
  context: cm.URLContext(&amp;quot;*.mozilla.org&amp;quot;)
});
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now, they have two choices:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;use a string written in their prefered language, like here. 
So that they don&amp;#39;t have to create a locale file.&lt;/li&gt;
&lt;li&gt;use an ID. Instead of &lt;code&gt;_(&amp;quot;My Menu Item&amp;quot;)&lt;/code&gt;, we will use: &lt;code&gt;_(&amp;quot;contextMenuLabel&amp;quot;)&lt;/code&gt;.
But it forces to create a localization file in order to map &lt;code&gt;contextMenuLabel&lt;/code&gt; to &lt;code&gt;My Menu Item&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Then, either a developer or a localizer can generate or modify locales files.
Each jetpack package can have its own &lt;code&gt;locale&lt;/code&gt; folder. 
This folder contains one JSON file per supported language.
Here is how looks like a jetpack addon:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;* my-addon/
  * package.json   # manifest file with addon name, description, version, ...
  * data/          # folder for all static files
    * images, 
    * html files, 
    * ...
  * lib /          # folder that contains all JS modules:
    * main.js      # main module to execute on startup
    * my-module.js # custom module that may use localization module
    * ...
  * locale/       # our main interest!
    * en-US.json
    * fr-FR.json
    * en-GB.json
    * ...
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The next iteration will add a new feature to our command line tool,
that is going to generate or update a locale file for a given language by fetching localization strings from source code.
For example, the following command will generate &lt;code&gt;my-addon/locale/fr-FR.json&lt;/code&gt; file:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sh&quot;&gt;$ cfx fetch-locales fr-FR
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;{
  &amp;quot;My Menu Item&amp;quot;: &amp;quot;My Menu Item&amp;quot;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Finally, we need to replace right side values with the localized strings:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;{
  &amp;quot;My Menu Item&amp;quot;: &amp;quot;Mon menu&amp;quot;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And build the final addon XPI file with:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-sh&quot;&gt;    $ cfx xpi
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Any kind of feedback would be highly appreciated on &lt;a href=&quot;https://groups.google.com/group/mozilla-labs-jetpack/t/da50c6dac33b445b&quot;&gt;this group thread&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;If you want to follow this work, 
subscribe to &lt;a href=&quot;https://bugzilla.mozilla.org/show_bug.cgi?id=691782&quot;&gt;bug 691782&lt;/a&gt;.&lt;/p&gt;
</content>
  </entry>

</feed>
