how to translate image from xslt by selected language

Apr 27, 2014 at 3:39 AM
hi,
i've tried polyglot and it works smart to render my more level menu name, the most page properties; title, bodytext by diff. language parameter.

just i have one problem to render diff. image in content for diff. language what i set. it still return on page the same image from default language but not from selacted language.

the image is not a page property but from my imageinlist.xslt to get media:

<xsl:output method="xml" omit-xml-declaration="yes"/>

<xsl:param name="currentPage"/>

<xsl:template match="/">

<xsl:variable name="media" select="umbraco.library:GetMedia($currentPage/image_for_list, 0)" />

<xsl:if test="$media">
    <xsl:variable name="url" select="$media/umbracoFile" />
    <xsl:variable name="width" select="$media/umbracoWidth" />
    <xsl:variable name="height" select="$media/umbracoHeight" />
    <img src="{$url}" width="{$width}" height="{$height}" />
</xsl:if>
</xsl:template>

here the "image_for_list" is my page property with type media picker in textpage to get media. how could i now solve $currentPage/image_for_list for multilanguage?

thanks a lot!

Jianchun
Coordinator
Apr 28, 2014 at 7:45 AM
Hi Jianchun,

Thank you for your interest in Polyglot. If, as you mention, you are not using the media picker as a standard property, translated in the translation nodes, perhaps you can make your code work like the code of Polyglot's PropertyTranslation script (https://github.com/dimitrikourk/Polyglot/blob/master/Dimi.Polyglot/UmbracoXsltScripts/PropertyTranslation.xslt) to achieve your expected results. I hope this helps.


Best regards,

Dimitri


Apr 28, 2014 at 10:34 AM
Hi dear Dimitri,

thanks for your reply.

The Problem is not only caused by media picker, we have more xslt files referenced in page template, they are installed by Embedded Content packet: http://our.umbraco.org/projects/backoffice-extensions/embedded-content, to list all list entries on page, example: we have test website:
http://www.melnet.com/sourcing-procurement.aspx?lang=en built with umbraco 6.1.3, on this page we have 7 list items to display with list title, text and image in each item. Default is english, if now I select chinese, then it only translate only Page title, body text, but not this image list from our xslt-file:

...
<xsl:template match="/">
<!-- loop all list items -->
<xsl:for-each select="$currentPage/imageList/data/item">        
    <div class="textbox2">
        <div class="left">
            <h2><xsl:value-of select="title" /></h2>
            <!-- load image -->
            <xsl:variable name="media" select="umbraco.library:GetMedia(image, 0)" />           
            <!-- render image -->
            <xsl:if test="$media">
                <p><xsl:variable name="url" select="$media/umbracoFile" />
                <xsl:variable name="width" select="$media/umbracoWidth" />
                <xsl:variable name="height" select="$media/umbracoHeight" />
                <img src="{$url}" width="{$width}" height="{$height}" /></p>
                <xsl:value-of select="img-text" disable-output-escaping="yes" />
            </xsl:if>
        </div>
        <div class="right">
            <p> <xsl:value-of select="description" disable-output-escaping="yes" /> </p>
        </div>  
    </div>
</xsl:for-each>
</xsl:template>
...

Hier your PropertyTranslation cannot help to translate xslt file, the problem is, how could i solve in xslt the $currentPage/imageList/data/item for multi-Language, here imageList is the page property of textPage with data type "Image List" created by Embedded Content packet. in Data type "Image List" i can define list title, text, image for each list item.

Could you please help me?

Thanks a lot!
  • Jianchun
Coordinator
Apr 28, 2014 at 11:44 AM
Hi Jianchun,

I am afraid that I have not used the Embedded Content package myself. Polyglot will translate standard property types as described in the instructions, but for properties that are inserted using other custom-made functionalities and/or other packages, it may very well be the case that some custom development needs to take place. I am afraid that I have no ready solution for this one. The best suggestion I can made is to use the source code of Polyglot as an example to develop your own scripts as you see fit, depending on what you need. It is all available on-line: https://github.com/dimitrikourk/Polyglot (please select "master" branch if you are using Polyglot 1.6 and not 2.0.

Best regards,

Dimitri


Apr 28, 2014 at 3:34 PM
Hi Deimitri,

I know here is not so easy to get xslt file language-depending solved by polyglot, I just try to solve $currentPage in my xslt from default language to $currentPage from selected language. I see in your PropertyTranslation.xslt:
...
select="umbraco.library:RenderMacroContent($currentPage/*[name() = concat($currentPageTypeAlias, '_TranslationFolder')]/
                *[name() = concat($currentPageTypeAlias, '_Translation') and language = $langISO]/
                  * [name() = $Property and not(@isDoc)], $currentPage/*[name() = concat($currentPageTypeAlias, '_TranslationFolder')]/
                      *[name() = concat($currentPageTypeAlias, '_Translation') and language = $langISO]/@id)"
...

Is that way to get currentpage by selected language from its currentpage by default language?

for example, the ID of node from default language is 1448, name "contact", its nodeID from selected langauge is 1658, name "zh", how is relation between both?

thanks!

-Jianchun
Coordinator
Apr 28, 2014 at 7:27 PM
Hi Jianchun,

In that case, I suppose the node will have a subnode called "contact_TranslationFolder" which will contain a node called "zh". So:

contact -> contact_TranslationFolder -> zh

So you probably need something like

$currentPage/*[name()="contact_TranslationFolder"]/*[name()="zh"]

or something more generic like the code you have pasted from Polyglot. Have a look into the App_Data/umbraco.config file of your website to see exactly how the xml is structured, in case I am missing something.

Best regards,

Dimitri






Apr 30, 2014 at 7:37 AM
Morning Dimitri,

I have tried to change my xslt suit for polyglot:
..
<xsl:output method="xml" omit-xml-declaration="yes"/>

<xsl:include href="../xslt/LanguageParameter.xslt" />
<xsl:param name="currentPage"/>

<xsl:template match="/">
<xsl:param name="Property" select="macro/Property" />
<xsl:variable name="currentPageTypeAlias" select="name($currentPage)" />

<xsl:output method="xml" omit-xml-declaration="yes"/>

<xsl:include href="../xslt/LanguageParameter.xslt" />
<xsl:param name="currentPage"/>

<xsl:template match="/">
<xsl:param name="Property" select="macro/Property" />
<xsl:variable name="currentPageTypeAlias" select="name($currentPage)" />
<!-- loop all list items -->
<xsl:for-each select="$currentPage/*[name() = concat($currentPageTypeAlias, '_TranslationFolder')]/
    *[name() = concat($currentPageTypeAlias, '_Translation') and language = $langISO]/imageList/data/item">
    <div class="textbox2">
        <div class="left">
            <h2><xsl:value-of select="title" /></h2>
            <!-- load image -->
            <xsl:variable name="media" select="umbraco.library:GetMedia(image, 0)" />           
            <!-- render image -->
            <xsl:if test="$media">
                <p><xsl:variable name="url" select="$media/umbracoFile" />
                <xsl:variable name="width" select="$media/umbracoWidth" />
                <xsl:variable name="height" select="$media/umbracoHeight" />
                <img src="{$url}" width="{$width}" height="{$height}" /></p>
                <xsl:value-of select="img-text" disable-output-escaping="yes" />
            </xsl:if>
        </div>
        <div class="right">
            <p> <xsl:value-of select="description" disable-output-escaping="yes" /> </p>
        </div>  
    </div>
</xsl:for-each>
</xsl:template>
...
Here i have only one change: <xsl:for-each select="$currentPage/*[name() = concat($currentPageTypeAlias, '_TranslationFolder')]/
    *[name() = concat($currentPageTypeAlias, '_Translation') and language = $langISO]/imageList/data/item">
instead of <xsl:for-each select="$currentPage/imageList/data/item">, and it return me also no xslt.error, but then on website "http://www.melnet.com/contact.aspx?lang=zh" for "Contact" the whole image list doesn't disply also for all languages.

All templates based on single document type "textpage", and according to Polyglot with textpage_Translation, textpage_TranslationFolder which works to translate Menu title, alle page properties just not for this xslt file with image list.

The question is, have I corretly implemented $currentPage for polyglot?

many thanks for your helps!
  • Jianchun
Coordinator
May 1, 2014 at 5:06 AM
Hi Jianchun,

This looks pretty good to me. I am not sure what can be wrong. If no error is returned, this probably means that your script is syntactically correct but the conditions you have set do not get fulfilled by the existing document type structure and / or data. To find out, try looking carefully through your umbraco.config file to make sure your queries match the structure of the xml file, especially for the imageList. If you still cannot find out what is wrong, try outputting each of your variables and data retrieved by the script, to see at which point the data found (or not found :) ) is not what was expected.

Best regards,

Dimitri


May 2, 2014 at 7:36 AM
Morning Dimitri,

many thanks for your Suggestion, now i get $currentPage for multi-language based on polyglot:

<xsl:include href="../xslt/LanguageParameter.xslt" />
<xsl:param name="currentPage"/>

<xsl:template match="/">
<xsl:variable name="currentPageTypeAlias" select="name($currentPage)" />
<xsl:choose>
<xsl:when test="$currentPage/*[name() = concat($currentPageTypeAlias, '_TranslationFolder')]/
                *[name() = concat($currentPageTypeAlias, '_Translation') and language = $langISO] != '' and
                string-length($currentPage/*[name() = concat($currentPageTypeAlias, '_TranslationFolder')]/
                *[name() = concat($currentPageTypeAlias, '_Translation') and language = $langISO]) != 0">
<xsl:variable name="myPage" select="$currentPage/*[name() = concat($currentPageTypeAlias, '_TranslationFolder')]/
                *[name() = concat($currentPageTypeAlias, '_Translation') and language = $langISO]" />  
  <xsl:for-each select="$myPage/imageList/data/item">
                    .... <!-- run my business routine for image list for selected language-->
  </xsl:for-each>
</xsl:when>
<xsl:otherwise>
    <xsl:for-each select="$currentPage/imageList/data/item">
        .... <!-- same routine for image list for default english -->
    </xsl:for-each>
</xsl:otherwise>
</xsl:choose>

</xsl:template>

and it works fine to get translated data deep in image list by selected language. Just one small problem, at first i want to set variable "myPage" in choose for both selected and default language, like:

<xsl:variable name="myPage">
<xsl:choose>
  <xsl:when test="$currentPage/*[name() = concat($currentPageTypeAlias, '_TranslationFolder')]/
                *[name() = concat($currentPageTypeAlias, '_Translation') and language = $langISO] != '' and
              string-length($currentPage/*[name() = concat($currentPageTypeAlias, '_TranslationFolder')]/
                *[name() = concat($currentPageTypeAlias, '_Translation') and language = $langISO]) != 0">
    <xsl:value-of select="$currentPage/*[name() = concat($currentPageTypeAlias, '_TranslationFolder')]/
                *[name() = concat($currentPageTypeAlias, '_Translation') and language = $langISO]" />
  </xsl:when>
  <xsl:otherwise>
      <xsl:value-of select="$currentPage" />
  </xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:for-each select="$myPage/imageList/data/item">
  .... <!-- run my business routine for image list for all languages-->
</xsl:for-each>

But xslt told me error: "To use a result tree fragment in a path expression, first convert it to a node-set using the msxsl:node-set() function", so i put my variable in msxml:node-set($myPage)/imageList/data/item, then no xslt error but no image list displayed on website for all language. As solution I put no variable, but my routine for image list seperate in both case like above.

We have more self-implemented macros based on xslt files like auto. get site in pdf-file for jobs in career, get diff. header-image user-defined in content for diff. page, ... I think this one could be my generic solution for all xslt-files which beginns with $currentPage.

Thanks a lot and appreciate very much for your support!

-- Jianchun
Coordinator
May 3, 2014 at 5:24 AM
You're welcome Jianchun. I'm happy to hear it works now. I have never encountered this problem. I have come across this thread though:

http://our.umbraco.org/forum/developers/extending-umbraco/4139-To-use-a-result-tree-fragment-in-a-path-expression,-first-convert-it-to-a-node-set-using-the-msxslnode-set%28%29-function

It is a little old but maybe it can help.

Best regards,

Dimitri


May 5, 2014 at 6:27 AM
Hi Dimitri,

Thanks a lot! I've tried all possibilities of this thread but no helps, so I keep my last solution for ImageList.

--Jianchun