action

Localization in Action, part 3 of 3 – A Node.js holiday season, part 11

This is episode 11, out of a total 12, in the A Node.JS Holiday Season series from Mozilla’s Identity team. It’s the last part about localization, hopefully making you feel all ready to handle that now!

Using Our Strings

So first we added the i18n-abide module to our code, then our Localization (L10n) team did some string wrangling, now we’ve got several locales with translated strings…

Let’s get these strings ready for Node.js and see this puppy in action!

The next step is that we’ll need your PO files, typically in a file system like this:

locale
  en
    LC_MESSAGES
      messages.po
  de
    LC_MESSAGES
      messages.po
  es
    LC_MESSAGES
      messages.po

We need a way to get strings from our PO files into our application at runtime. There are a few ways you can do this:

  1. Have server side strings and the gettext function provided by i18n-abide will work it’s magic.
  2. Have client side strings and you’ll include a gettext.js script in your code. This is distributed with i18n-abide.

Both of these methods require the strings to be in a JSON file format.
The server side translation loads them on application startup, and the client side translation loads them via HTTP (or you can put them into your built and minified JavaScript).

Since this system is compatible with GNU Gettext, a third option for server side strings is to use node-gettext. It’s quite efficient for doing server side translation.

We’ll use the first option in this blog post, as it is the most common way to use i18n-abide.

compile-json

So, how do we get our strings out of the PO files and into JSON files?

Our build script is called compile-json.

Assuming out files are in a top level directory locale of our project, and we want the .json files to go into static/i18n, we’d do this:

Example:

$ mkdir -p static/i18n
$ ./node_modules/.bin/compile-json locale static/i18n

And we get a file structure like:

static
  i18n
    en
      messages.json
      messages.js
    de
      messages.json
      messages.js
    es
      messages.json
      messages.js

compile-json loops over each of our .po files and calls po2json.js on it, producing .json and .js files. po2json.js is another program provided by i18n-abide.

If we take the Spanish messages.po we have so far from these blog posts, we’d see:

# Spanish translations for PACKAGE package.
# Copyright (C) 2013 THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# Austin King <ozten@localhost>, 2013.
#
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2012-06-24 09:50+0200\n"
"PO-Revision-Date: 2013-04-24 16:42-0700\n"
"Last-Translator: Austin King <ozten@nutria.localdomain>\n"
"Language-Team: Spanish\n"
"Language: es\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
 
#: /home/ozten/abide-demo/views/homepage.ejs:3
msgid "Mozilla Persona"
msgstr "Mozilla Personidada"

which would be converted into

messages": {
      "": {
         "Project-Id-Version": " PACKAGE VERSION\nReport-Msgid-Bugs-To: \nPOT-Creation-Date: 2012-06-24 09:50+0200\nPO-Revision-Date: 2013-04-24 16:42-0700\nLast-Translator: Austin King <ozten@nutria.localdomain>\nLanguage-Team: German\nLanguage: de\nMIME-Version: 1.0\nContent-Type: text/plain; charset=UTF-8\nContent-Transfer-Encoding: 8bit\nPlural-Forms: nplurals=2; plural=(n != 1);\n"
      },
      "Mozilla Persona": [
         null,
         "Mozilla Personidada"
      ]
   }
}

So we can use these .json files server side form Node code, or client side by requesting them via AJAX.

The static directory is exposed to web traffic, so a request to /i18n/es/messages.json would get the Spanish JSON file.

This static directory is an express convention, you can store these files where ever you wish. You can serve up static files this via Node.js or a web server such as nginx.

Note: You don’t need the .PO files to be deployed to production, but it doesn’t hurt to ship them.

Configuration

i18n-abide requires some configuration to decide which languages are supported and to know where to find our JSON files.

As we saw in the first installment, here is the required configuration for our application

app.use(i18n.abide({
  supported_languages: ['en-US', 'de', 'es', 'zh-TW'],
  default_lang: 'en-US',
  translation_directory: 'static/i18n'
}));
  • supported_languages tells the app that it supports English, German, Spanish, Chinese (Traditional).
  • The translation_directory config says that the translated JSON files are under static/i18n.
  • Note that translation_directory is needed for server side gettext only.

We explained in the first post that i18n-abide will do its best to serve up an appropriate localized string.

It will look at supported_languages in the configuration to find the best language match.

You should only put languages in supported_languages, where you have a locale JSON file ready to go.

Start your engines

Okay, now that configs are in place and we have at least one locale translated, let’s fire it up!

npm start

In your web browser, change your preferred language to one which you have localized.

Now load a page for your application. You should see it translated now.

For a real world example, here is Mozilla Persona in Greek. So, cool!

gobbledygook

If you want to test your L10n setup, before you have real translations done, we’re built a great test locale. It is inspired by David Bowie’s Labyrinth.

To use it, just add it-CH or another locale you’re not currently using to your config under both supported_languages as well as the debug_lang setting.

Example partial config:

app.use(i18n.abide({
  supported_languages: ['en-US', 'de', 'es', 'zh-TW', 'it-CH'],
  debug_lang: 'it-CH',
  ...

Now if you set your browser’s preferred language to Italian/Switzerland (it-CH), i18n-abide will use gobbledygook to localize the content.

This is a handy way to ensure your visual design and prose work for bi-directional languages like Hebrew. Your web designer can test their RTL CSS, before you have the resources to create actual Hebrew strings.

Going Deeper

We’ve just scratched the surface of i18n and l10n. If you ship a Node.js based service in multiple locales, you’ll find many gotchas and interesting nuances.

Here is a heads up on a few more topics.

String interpolation

i18n-abide provides a format function which can be used in client or server side JavaScript code.

Format takes a formatted string and replaces parameters with actual values at runtime. This function can be used in one of two flavors of parameter replacements.

Formats

  • %s – format is called with a format string and then an array of strings. Each will be replaced in order.
  • %(named)s – format is called with a format string and then an object where the keys match the named parameters.

You can use format to keep HTML in your strings to a minimum.

Consider these three examples

<%= gettext('<p>Buy <a href="/buy?prod=blue&amp;tyep=ticket">Blue Tickets</a> Now!</p>') %>
<p><%= format(gettext('Buy <a href="%s">Blue Tickets</a> Now!'), ['/buy?prod=blue&amp;tyep=ticket']) %></p>
<p><%= format(gettext('Buy <a href="%(url)s">Blue Tickets</a> Now!'), {url: '/buy?prod=blue&amp;tyep=ticket'}) %></p>

In the PO file, they produce these strings:

<p>Buy <a href=\"/buy?prod=blue&amp;tyep=ticket\">Blue Tickets</a> Now!</p>"
msgid "Buy <a href="%s">Blue Tickets</a> Now!"
msgid "Buy <a href="%(url)s">Blue Tickets</a> Now!"

The first example has a paragraph tag that shows up in the PO file. Yuck. If you ever change the markup… you may have to update it in every locale!

Also, look at that ugly URL.

Reasons to use format:

  • Avoid confusing localizers who aren’t familiar with HTML and may break your code accidentally
  • Avoid maintenance issues

The named parameters are nice, in that they are self documenting. The localizer knows that the variable is a URL. String interpolation is quite common in localizing software.

Another example is runtime data injected into your strings.

<p><%= format(gettext('Welcome back, %(user_name)s'), {user_name: user.name}) %></p></p>

Avoid Inflexible Designs

We need to put our L10n hats on early. As early as when we review the initial graphic design of the website.

  • Avoid putting text into images. Use CSS to keep words as plain text positioned over images.

  • Make sure CSS is bulletproof. An English word in German can be many times larger and destroy a
    poorly planned design.

  • Try this bookmarklet: Fauxgermanhausen das Pagen!

Database-backed websites have already taught us to think about design in a systematic way, but designers may not be used to allowing for variable length labels or buttons.

String Freeze

Remember our build step to prepare files for localizers to translate? And in this post we learned about po2json.js for using these strings in our app… Well, this means we’re going to need to coordinate our software releases with our L10n community.

Continuous deployment isn’t a solved problem with L10n. Either you have to block on getting 100%
of your strings translated before deploying, or be comfortable with a partially translated app in some locales.

L10n teams may need 1, 2 or even 3 weeks to localize your app, depending on how many strings there are. Schedule this to happen during the QA cycle.

Provide a live preview site, so that localizers can check their work.

Wrapping up

In these three blog posts, we’ve seen how to develop a localized app with i18n-abide, how to add a L10n phase to our release build, and lastly, how to test our work.

Localizing your website or application will make your site valuable to an even larger global audience.

Node.js hackers, go make your services accessible to the World!

Previous articles in the series

This was part eleven in a series with a total of 12 posts about Node.js. The previous ones are:

View full post on Mozilla Hacks – the Web developer blog

VN:F [1.9.22_1171]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

Another foreword – HTML5 in Action

Keeping the streak alive, I was asked to provide a foreword for another book, this time HTML5 in action by Robert Crowther, Joe Lennon, and Ash Blue. So here is what I had to say:

Foreword

Explaining what HTML5 is can be a very daunting task. I’ve been doing this more or less since its inception and I am still amazed just how many myths and how much confusion is there on the topic.

With HTML5 we re-booted web development. The world of HTML4.01 and the non-starter XHTML left those who wanted to use the web as a platform for applications stranded. HTML4 was meant for linked documents and XHTML was far too strict for its own good and it lacked real support in browsers.

HTML5 started with a clean slate. We analysed what was used on the web and added a lot of features we didn’t have before, like CANVAS for creating visuals on the fly or accessing images and videos on a pixel level, native audio and video without the need for plugins and forms that validate in the browser without us having to write extra JavaScript. We also started mudding the waters by merging HTML and JavaScript functionality – a lot of HTML5 will not do anything without accessing the elements via a JavaScript API. This confuses a lot of people. We moved on from a document based web and in that process we need more technical know-how. And this means we need to rethink a few of our “best practices” now which can annoy people so that they spread nasty rumours about the viability of HTML5 as a choice for professional development.

HTML5 is built on the robustness principle, which means that a browser will make a lot of educated guesses what you might have meant when you make a syntax error instead of simply giving up and showing an error. This gives it backwards compatibility and we will be able to show pages developed for a never-to-arrive XHTML world in browsers these days. A large part of the standard is just that – it tells you how to write a browser that renders HTML5 rather than using it as a web developer. Again, this angers some people and they shout about the verbosity of the standard.

HTML5 is also the new hotness. A lot of advertising talk, shiny demos and promises of fidelity that matches native apps on phones make us cynical battle hardened web developers think back on Java, Flash and Silverlight and their promises and sigh. We have a lot of buzz about HTML5 and a lot of things that are not part of the standard are simply declared part of it as it makes a good punch line.

When it comes to extending the language and bringing new features into it we are running wild right now. Every browser maker and web company comes up with great new concepts on almost a weekly level. That can be frustrating for developers who just want to get a job done. Can you rely on the functionality that is currently developed or will the standard be changed later on? We are pushing browsers further into the operating system and allow them to access hardware directly which comes with security and robustness issues that need to be fixed by trial and error. Can you take that risk with us when it comes to delivering your product?

These are exciting times and when you want to be part of the ride you can help forge the future development environment for all of us. If you don’t have the time to follow the discussions on mailing lists, do a lot of browser testing in previews and propose own ideas you can be left quite confused.

And this is where a book like this comes in. Instead of promising you a cornucopia of functionality that will soon be available you get examples that work right now based on examples that worked in the past. Instead of getting experimental demos you learn how to build production code based on proven ideas but using the features in modern browsers that make it easier for us developers and much more enjoyable for our end users. All the examples come with a legend telling you which browsers support the features and you learn how not to give them to old browsers that will choke on them.

You will learn how to use HTML5 now, using secure and intelligent solutions like Modernizr and HTML5 Boilerplate and you will come out at the end understanding how to write things in HTML5 that work right now. This will make you a part of the movement to get HTML5 “production ready” for all of us.

Those who live on the bleeding edge of defining the next browser and language features need implementations in the wild right now. We are past the show and tell stage and we need to get to deliver and enhance. And you can become an integral part of this process by following the advice and applying the examples you find here. Go forth and deliver.


View full post on Christian Heilmann

VN:F [1.9.22_1171]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

Lights, Camera, Action! July Dev Derby is all about HTML5 Video!

Show off your coolest video hack in July’s Mozilla Dev Derby!

Moving pictures have always fascinated people. From the first zoetropes to the multi million dollar blockbusters of today – seeing things move grabs our attention as humans much better than any clever copy or imagery could. Video was alien to the web for a long time. Well, not alien, but we needed plugins to make them play. With newer browsers and HTML5, we now have the <video> element to natively embed video in a web page. This allows us to, amongst other things:

  • Style video elements with CSS and SVG
  • Make the video interact with other elements of the document and vice versa
  • Use Canvas to grab frames from videos and manipulate them
  • Create accessible video as the controls can be used with a keyboard without us having to write that functionality

Using this arsenal, you can do pretty cool things. You can:

..and many more things.

Now it is your turn to show us what you can do with HTML5 video! We don’t expect you to build another Wilderness Downtown or 3 Dreams of Black, but we are very excited to offer you the chance to shine in July’s Mozilla Dev Derby.

Why not use CSS3 and Canvas to redesign the Outer Limits intro? Why not make the video do the things Diana Ross talks about in Upside down? Why not build a video cropping tool in Canvas? How about you have a crack at making closed captioning and subtitling work with HTML5 video? There are many ideas floating about – it just needs a bit of drive and a text editor to go for it. So, show us what you can do!

There are a lot of tools out there to make your life easier with HTML5 video. Vid.ly makes it easy to convert videos, Popcorn.js is a library to sync page content and video and there are many tutorials on video available.

To get you into the mood and see some examples in action, we are running an HTML5 video webinar on the 14th of July and you can ask some questions you have upfront using Google Moderator.

Bring the web screen alive, I dare you! I am off to watch Cinema Paradiso again.

View full post on Mozilla Hacks – the Web developer blog

VN:F [1.9.22_1171]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

Sr Web Developer Action Script, Mobile

WA-Seattle, Sr Web Developer Action Script, Mobile Start ASAP 3 month-1 year contract Seattle, WA Role Purpose: Our clients organization is looking for a highly talented Developer crucial to helping deploy branded advertising experiences on PC, Mobile and TV. In general, the Web Developer is responsible for connecting to the back end by either connecting to outside APIs, databases, Socket Servers, or other te View full post on Monster Job Search Results jt:(Web Developer)

View full post on WebProJobs.org

VN:F [1.9.22_1171]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

As Music Web Market Grows , Google Wants To Get Into The Action

When Warner Music the music label appointed Goldman Sachs to help find buyers early this year, the stock price of the beleaguered music company shot up from an all time low of $6 to $7.7 as everyone from oil tycoons to supermarket moguls and bigger music brands like Sony Universal and WMG showed interest. However […]

View full post on web development – Yahoo! News Search Results

VN:F [1.9.22_1171]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

SketchyPad in action



VN:F [1.9.22_1171]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

New generation of Web browsers ready for action

Browser makers Microsoft, Mozilla and Google believe it is possible to spend even more time on the Web. The next generation of browsers, including Internet Explorer 9, promises more social networking, better graphics and faster speeds, all designed to make you live more of your life online.

View full post on Yahoo! News Search Results for web development

VN:F [1.9.22_1171]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)