docbook-apps

  • 1.  Custom Localization Support Broken?

    Posted 07-05-2012 08:46
    Hi,

    recently, I've observed some strange behavior for my localization
    customization. Maybe I didn't see my error as I've looked at it too
    long. ;) Or it has something to do with the localization optimization
    in revisions 8719, 8722, 8752, and 8760.

    Ok, I've tried to strip it down to a small test case. Let's begin with
    this small XML file (note the empty keycaps):

    -------------------[ test.xml ]-------------------
    "http://www.docbook.org/xml/4.5/docbookx.dtd">


    <para>This is a <keycap function="escape"/> key.</para>
    <para>This is a <keycap function="alt"/> key.</para>

    --------------------------------------------------

    What I was trying is to use the @function attribute and create a
    localized string. In the above case, it should return "ESC" and "Alt"
    for the two keycaps.

    For this reason, I've created a language mapping in the l:i18n/l:l10n
    elements with the context "keycap". The idea was to extract the
    respective entry from the table through the gentext.template function.

    Here is my customization layer:

    -------------------[ mydb.xsl ]-------------------
    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0"
    exclude-result-prefixes="l">

    <xsl:import
    href="http://docbook.sourceforge.net/release/xsl/current/xhtml/docbook.xsl"/>

    <xsl:param name="local.l10n.xml" select="document('')"/>
    <l:i18n xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0">
    <l:l10n language="en" english-language-name="English">
    <l:context name="keycap">
    <l:template name="alt" text="Alt"/>
    <l:template name="backspace" text="<—"/>

    <l:template name="control" text="Ctrl"/>
    <l:template name="delete" text="Del"/>
    <l:template name="down" text="↓"/>
    <l:template name="end" text="End"/>
    <l:template name="enter" text="Enter"/>
    <l:template name="escape" text="Esc"/>
    <l:template name="home" text="Home"/>
    <l:template name="insert" text="Ins"/>
    <l:template name="left" text="←"/>
    <l:template name="meta" text="Meta"/>

    <l:template name="other" text="???"/>
    <l:template name="pagedown" text="Page ↓"/>
    <l:template name="pageup" text="Page ↑"/>
    <l:template name="right" text="→"/>
    <l:template name="shift" text="Shift"/>
    <l:template name="space" text="Space"/>
    <l:template name="tab" text="→|"/>
    <l:template name="up" text="↑"/>
    </l:context>
    </l:l10n>
    </l:i18n>

    <xsl:template match="keycap">
    <xsl:message>
    <xsl:text>keycap: @function=</xsl:text>
    <xsl:value-of select="@function"/>
    <xsl:text> [</xsl:text>
    <xsl:call-template name="gentext.template">
    <xsl:with-param name="context" select="local-name()"/>
    <xsl:with-param name="name" select="@function"/>
    </xsl:call-template>
    <xsl:text>]</xsl:text>
    </xsl:message>

    </xsl:template>
    </xsl:stylesheet>
    --------------------------------------------------

    After I've transforming the above XML to XHTML, I'm getting this output:

    $ xsltproc --output test.html mydb.xsl test.xml
    keycap: @function=escape []
    keycap: @function=alt []

    Another point to mention:
    The above keycap context is not available in the original en.xml file.
    The interesting thing is, if I include the context in the original file,
    my customization works too.


    Thanks! :-)

    --
    Gruß/Regards,
    Thomas Schraitle



  • 2.  Re: [docbook-apps] Custom Localization Support Broken?

    Posted 07-05-2012 09:41
    On 5.7.2012 10:46, Thomas Schraitle wrote:

    > After I've transforming the above XML to XHTML, I'm getting this output:
    >
    > $ xsltproc --output test.html mydb.xsl test.xml
    > keycap: @function=escape []
    > keycap: @function=alt []
    >
    > Another point to mention:
    > The above keycap context is not available in the original en.xml file.
    > The interesting thing is, if I include the context in the original file,
    > my customization works too.

    Your code looks OK. Could please try to use Saxon6 with your
    customization layer instead of xsltproc? I'm sure code was working when
    I was making this change, so I suspect xsltproc might have some bug in
    key() implementation.

    Jirka

    --
    ------------------------------------------------------------------
    Jirka Kosek e-mail: jirka@kosek.cz http://xmlguru.cz
    ------------------------------------------------------------------
    Professional XML consulting and training services
    DocBook customization, custom XSLT/XSL-FO document processing
    ------------------------------------------------------------------
    OASIS DocBook TC member, W3C Invited Expert, ISO JTC1/SC34 member
    ------------------------------------------------------------------




  • 3.  Re: [docbook-apps] Custom Localization Support Broken?

    Posted 07-05-2012 09:57
    Hi Jirka,

    thanks for your quick answer! :-)

    On Thu, 05 Jul 2012 11:41:15 +0200
    Jirka Kosek <jirka@kosek.cz> wrote:

    > [...]
    >
    > Your code looks OK.

    Thanks for confirming. After looking at such a long time, I wasn't
    sure anymore. ;)


    > Could please try to use Saxon6 with your
    > customization layer instead of xsltproc?

    I've tried it with Saxon, but without success:

    $ saxon -o test.html test.xml mydb.xsl
    keycap: @function=escape []
    keycap: @function=alt []


    > I'm sure code was working
    > when I was making this change, so I suspect xsltproc might have some
    > bug in key() implementation.

    Strange. I use openSUSE 12.1 and here are the versions:

    $ rpm -q saxon libxml2 libxslt1 docbook-xsl-stylesheets
    saxon-6.5.5-229.1.noarch
    libxml2-2.7.8+git20110708-3.5.1.x86_64
    libxslt1-1.1.26-15.3.1.x86_64
    docbook-xsl-stylesheets-1.77.1-11.noarch


    Thanks.


    --
    Gruß/Regards,
    Thomas Schraitle



  • 4.  Re: [docbook-apps] Custom Localization Support Broken?

    Posted 07-05-2012 11:46
    On 5.7.2012 11:57, Thomas Schraitle wrote:

    > thanks for your quick answer! :-)

    OK, I have investigated little bit. There is no bug in stylesheets but
    there is a feature -- local localization can override only existing
    context (it is because in XSLT it's quite inconvenient to switch
    documents on which key() operates). Line 512 in common/l10n.xsl is "guilty":

    <xsl:for-each select="$context.node">

    In your case there is no such content in common/en.xml and code inside
    xsl:for-each is not invoked -- but this code uses also local l10n into
    account.

    The easiest solution would be to reuse existing context, ie. change

    <l:context name="keycap">

    to

    <l:context name="msgset">

    Not nice, but will work.

    Jirka


    --
    ------------------------------------------------------------------
    Jirka Kosek e-mail: jirka@kosek.cz http://xmlguru.cz
    ------------------------------------------------------------------
    Professional XML consulting and training services
    DocBook customization, custom XSLT/XSL-FO document processing
    ------------------------------------------------------------------
    OASIS DocBook TC member, W3C Invited Expert, ISO JTC1/SC34 member
    ------------------------------------------------------------------




  • 5.  Re: [docbook-apps] Custom Localization Support Broken?

    Posted 07-05-2012 12:12
    Hi Jirka,

    On Thu, 05 Jul 2012 13:45:46 +0200
    Jirka Kosek <jirka@kosek.cz> wrote:

    > [...]
    > OK, I have investigated little bit. There is no bug in stylesheets but
    > there is a feature -- local localization can override only existing
    > context (it is because in XSLT it's quite inconvenient to switch
    > documents on which key() operates). Line 512 in common/l10n.xsl is
    > "guilty":
    >
    > <xsl:for-each select="$context.node">

    Ah, I see. I hope, XSLT2 should do better in that regard, right?


    > In your case there is no such content in common/en.xml [...]

    Well, that reminds me: why does the DocBook stylesheets don't support
    the @function attribute?

    I think, it wouldn't be very difficult to add a "keycap" context in the
    language files, extend the keycap template, and output the localized
    string. That would make live for writers and translators much more
    easier. :)


    > The easiest solution would be to reuse existing context, ie. change
    >
    > <l:context name="keycap">
    >
    > to
    >
    > <l:context name="msgset">
    >
    > Not nice, but will work.

    Right, that works! :)

    Thanks Jirka!


    --
    Gruß/Regards,
    Thomas Schraitle



  • 6.  Re: [docbook-apps] Custom Localization Support Broken?

    Posted 07-05-2012 12:26
    On 5.7.2012 14:11, Thomas Schraitle wrote:

    > Well, that reminds me: why does the DocBook stylesheets don't support
    > the @function attribute?

    Hmm, function attribute. Was I aware of it before today? Probably not. :-)

    Please fill RFE ideally accompanied with snippet of your localization file.

    Jirka

    --
    ------------------------------------------------------------------
    Jirka Kosek e-mail: jirka@kosek.cz http://xmlguru.cz
    ------------------------------------------------------------------
    Professional XML consulting and training services
    DocBook customization, custom XSLT/XSL-FO document processing
    ------------------------------------------------------------------
    OASIS DocBook TC member, W3C Invited Expert, ISO JTC1/SC34 member
    ------------------------------------------------------------------




  • 7.  Re: [docbook-apps] Custom Localization Support Broken?

    Posted 07-05-2012 12:59
    Hi Jirka,

    On Thu, 05 Jul 2012 14:26:11 +0200
    Jirka Kosek <jirka@kosek.cz> wrote:

    > > Well, that reminds me: why does the DocBook stylesheets don't
    > > support the @function attribute?
    >
    > Hmm, function attribute. Was I aware of it before today? Probably
    > not. :-)

    :-D


    > Please fill RFE ideally accompanied with snippet of your localization
    > file.

    https://sourceforge.net/tracker/?func=detail&aid=3540451&group_id=21935&atid=373750

    I took the liberty to commit the language file in
    gentext/locale/en.xml already. Of course, it needs to be done for all
    the other languages as well. I can provide German. :)

    If you don't object, I can also update the keycap template.


    --
    Gruß/Regards,
    Thomas Schraitle



  • 8.  Re: [docbook-apps] Custom Localization Support Broken?

    Posted 07-05-2012 14:13
    On 5.7.2012 14:59, Thomas Schraitle wrote:

    > https://sourceforge.net/tracker/?func=detail&aid=3540451&group_id=21935&atid=373750
    >
    > I took the liberty to commit the language file in
    > gentext/locale/en.xml already. Of course, it needs to be done for all
    > the other languages as well. I can provide German. :)
    >
    > If you don't object, I can also update the keycap template.

    Thanks, please go ahead.

    --
    ------------------------------------------------------------------
    Jirka Kosek e-mail: jirka@kosek.cz http://xmlguru.cz
    ------------------------------------------------------------------
    Professional XML consulting and training services
    DocBook customization, custom XSLT/XSL-FO document processing
    ------------------------------------------------------------------
    OASIS DocBook TC member, W3C Invited Expert, ISO JTC1/SC34 member
    ------------------------------------------------------------------




  • 9.  Re: [docbook-apps] Custom Localization Support Broken?

    Posted 07-05-2012 15:01
    Hi,

    On Thu, 05 Jul 2012 16:13:04 +0200
    Jirka Kosek <jirka@kosek.cz> wrote:

    > On 5.7.2012 14:59, Thomas Schraitle wrote:
    >
    > > https://sourceforge.net/tracker/?func=detail&aid=3540451&group_id=21935&atid=373750
    > >
    > > I took the liberty to commit the language file in
    > > gentext/locale/en.xml already. Of course, it needs to be done for
    > > all the other languages as well. I can provide German. :)
    > >
    > > If you don't object, I can also update the keycap template.
    >
    > Thanks, please go ahead.

    Ok, I've fixed it in xsl/fo/inline.xsl xsl/html/inline.xsl (revision
    9469). From my understanding, the XHTML* stylesheets will be
    automatically generated and JavaHelp and HTMLHelp are based on HTML. So
    I haven't changed these.

    There is also manpage/inline.xsl which I haven't touched too. It seems
    there isn't a keycap template so I wasn't sure what was the best
    approach. Before I mess up things, I'll leave it to Michael, maybe he
    can have a look and add a small patch. :)

    The current implementation is this: If @function is set and keycap is
    empty, then the template will use the content from the keycap context,
    otherwise it will use just the given text.

    <keycap>X</keycap> => X
    <keycap function="alt"/> => Alt
    <keycap function="control">Control</keycap> => Control

    Hope that's ok. :) I've tested it in my environment, but it would be
    nice if someone can have a look...


    --
    Gruß/Regards,
    Thomas Schraitle