Skip to content
fabi1cazenave edited this page Feb 15, 2012 · 8 revisions

How to choose the appropriate locale, and how the l10n resource format should help.

HTML Markup

    <link rel="resource" type="application/l10n" href="data.properties" />

Requested features:

  • we don’t want to specify the locale in the HTML document;
  • we want to be able to add a locale without changing the HTML document;
  • it should work without any web server (e.g. mobile app);
  • the content JS should know which locales are available, and which locale has been selected.

Use Cases

1. With a Web Server

That’s a trivial case: content negotiation ⇒ the web server sends a data.properties file that best matches the browser prefs:

hello=Hello!
hello.accesskey=h
hello.title=click me
sayHello=Hello Mozilla!\nHello, world!

2. Client-side, single file

This can be achieved easily by grouping entities in [lang] sections:

[*]
hello=Hello!
hello.accesskey=h
hello.title=click me
sayHello=Hello Mozilla!\nHello, world!

[fr]
hello=Bonjour !
hello.accesskey=b
hello.title=cliquez-moi !
sayHello=Bonjour Mozilla !\nBonjour, le monde !

[de]
hello=Hallo!
hello.accesskey=h
hello.title=hier clicken
sayHello=Hallo Mozilla!\nHallo, Welt!

3. Client-side, multiple files

A resource file can be used as an index, using @import rules:

[*]
@import url("locales/data.en.properties")

[fr]
@import url("locales/data.fr.properties")

[de]
@import url("locales/data.de.properties")

Resource files can contain @import rules and key/value pairs, e.g. to factorize the most common strings like OK/Cancel in a single file, and reuse this file in all resources.

Clone this wiki locally