Skip to content
This repository has been archived by the owner on Jan 19, 2022. It is now read-only.

Commit

Permalink
Incorporating stomlinson's review and edits.
Browse files Browse the repository at this point in the history
  • Loading branch information
ozten committed Mar 22, 2013
1 parent 405698f commit 9f4ccbe
Showing 1 changed file with 21 additions and 25 deletions.
46 changes: 21 additions & 25 deletions localization/localization_part_1.md
@@ -1,35 +1,33 @@
# How to Localize Your Node.js service # Localize Your Node.js Service


![](dialog_fanv2.png) ![](dialog_fanv2.png)


Mozilla provides products and services which are localized into as many as 90 languages! Did you know that Mozilla's products and services are localized into into as many as 90 languages?


The following are just a few examples of localization: The following are just a few examples of localization:
* Providing text translated into a specific regional variation of a language * Text translated into a regional language variations
* Rendering a screen right to left for a given language * A screen rendered right to left for a given language
* Bulletproofing designs to accommodate variable length prose * Bulletproof designs that accommodate variable length prose
* Making labels, headings, and buttons have names that resonate with a local audience * Label, heading, and button text that resonates with a locale audience


In this series of posts, I'm going to cover some technical aspects of how to localize a Node.js service. In this series of posts, I'm going to cover some technical aspects of how to localize a Node.js service.


I'll be using the terms L10n (<b>L</b>ocalizatio<b>n</b>) and I18n <b>I</b>nternationalizatio<b>n</b>. Before we start, I'll be using the acronyms L10n (<b>L</b>ocalizatio<b>n</b>) and I18n <b>I</b>nternationalizatio<b>n</b>. I18n is the technical plumbing needed to make L10n possible.


I18n is the technical plumbing needed, to make L10n possible. Mozilla Persona is a Node.js based service localized into X locales. Our team has very specific goals that inhibit us from using existing Node L10n libraries.


## i18n-abide ### Goals
We created these modules, to meet the following goals
* Work well with existing Mozilla L10n community
* Let developers work with a pure JS toolkit


Mozilla Persona is a Node.js based service localized into X locales. To accomplish this, it uses the following tools The resulting toolkit contains several new Node modules:


* i18n-abide * i18n-abide
* jsxgettext * jsxgettext
* po2json.js * po2json.js
* gobbledygook * gobbledygook


### Goals
We created these modules, to meet the following goals
* Work well with existing Mozilla L10n community
* Let developers work with a pure JS toolkit

i18n-abide is the main module you'll use to integrate translations into your own service. i18n-abide is the main module you'll use to integrate translations into your own service.
Let's walk through how to add it. Let's walk through how to add it.


Expand All @@ -53,9 +51,9 @@ In your code


We will look at the configuration values in detail during the third installment of this L10n series. We will look at the configuration values in detail during the third installment of this L10n series.


The i18n `abide` middleware sets up request processing and injects various functions we'll use for translation. The i18n `abide` middleware sets up request processing and injects various functions which We'll use for translation. Below, we will see these are available in the request object and in the templating context.


The next step is to work through all of your code where you have user visible prose. Okay, you next step is to work through all of your code where you have user visible prose.


Here is an example template file: Here is an example template file:


Expand All @@ -74,8 +72,8 @@ It will be either `ltr` or `rtl`. The English language is rendered `ltr` or left


`gettext` is a JS function which will take an English string and return a localize string, again based on the user's preferred region and language. `gettext` is a JS function which will take an English string and return a localize string, again based on the user's preferred region and language.


When doing localization, we refer to **strings** or Gettext strings. When doing localization, we refer to **strings** or Gettext strings:
These are pieces of prose, labels, button, etc. these are pieces of prose, labels, button, etc.
Any prose that is visible to the end user is a string. Any prose that is visible to the end user is a string.


Technically, we don't mean JavaScript String, as you can have strings which are part of your program, but never shown to the user. Technically, we don't mean JavaScript String, as you can have strings which are part of your program, but never shown to the user.
Expand All @@ -95,22 +93,20 @@ So to setup our site for localization, we must look through all of our code and


## Language Detection ## Language Detection


By setting up the i18n-abide module, we've actually installed a new piece of middleware. How do we know what the user's preferred language is?


At runtime, the middleware will detect the user's preferred language. At runtime, the middleware will detect the user's preferred language.


But, how do we know what the user's preferred language is?

The i18n-abide module looks at the `Accept-Language` HTTP header. The i18n-abide module looks at the `Accept-Language` HTTP header.
This is sent by the browser and includes all of the user's preferred languages with a preference order. This is sent by the browser and includes all of the user's preferred languages with a preference order.


i18n-abide processes this value and compares it with your app's `supported_languages` configuration. i18n-abide processes this value and compares it with your app's `supported_languages` configuration.
It will make the best match possible and serve up that language. It will make the best match possible and serve up that language.


If it cannot find a good match, it will serve up the strings you've put into your code and templates, which is typically English strings. If a good match cannot be found, it will use the strings you've put into your code and templates, which are typically English strings.


## Wrapping Up ## Wrapping Up


In our next post, we'll look at how strings like "Hello, World!" are extracted, translated, and prepared for use by our service. In our next post, we'll look at how strings like "Hello, World!" are extracted, translated, and prepared for use.


In the third post, we'll look more deeply at the middleware and configuration options. In the third post, we'll look more deeply at the middleware and configuration options. We'll also test out our localization work.

0 comments on commit 9f4ccbe

Please sign in to comment.