RFC: String repository and localization for Flash

Posted on Tuesday 4 October 2005

Recently there's been discussion about loading settings files and strings on osFlash. I think it's time we take a look at the issue of localization and come up with a standard way of handling things. I've seen various schemes for handling multi-language movies:

  • The copy-and-paste approach (ie: whenever the site is 'done' in one language, copy the fla and translate; I've even used it for this site)
  • The XML dictionary approach. Here I've encountered various schemes. One I liked was quite simple: a top node and sub-nodes with the name of the node being the key, and the value inside. Another standard one is an element or string node with a key attribute and then the value. The application of the strings is then left to the app.
  • The XML rules approach. Here what we have is not keys and values, but rather movieclips/textfields and values. This requires constant naming discipline but I've seen it work.

All of these are flawed: the copy and paste approach always gives the best results (alignment and overrunning text and whatnot) but it's by far the most time-consuming. The dictionary approach leaves implementation to the Flash movie but it involves writing a lot of code for l10n. The rules approach may store duplicate strings. XML approaches also don't offer the level of control of the copy-and-paste approach.

I believe a right scheme would require the following:

  • An XML dictionary section. A "string" element with a key attribute and the value in the current language would define a dictionary entry.
  • An XML rules section. Based on the dictionary entries, a rules section would allow strings to be directly applied to on-screen elements. Obviously this could only work properly in one-frame movies. The rules could be applied as soon as the dictionary is loaded or deferred in the case fo attached movies. The apply tag would have atributes 'from', 'to', 'align', 'valign' and 'overflow'. 'valign' would allow large text blocks to be aligned to bottom or middle. 'overflow' could be set to 'autosize' to let text become smaller to fit in an insufficient space.
  • A template standard. I'm thinking using either $ or % as the template meta char.
  • Supporting classes to handle all of this, under the namespace org.osflash.translator

So basically an XML file like this:


<scheme>
 <dicts>
  <dict xml:lang="fr">
   <entry key="open">Ouvrir</string>
   <entry key="save">Sauvegarder</string>
   <entry key="close">Fermer</string>
   <entry key="closewarning">Le document $document n'est pas sauvegardé. Fermer?</string>
  </dict>
  <dict xml:lang="en">
   <entry key="open">Open</string>
   <entry key="save">Save</string>
   <entry key="close">Close</string>
   <entry key="closewarning">The document $document is not saved. Close?</string>
  </dict>
 </dicts>
 <rules>
  <set id="start">
   <apply from="open" to="_root.mainForm.btnOpen.label" overflow="autosize" />
   <apply from="save" to="_root.mainForm.btnSave.label" overflow="autosize" />
   <apply from="close" to="_root.mainForm.btnClose.label" overflow="autosize" />
  </set>
 </rules>
</scheme>
 

Then as far as API methods:


load(file:String):Void
applyRuleset(id:String):Void
getString(key:String):String
replaceTokens(src:String, tokensDict:Object):String
static getInstance():Translator
addEventListener()
removeEventListener()
 

And three events: load, timeout and error.

How does that sound? Am I missing something? Any volunteers?


WordPress database error: [Can't open file: 'wp_comments.MYD'. (errno: 145)]
SELECT * FROM wp_comments WHERE comment_post_ID = '155' AND comment_approved = '1' ORDER BY comment_date

No comments have been added to this post yet.

Leave a comment




Your e-mail address is never displayed. If you run into issues with SpamKarma blocking you, email me at $patrick->5etdemi(com)


RSS feed for comments on this post | TrackBack URI