Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Browser-side xml/xsl localization ...

From: 20100.is@-----.---
To: NULL
Date: 4/1/2009 5:34:00 AM
On Mar 27, 4:48=A0pm, 20100...@gmail.com wrote:
> On Mar 27, 3:44=A0pm, 20100...@gmail.com wrote:
>
>
>
> > Hello,
>
> > Note that this question applies to Browser-side xml/xsl, evidently
> > this means that the transformation will need to work client-side, on
> > all sorts of browsers, but let's just worry about the two main ones,
> > IE and Firefox to start off with.
>
> > I've been frantically trying to come up with a solution that would
> > provide me with the following functionality:
>
> > a) Multiple localized files, each with a default fall-back (en.xml, en-
> > gb.xml, en-us.xml, es.xml, es-mx.xml, ...)
> > a.1) looking up a token in en-gb if not found, would look it up in
> > en.xml instead, this would allow me to share tokens in en.xml with all
> > "en" languages but override the ones in the more language specific
> > ones.
> > b) Easy access through just using a single line lookup (not through
> > apply-template)
>
> > So far there are a few solutions I've run through, but none of them
> > combine the above functionality
>
> > * Solution 1
> > Link:http://www.altova.com/list/comp.text.xml/200409/msg1000211568.html
> > Defining a custom DTD to
> > Apparently Mozilla doesnt' allow you to load external DTDs (entity/
> > entities) (local and remote) and has been a bug assigned for over 9
> > years now:https://bugzilla.mozilla.org/show_bug.cgi?id=3D22942, This
> > code will only work on IE as IE allows referencing external DTD's
>
> > Verdict: Has the exact functionality I need, but only IE supports this
> > behavior currently, this system supports fall-back when a word is not
> > found
>
> > * Solution 2
> > Link:http://docstore.mik.ua/orelly/xml/jxslt/ch08_06.htm
> > An interesting approach, storing the locale specific content in xsl
> > documents as xsl:variable, this way ofcourse, we could utilize the
> > import mechanic to overwrite any entries in the imported stylesheet,
> > as an imported style sheet has lower precedence than the importing
> > style sheet. The only problem here is that (and pardon me in advance,
> > but I just don't see how) you can't do "dynamic" imports at run-time
>
> > ie: <xsl:import href=3D"en-GB.xsl"/> ... you can't use any variable in
> > the href element, since it's imported at runtime.
>
> > Verdict: Comes close to the functionality required, but not sure how
> > to make this work with parameters.
>
> > * Solution 3
>
> > define the location of both the master subset of strings and the one
> > that we need to override with
>
> > <xsl:variable name=3D"lang" select=3D"/page/@lang"/>
> > <xsl:variable name=3D"slang" select=3D"substring($lang, 1, 2)"/>
> > <xsl:variable name=3D"loc_fallback" select=3D"document(concat('/strings=
/',
> > $lang,'/strings.xml'))"/>
> > <xsl:variable name=3D"loc_current" select=3D"document(concat('/strings/=
',
> > $slang,'/strings.xml'))"/>
>
> > then to look up, utilise the "or" operand to fetch accordingly
>
> > <xsl:value-of select=3D"$loc/strings/str[@id=3D'wallet'] | $loc2/string=
s/
> > str[@id=3D'wallet']" />
>
> > Our strings.xml files would look like this:
> > <?xml version=3D"1.0" encoding=3D"UTF-8"?>
> > =A0 <strs>
> > =A0 =A0<str id=3D"wallet">Wallet</str>
> > =A0 =A0<str id=3D"purse">Purse</str>
> > =A0 =A0<str id=3D"bag">Bag</str>
> > =A0 </strs>
>
> > Verdict: This solution is also rather appealing, if it wasn't for the
> > need to always include the "or" statement to look up when the first
> > lookup fails.
>
> > * Solution 4
> > Link:http://www.wowarmory.com
> > Blizzard's approach to solving this problem is by keeping xml files
> > for each different language with the exact amount of strings in each
> > file. This means, on the web-end, a rather big overhead when it comes
> > to changing from en-US to en-UK (since most of the strings are exactly
> > the same)
>
> > this is the snippet how they reference a file:
> > <xsl:variable name=3D"lang" select=3D"/page/@lang"/>
> > <xsl:variable name=3D"loc" select=3D"document(concat('/strings/',$lang,=
'/
> > strings.xml'))"/>
> > and then to display the information based on a token
> > <xsl:value-of select=3D"$loc/strs/common/str[@id=3D'the-wow-armory']"/>
>
> > Verdict: There is no fall-back option here, when the transformation
> > doesn't find a string, it won't display anything.
>
> > My question is, is there a solution to this specific problem, whilst
> > keeping the xml/xsl transformation on the client-side, in the browser,
> > instead of processing the xml and xsl file server-side.
>
> > I'm at a loss here and any input is deeply appreciated.
>
> > -V.
>
> in Solution 3
>
> <xsl:value-of select=3D"$loc/strings/str[@id=3D'wallet'] | $loc2/strings/
> str[@id=3D'wallet']" />
>
> should be
>
> <xsl:value-of select=3D"$loc_current/strings/str[@id=3D'wallet'] |
> $loc_fallback/strings/
> str[@id=3D'wallet']" />

en.xml:

<?xml version=3D"1.0" encoding=3D"UTF-8"?>
<?xml-stylesheet type=3D"text/xsl" href=3D"en.xsl"?>
<languages name=3D"English" xml:lang=3D"en">
  <language name=3D"English (Unspecified)" xml:lang=3D"en-GB">
    <token name=3D"autumn">Autumn</token>
    <token name=3D"barrister">Barrister</token>
    <token name=3D"biscuit">Biscuit</token>
    <token name=3D"bonnet">Bonnet</token>
    <token name=3D"car">Car</token>
    <token name=3D"caravan">Caravan</token>
    <token name=3D"chemist">Chemist</token>
    <token name=3D"chips">Chips</token>
    <token name=3D"coffin">Coffin</token>
    <token name=3D"condom">Condom</token>
    <token name=3D"crisps">Crisps</token>
    <token name=3D"crossroads">Crossroads</token>
    <token name=3D"cupboard">Cupboard</token>
    <token name=3D"cutlery">Cutlery</token>
    <token name=3D"diversion">Diversion</token>
    <token name=3D"dustbin">Dustbin</token>
    <token name=3D"dustman">Dustman</token>
    <token name=3D"engine">Engine</token>
    <token name=3D"film">Film</token>
    <token name=3D"flat">Flat</token>
    <token name=3D"flyover">Flyover</token>
    <token name=3D"galoshes">Galoshes</token>
    <token name=3D"handbag">Handbag</token>
    <token name=3D"holiday">Holiday</token>
    <token name=3D"jam">Jam</token>
    <token name=3D"jeans">Jeans</token>
    <token name=3D"jug">Jug</token>
    <token name=3D"lift">Lift</token>
    <token name=3D"lorry">Lorry</token>
    <token name=3D"luggage">Luggage</token>
    <token name=3D"mad">Mad</token>
    <token name=3D"maize">Maize</token>
    <token name=3D"maths">Maths</token>
    <token name=3D"motorbike">Motorbike</token>
    <token name=3D"motorway">Motorway</token>
    <token name=3D"motorway">Motorway</token>
    <token name=3D"napkin">Napkin</token>
    <token name=3D"nappy">Nappy</token>
    <token name=3D"pants">Pants</token>
    <token name=3D"pavement">Pavement</token>
    <token name=3D"petrol">Petrol</token>
    <token name=3D"post">Post</token>
    <token name=3D"postbox">Postbox</token>
    <token name=3D"postcode">Postcode</token>
    <token name=3D"postman">Postman</token>
    <token name=3D"pub">Pub</token>
    <token name=3D"puncture">Puncture</token>
    <token name=3D"railway">Railway</token>
    <token name=3D"road surface">Road Surface</token>
    <token name=3D"roundabout">Roundabout</token>
    <token name=3D"rubber">Rubber</token>
  </language>
  <language name=3D"English (United States)" xml:lang=3D"en-US">
    <token name=3D"url.apb.vault">http://www.apbvault.com</token>
    <token name=3D"autumn">Fall</token>
    <token name=3D"barrister">Attorney</token>
    <token name=3D"biscuit">Cookie</token>
    <token name=3D"bonnet">Hood</token>
    <token name=3D"car">Automobile</token>
    <token name=3D"caravan">Trailer</token>
    <token name=3D"chemist">Drugstore</token>
    <token name=3D"chips">French Fries</token>
    <token name=3D"coffin">Casket</token>
    <token name=3D"condom">Rubber</token>
    <token name=3D"crisps">Potato Chips</token>
    <token name=3D"crossroads">Intersection</token>
    <token name=3D"cupboard">Closet</token>
    <token name=3D"cutlery">Silverware</token>
    <token name=3D"diversion">Detour</token>
    <token name=3D"dustbin">Ashcan, Garbage Can, Trashcan</token>
    <token name=3D"dustman">Garbage Collector</token>
    <token name=3D"engine">Motor</token>
    <token name=3D"film">Movie</token>
    <token name=3D"flat">Apartment</token>
    <token name=3D"flyover">Overpass</token>
    <token name=3D"galoshes">Toe Rubbers</token>
    <token name=3D"handbag">Purse</token>
    <token name=3D"holiday">Vacation</token>
    <token name=3D"jam">Jelly</token>
    <token name=3D"jeans">Blue Jeans</token>
    <token name=3D"jug">Pitcher</token>
    <token name=3D"lift">Elevator</token>
    <token name=3D"lorry">Truck</token>
    <token name=3D"luggage">Baggage</token>
    <token name=3D"mad">Crazy</token>
    <token name=3D"maize">Corn</token>
    <token name=3D"maths">Math</token>
    <token name=3D"motorbike">Motorcycle</token>
    <token name=3D"motorway">Freeway, Expressway</token>
    <token name=3D"motorway">Freeway</token>
    <token name=3D"napkin">Napkin</token>
    <token name=3D"nappy">Diaper</token>
    <token name=3D"pants">Shorts</token>
    <token name=3D"pavement">Sidewalk</token>
    <token name=3D"petrol">Gas, Gasoline</token>
    <token name=3D"post">Mail</token>
    <token name=3D"postbox">Mailbox</token>
    <token name=3D"postcode">Zip Code</token>
    <token name=3D"postman">Mailman</token>
    <token name=3D"pub">Bar</token>
    <token name=3D"puncture">Flat</token>
    <token name=3D"railway">Railroad</token>
    <token name=3D"road surface">Pavement</token>
    <token name=3D"roundabout">Traffic Circle</token>
    <token name=3D"rubber">Eraser</token>
  </language>
  <language name=3D"English (Canada)" xml:lang=3D"en-CA">
    <token name=3D"autumn">Autumn/Fall</token>
    <token name=3D"barrister">Lawyer</token>
    <token name=3D"biscuit">Cookie</token>
    <token name=3D"bonnet">Hood</token>
    <token name=3D"car">Car</token>
    <token name=3D"caravan">Trailer</token>
    <token name=3D"chemist">Drugstore</token>
    <token name=3D"chips">French Fries/Chips</token>
    <token name=3D"coffin">Coffin</token>
    <token name=3D"condom">Condom</token>
    <token name=3D"crisps">Potato Chips</token>
    <token name=3D"crossroads">Intersection</token>
    <token name=3D"cupboard">Cupboard</token>
    <token name=3D"cutlery">Cutlery</token>
    <token name=3D"diversion">Diversion, Detour</token>
    <token name=3D"dustbin">Garbage Can, Trash Can</token>
    <token name=3D"dustman">Garbageman</token>
    <token name=3D"engine">Engine</token>
    <token name=3D"film">Movie</token>
    <token name=3D"flat">Apartment</token>
    <token name=3D"flyover">Overpass</token>
    <token name=3D"galoshes">Galoshes</token>
    <token name=3D"handbag">Handbag</token>
    <token name=3D"holiday">Holiday</token>
    <token name=3D"jam">Jam</token>
    <token name=3D"jeans">Jeans</token>
    <token name=3D"jug">Jug</token>
    <token name=3D"lift">Elevator</token>
    <token name=3D"lorry">Truck</token>
    <token name=3D"luggage">Luggage</token>
    <token name=3D"mad">Crazy</token>
    <token name=3D"maize">Corn</token>
    <token name=3D"maths">Math</token>
    <token name=3D"motorbike">Motorbike, Motorcycle</token>
    <token name=3D"motorway">Highway, Thoroughfare</token>
    <token name=3D"motorway">Freeway</token>
    <token name=3D"napkin">Serviette, Table Napkin</token>
    <token name=3D"nappy">Diaper</token>
    <token name=3D"pants">Shorts</token>
    <token name=3D"pavement">Sidewalk, Pavement</token>
    <token name=3D"petrol">Gas, Gasoline</token>
    <token name=3D"post">Mail, Post</token>
    <token name=3D"postbox">Mailbox, Post-Box</token>
    <token name=3D"postcode">Postal Code</token>
    <token name=3D"postman">Mailman, Letter Carrier</token>
    <token name=3D"pub">Bar, Pub</token>
    <token name=3D"puncture">Flat</token>
    <token name=3D"railway">Railway</token>
    <token name=3D"road surface">Road Surface, Asphalt</token>
    <token name=3D"roundabout">Roundabout</token>
    <token name=3D"rubber">Eraser</token>
  </language>
</languages>

en.xsl

<?xml version=3D"1.0"?>
<xsl:stylesheet version=3D"1.0" xmlns:xsl=3D"http://www.w3.org/1999/XSL/
Transform">
  <xsl:output method=3D"html" indent=3D"no"/>
  <xsl:key name=3D"l10n.dict.token.name" match=3D"token" use=3D"@name"/>
  <xsl:template match=3D"/">
    <table border=3D"1">
      <xsl:for-each select=3D"/languages/language/token[generate-id(.)=3D
        generate-id(key('l10n.dict.token.name', @name)[1])]">
        <xsl:sort select=3D"@name"/>
        <xsl:for-each select=3D"key('l10n.dict.token.name', @name)">
          <tr>
            <xsl:if test=3D"position() =3D 1">
              <td valign=3D"center" bgcolor=3D"#999999">
                <xsl:attribute name=3D"rowspan">
                  <xsl:value-of select=3D"count(key
('l10n.dict.token.name', @name))"/>
                </xsl:attribute>
                <b>
                  <xsl:text>Name:</xsl:text><xsl:value-of
select=3D"@name"/>
                </b>
              </td>
            </xsl:if>
            <td align=3D"right">
              <xsl:value-of select=3D"parent::*/@xml:lang"/>
            </td>
            <td align=3D"right">
              <xsl:value-of select=3D"text()"/>
            </td>
          </tr>
        </xsl:for-each>
      </xsl:for-each>
    </table>
  </xsl:template>
</xsl:stylesheet>


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent