L20n/Features/Language Negotiation

From MozillaWiki
< L20n‎ | Features
Jump to: navigation, search


goals

  • the app knows which locales are available
  • for small projects, fetching localizations should be easy (single http request/file i/o)
  • we might need to convey additional metadata to the client, such as fallback routes.

proposed solutions

  • a json bundle
  • a manifest file
  • inline metadata
  • server side negotiation

JSON bundle

HTML:

 <link rel="resource" type="application/l20n" href="locales/homescreen.json">

JSON:

 {
     "de": "<entry \"Deutsch\">",
     "fr":..
 }

JSON stores the serialized and possibly minified L20n code.

→ Why should we store the whole l20n markup instead of a JSON AST?

Manifest file

HTML:

 <!doctype html>
 <script type="text/javascript" src="../l10n.js"></script>
 <link rel="manifest" type="application/json" href="../manifest.json">
 <link rel="resource" type="application/lol" href="l10n:apps/homescreen">
 <button data-l10n-id="test" title="click me!">This is a test</button>

manifest.json:

 {
    "root": "/srv/http/example.com/locales",
    "urischeme": "{{ locale }}/{{ urn }}.lol",
    "locales": {
        "supported": [
            "fr",
            "pl"
        ],
        "current": "fr"  // comes from the server side lang negatiation
    }
 }

Inline metadata

HTML:

 <!DOCTYPE html>
 <html data-locales='de fr'>

or:

 <!DOCTYPE html>
 <meta name="locales" content="fr de">
 <meta name="locales-path" content="../blabla/here/be/dragons/">

Note: your project needs to be really small, or dynamically generate your html from templates; otherwise adding a locale to the list might be a pain requiring you to modify all html files.

Server side

Another possibility is the provide a server side component that would recognize requests to l20n files and serve the resource in the correct language. This has the benefit of the server side negotiation being generaly more powerful than the client side one.

The exact details are TBD, but the following options are on the table:

  • server mod (Apache, nginx)
  • python library
  • django middleware

Discussion

We want to support two regimes:

  • all locale contents together are small compared to the app
    • -> load all locales in one blob?
  • all locales are too bloated
    • -> load manifest, and just locales that are in the fallback chain, for the selected locale

Status

Pike
gandalf
stas

See also