1 and 2 are mostly headaches for localization and build people, and I can't really speak for them. But both numbers 3 and 4 demand extra implementation work.
XUL Coding Style guidelines: submitted for internal review. XUL/XML parser dependency
The proposed XUL Localizability solution (see http://www.mozilla.org/projects/intl/xul-l10n.html for more information.) requires two features from XML parser:The earlier these features, especially (1), get into the tree, the less work we need to convert existing XUL file/stream into localizable format.General entities substitution. The proposal requires all localizable resources to be declared as general entities in a language-specific external DTD. Reference to these entities will be substituted inline during parsing. Location of this DTD will be determined by the combination of system locale and the URI referenced by the SYSTEM identifier in the doctype declaration or entity declaration. A potential solution is that the parser, in encountering the SYSTEM keyword, notifies the application through a callback hook so that locale information can be used to fetch the localized version of DTD. For example, assuming the doctype declaration is this:
<!DOCTYPE xui SYSTEM "http://www.mozilla.org/xul/toolbar.dtd">And the current system locale is "fr", then the parser shall fetch
"http://www.mozilla.org/xul/fr/toolbar.dtd"
for the entity declaration.
To sum up, the XUL localizability dependency on XML parser is
Internal and external general entity support. External DTD support. SYSTEM identifier callback hook.
Description:
Sample XUL: toolbar.xul
Sample DTD: toolbar.dtd
Pros:
Cons:
In the example of a dialog UI, if we used entities and DTDs, we would have to tear down the whole DOM tree and the dialog that sits on top of that, and then rebuild a new DOM tree and dialog. This would be wasteful, since our layout manager is able to resize elements dynamically, so we can "edit" the DOM tree and have the dialogs redraw themselves automatically.
However, we can live with this performance drag since the users might not switch language in runtime that often.
Descriptions:
Sample XUL: toolbar.xul
<xul:toolbar>
Sample property file: property.toolbar
8000: Random content data
8001.img: resource:/res/toolbar/TB_Back.gif
8001: Back to %s
8002.img: resource:/res/toolbar/TB_Forward.gif
8002: Forward
8003.img: resource:/res/toolbar/TB_Wizard.gif
8003: Wizard
Sample resource tags definition
#define RES_TEXT 0x1234
#define RES_IMG 0x1235
To get the text string for a "Back" button's label, we call
gettext(8001, RES_TEXT, "Back to %s")
Pros
Cons
Description: With the marriage of #1 and #2, we can take the advantage of both worlds. The idea is to use text entities for content data to remedy the awkwardness of the #2 approach in dealing with content data.
Pros:
Cons:
Description: Assuming the "timely access" problem can be overcome, we could get around the "syntax constraint" problem by using an entity-like syntax of our own. That is, we invent something, say we use the "@" symbol like entities use the "&". Then these things are used throughout the content just like entities would have been used to do localization. This still assumes we have some way to get at the language-specific-substitution text after parsing (so it can't be a parser directive; it may have to be some sort of special element that XUL will recognize and not display). If all this worked, we'd be free to stick in localizable text anywhere without constraining the element and attribute structure. The above example
<element l10nID="100" text="english version"/>
becomes
<element text="@100;"/> ( or <element>@100;</element>, if that's more appropriate for the widget).
There just needs to be a single routine somewhere central that knows where to find the table of localized text strings. It finds "@.*;" sequences and substitutes them. We have to walk the content model after parsing and hand every string to this routine, and widgets have to pass all their text strings through it before they do anything with them.
Cons:
Abstract:
Use XLink & Xpointer to specifically referance text in a file that
is seperate from the base XUL file so that this text can be easily localised
and display this text to the end user in manner consistent with XPFE requirements.
Pros:
Since it is all written in vanilla XML there is no need to create custom
file types and this system can accept anything the parser can handle. It
maintains the name value paring essential for localisation. It allows us
to add localisation and developer notes to the object (e.g. button) and
the localised text separately but maintain a direct link between the two.
The text is pulled into the UI elements when the XUL file is parsed. This
also addressed the goal of separating markup, style and content.
Cons:
This does not leave us with a flat file solution. However the file
containing the text to be localised is of such a simple format that writing
a tool to parse it is a trivial exercise. We are going need some form of
tool to convert native encoding to unicode character references.
There are 4 files to track! Actually the language specific DTD is complete
and valid as is so it could easily be declared inline in the language specific
XML file. The link-attributes has been entitised and could conceivably
be inherited from a higher level DTD.
In reloading downloadble chrome, not all related files can be
blown away by the client.
Here is an example syntax needed for a button UI element.
|
|
|
|
<button href="&locale/uilang.xml| id(1234).child(text)"> <content-info> Put comments on button functionality here </content-info> other xul markup
|
<!ENTITY % link-attributes
"xlink:form CDATA #FIXED 'simple' href CDATA #REQUIRED content-info CDATA #IMPLIED show CDATA #FIXED 'embed' actuate CDATA #FIXED 'auto'" > <!ELEMENT button (#PCDATA)>
|
| UILANG.XML | UILANG.DTD |
| <loctext id = "1244">
<text> Gallia est omnis divisa in partes tres, quarum unam incolunt Belgae, aliam Aquitani, tertiam qui ipsorum lingua Celtae, nostra Galli appellantur. </text> <note>These are Ceasars first words on Gaul. This button soulld be centered on column 1 of the dialog </note> |
<!ELEMENT loctext (text, note?)>
<!ATTLIST loctext id ID #REQUIRED> <!ELEMENT text (#PCDATA)> <!ELEMENT note (#PCDATA)> |
So, when <button> tag is parsed the "simple" xlink href (which is #REQUIRED) is automatically (actuate = 'auto') embedded (show = 'embed') with the text from the <text> child element of the element with id = 1234 in the file at URI location which is the value of &locale(some more globally set value)/UILANG.XML.
OK so that is probably a bad explaination but I hope the code is clear enough. If you have any questions don't hesitste to flame away.
Daniel.
| Criteria to examine | XUL + Language-specific DTD | XUL + Language-specific property file | Description |
| Simple | ***** | **** Need to define resources tags in widget code and widgetID in XUL file. | Both core development and localization work shall be made easy and less error prone. |
| Leveragible | *** Need a parser to list, identify, and compare resources. | ***** All resources are in property files which are flat and easier for leveraging. | Localization results shall be leveragible from release to release. |
| Consistent | *** Two file formats, DTD and property file, to deal with. | ***** Only one file format, property file. | This scheme that will work across modules instead of within the XUL component only. |
| Standard compliant | ***** | **** (We can extend property file format to have similar syntax to X/MOTIF's application default file.) | Achievable on all platforms including Unix, Windows, Mac, and others. |
| Portable | ***** | ***** | Achievable on all platforms including Unix, Windows, Mac, and others. |
| Extensible | ***** In the same direction as XML. | **** Need to treat content data as the text resource of a label widget. | The adopted solution will be flexible for customization and future extension. |
| Dynamic binding | *** Resources binding mostly appens in XML parser. | ***** Resources binding occurs at the last minute. | Some of the items requiring translation may be dynamic, usually because they require string composition ("Installing item 5 of 10"). |
| Validatible | *** (need a DTD parser) | ***** (right on the scene) | Localizers/translators will be able to validate the localization results. |
| Parsable | *** (DTD file contains XML tags, keywords, and others) | ***** (localizable resources are easily identified) | It should be possible to unambiguously and automatically determine which embedded items contain localizable text, and what items need to be locked. |
| Invisible (Internationalization) | *** (entity defined in external DTD) | **** (developers need to assign an id to each resource; but the generation of the US/EN property file could be done by the XUL parser.) | As much as possible, the standard tools that create US UI should emit files that already localizable, without requiring additional processing. |
| Identifiable | **** (entity names are unique; but we lose them after parsing.) | **** (all resources are identified by the combination of widgetID and resTag; but we must treat content data as the text resource of a label widget) | All resources shall be uniquely identifiable |
| Dynamic Language Switching | *** Need to reload the XUL | **** We can design it to modify localizable attributes only. | Dynamically switch to different language and reflect it to UI. (this does not happen quite often.) |
For example, if we declare the entity as
<!ENTITY JFile SYSTEM "http://www.home.org/l10n-property.xxx" NDATA L10N-PTY>
And, the current locale is "ja". Then, our real URI is
The real location of the language-specific DTD file can be determined in a similar fashion.