473,594 Members | 2,713 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

I18N: tool for managing XSL variables in different languages?

Greetings,

I'm developing an application that supports multiple languages. In my
XSL I use variables to place the text where it belongs to. At the top of
the document I include those variables - the included file depends on
the language.

Atm I'm editing those file manually. Luckily atm it's only two languages
I have to work with, but even in this case I forget to add a variable
that I added in the other file, forget to use entities .. and so on.

It would be fine to have a tool, that manages the variables, ensures
that I enter text for every defined language, and maybe even saves those
variables in a file for every language.

Do you know of some tool I could use for that?

Thx for you answers,

Sebastian
Jul 20 '05 #1
8 2351
Sebastian Kerekes wrote:
Greetings,

I'm developing an application that supports multiple languages. In my
XSL I use variables to place the text where it belongs to. At the top
of the document I include those variables - the included file depends
on the language.

Atm I'm editing those file manually. Luckily atm it's only two
languages I have to work with, but even in this case I forget to add
a variable that I added in the other file, forget to use entities ..
and so on.

It would be fine to have a tool, that manages the variables, ensures
that I enter text for every defined language, and maybe even saves
those variables in a file for every language.

Do you know of some tool I could use for that?


Define all the variables in an external XSLT file and then include it. You
will need a separate file for each language; you include only the one you
need.

Berislav

--
If the Internet is a Marx Brothers movie, and Web, e-mail, and IRC are
Groucho, Chico, and Harpo, then Usenet is Zeppo.
Jul 20 '05 #2
Berislav Lopac wrote:
Define all the variables in an external XSLT file and then include it. You
will need a separate file for each language; you include only the one you
need.

Berislav


Thx for your answer, but maybe I didn't make myself clear: I'm already
doing it as you suggested. What I'm looking for is a tool which can help
me editing these files and keep the consistency. Editing the files
manually for every language causes errors ..

Angus
Jul 20 '05 #3
Sebastian Kerekes wrote:
Angus


Oops .. i ment Sebastian ;)
Jul 20 '05 #4
Hi,

Using variables and including them? That seems a long way to do things?

Show a short example of what you are doing - perhaps there's a better way of
achieving your goal. ;)

To your original question...
You could use XSLT itself to perform the checks to ensure that a word is
defined in each language.

Cheers
Marrow
http://www.marrowsoft.com - home of Xselerator (XSLT IDE and debugger)
http://www.topxml.com/Xselerator

"Sebastian Kerekes" <se************ ***@gmx.net> wrote in message
news:10******** *******@newsmas ter-03.atnet.at...
Berislav Lopac wrote:
Define all the variables in an external XSLT file and then include it. You will need a separate file for each language; you include only the one you need.

Berislav


Thx for your answer, but maybe I didn't make myself clear: I'm already
doing it as you suggested. What I'm looking for is a tool which can help
me editing these files and keep the consistency. Editing the files
manually for every language causes errors ..

Angus

Jul 20 '05 #5
On Wed, 01 Sep 2004 13:28:48 +0200, Sebastian Kerekes
<se************ ***@gmx.net> wrote:
I'm developing an application that supports multiple languages. In my
XSL I use variables to place the text where it belongs to. At the top of
the document I include those variables - the included file depends on
the language.

Atm I'm editing those file manually. Luckily atm it's only two languages
I have to work with, but even in this case I forget to add a variable
that I added in the other file, forget to use entities .. and so on.

It would be fine to have a tool, that manages the variables, ensures
that I enter text for every defined language, and maybe even saves those
variables in a file for every language.

Do you know of some tool I could use for that?

Thx for you answers,


Hi Sebastian,

by accident I stumbled yesterday across the following site:
http://www-106.ibm.com/developerwork...ary/x-localis/

There they talk about XML Localisation Interchange File Format
(XLIFF). There's also a screenshot of an XLIFF-editor. Maybe
you could use this standard in your application.

HTH,
Gerald
--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Jul 20 '05 #6
Marrow wrote:
Hi,

Using variables and including them? That seems a long way to do things?

Show a short example of what you are doing - perhaps there's a better way of
achieving your goal. ;)
Ok, here's a very simple and short example:

Somewhere at the top of the document i have my variables. The variables
need to have different content depending on the language I want to use.
So my XSL is a JSP file that gets a "language" parameter and includes
the file with the right language.

When the JSP finishes processing, the result is a XSL with for the
specific language passed with "language". For "en" the result is:
<xsl:variable name="text.gree tings" select="'Userna me'" />
<b><xsl:value-of select="$text.g reetings" /></b>

for "de" it's:

<xsl:variable name="text.gree tings" select="'Benutz ername'" />
<b><xsl:value-of select="$text.g reetings" /></b>

and so on.

I found this approach in a book, and it seems ok to me, but if you have
any other (more common, more elegant) solutions, feel free to post them ;)
To your original question...
You could use XSLT itself to perform the checks to ensure that a word is
defined in each language.


Uuuhm .. how? How would you solve this?

Greetings, Sebastian
Jul 20 '05 #7


for "de" it's:

<xsl:variable name="text.gree tings" select="'Benutz ername'" />
<b><xsl:value-of select="$text.g reetings" /></b>

that means you have to modify the XSL for each language, and can't
easily be extended to support more than one language at a time (eg the
current language from an xml:lang attribute in the source file)

If instead your language config file was more like

<text name="greetings ">
<x lang="en">Greet ings</x>
<x lang="de">Benut zername</x>
</text>
....

then instead of going
<xsl:value-of select="$text.g reetings" />
you'd go

<xsl:value-of select="$lang-config/text[@name='greeting s']/x[@lang='de']" />

here you can eaily replace 'de' by for example
ancestor-or-self::*[@xml:lang][1]/@xml:lang
which gets the in scope xml:lang attribute, or have some xsl code to
provide a fall back or warning message if the language specific text is
absent.

David
Jul 20 '05 #8
Hi Sebastian,

First off, there are a few features in XML and XSLT that can assist you with
localization, e.g...

In XML there is a pre-defined attribute of xml:lang which can contain
language (and optionally, national dialect) values. The useful thing about
utilising the xml:lang rather than defining your own 'lang' attribute is
that the xml:lang is decended down the tree for you until it is overridden.
In XSLT you have the lang() function - which can be used to query/test XML
based upon it's xml:lang attribute. The lang() function also gives you a
certain amount of fallback functionality (see below) and also is one of the
few parts of XML that is not case-sensitive.

So given those features there are several ways in which you can go about
providing a localization system for use in XSLT.

As an example...

Say you had a single vocabulary XML document that defined all of your
'tokenized' words, e.g. something like...

== Vocabulary.xml =============== =============== =
<?xml version="1.0"?>
<vocab xml:lang="EN-GB"> <!-- this lang gives the default/fallback
language -->
<language name="English (GB)">
<token name="bin">Dust bin</token>
<token name="trousers" >Trousers</token>
<token name="errtest"> Something</token>
</language>
<language name="English (US)" xml:lang="en-us">
<token name="bin">Tras h can</token>
<token name="trousers" >Pants</token>
</language>
<language name="Deutsch" xml:lang="de">
<token name="bin">Müll eimer</token>
<token name="trousers" >Hose</token>
</language>
</vocab>
== end of Vocabulary.xml =============== =========

using the lang() function in XSLT if you did used the XPath selection...
/vocab/language/token[@name = 'bin'][lang('en')]
it would give you the nodes...
<token name="bin">Dust bin</token>
<token name="bin">Tras h can</token>
because both are defined under an element whose xml:lang is "en" (i.e.
"en-gb" and "en-us").
So if you do a more specific selection of...
/vocab/language/token[@name = 'bin'][lang('en-gb')]
this would give just the node...
<token name="bin">Dust bin</token>

So utilising that in XSLT could look something like...
== TestVocab.xsl =============== =============== =
<?xml version="1.0"?>
<xsl:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
<xsl:param name="lang-select" select="'en'"/>

<xsl:output method="text"/>
<!-- get the vocabulary document -->
<xsl:variable name="vocab-doc" select="documen t('Vocabulary.x ml')/*"/>
<!-- pick the token words from the vocab document according to the selected
language -->
<!-- also providing fallback when the selected language does not exist -->
<xsl:variable name="vocab"
select="$vocab-doc/language[lang($lang-select)]/token |

$vocab-doc/language[lang(/vocab/@default-lang)][not(/vocab/language[lang($la
ng-select)])][1]/token"/>

<xsl:template match="/">
<xsl:value-of select="$vocab[@name = 'bin']"/>
</xsl:template>
</xsl:stylesheet>
== end of TestVocab.xsl =============== =========

NB. Selecting the approriate tokens into the $vocab variable once saves you
keep specifying the language in later XPath expressions.

Also, some people like to keep each language in a seperate XML document - in
which case you could use system entities to accomplish this and still only
refer to one document() in your XSLT, e.g.

== Vocabulary.xml =============== =============== =
<?xml version="1.0"?>
<!DOCTYPE includes [
<!ENTITY en-gb SYSTEM "VocabEN-GB.xml">
<!ENTITY en-us SYSTEM "VocabEN-US.xml">
<!ENTITY de SYSTEM "VocabDE.xm l">
]>
<vocab xml:lang="EN-GB"> <!-- this lang gives the default/fallback
language -->
&en-gb;
&en-us;
&de;
</vocab>
== end of Vocabulary.xml =============== =========

and the the individual language XML documents...

== VocabEN-GB.xml =============== =============== =
<language name="English (GB)" xml:lang="en-gb">
<token name="bin">Dust bin</token>
<token name="trousers" >Trousers</token>
<token name="errtest"> Something</token>
</language>
== end of VocabEN-GB.xml =============== =========

== VocabEN-US.xml =============== =============== =
<language name="English (US)" xml:lang="en-us">
<token name="bin">Tras h can</token>
<token name="trousers" >Pants</token>
</language>
== end of VocabEN-US.xml =============== =========

== VocabDE.xml =============== =============== =
<language name="Deutsch" xml:lang="de">
<token name="bin">Müll eimer</token>
<token name="trousers" >Hose</token>
</language>
== end of VocabDE.xml =============== =========
Using such a system it would then be fairly 'easy' to write a stylesheet
that
checked the existence of each token in the languages, e.g.

== CheckVocab.xsl =============== =============== =
<?xml version="1.0"?>
<xsl:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes"/>

<xsl:variable name="vocab" select="/vocab/language[lang('invalid')]/token |

/vocab/language[lang(/vocab/@xml:lang)][not(/vocab/language[lang('invalid')]
)][1]/token"/>

<xsl:key name="kXMLLangA tts" match="@xml:lan g" use="'x'"/>
<xsl:key name="kDistinct Languages" match="@xml:lan g"
use="translate( substring(.,1,2 ),'ABCDEFGHIJKL MNOPQRSTUVWXYZ' ,'abcdefghijklm n
opqrstuvwxyz')"/>
<xsl:key name="kDistinct LangDialect" match="@xml:lan g"
use="translate( .,'ABCDEFGHIJKL MNOPQRSTUVWXYZ' ,'abcdefghijklm nopqrstuvwxyz') "
/>
<xsl:key name="kDistinct Tokens" match="token" use="@name"/>
<xsl:variable name="ucase" select="'ABCDEF GHIJKLMNOPQRSTU VWXYZ'"/>
<xsl:variable name="lcase" select="'abcdef ghijklmnopqrstu vwxyz'"/>

<xsl:variable name="vDistinct Languages"
select="key('kX MLLangAtts','x' )[generate-id() =
generate-id(key('kDistin ctLanguages',tr anslate(substri ng(.,1,2),$ucas e,$lcas
e)))]"/>
<xsl:variable name="vDistinct Tokens"
select="/vocab/language/token[generate-id() =
generate-id(key('kDistin ctTokens',@name ))]"/>

<xsl:template match="/">
<html>
<head>
<title>
<xsl:text>My Vocabulary Checks</xsl:text>
</title>
</head>
<body>
<h2>
<xsl:text>Vocab ulary Checks</xsl:text>
</h2>
<hr/>
<table border="1">
<tr>
<th rowspan="2" align="center" valign="bottom" >
<xsl:text>Token </xsl:text>
</th>
<th rowspan="2" align="center" valign="bottom" >
<xsl:text>Defau lt</xsl:text>
<br/>
<xsl:text>Value </xsl:text>
</th>
<xsl:for-each select="$vDisti nctLanguages">
<xsl:variable name="this-lang"
select="transla te(substring(., 1,2),$ucase,$lc ase)"/>
<xsl:variable name="no-dialects"
select="count(k ey('kDistinctLa nguages',$this-lang)[contains(.,'-')][generate
-id() =
generate-id(key('kDistin ctLangDialect', translate(.,$uc ase,$lcase)))])+1"/>
<th align="center" colspan="{$no-dialects}">
<xsl:text>Langu age: </xsl:text>
<xsl:value-of select="$this-lang"/>
</th>
</xsl:for-each>
</tr>
<tr>
<xsl:for-each select="$vDisti nctLanguages">
<xsl:variable name="this-lang"
select="transla te(substring(., 1,2),$ucase,$lc ase)"/>
<th>
<xsl:value-of select="$this-lang"/>
</th>
<xsl:variable name="dialects"
select="key('kD istinctLanguage s',$this-lang)[contains(.,'-')][generate-id()
= generate-id(key('kDistin ctLangDialect', translate(.,$uc ase,$lcase)))]"/>
<xsl:for-each select="$dialec ts">
<th>
<xsl:value-of select="transla te(.,$ucase,$lc ase)"/>
</th>
</xsl:for-each>
</xsl:for-each>
</tr>
<xsl:for-each select="$vDisti nctTokens">
<xsl:sort/>
<tr>
<th align="left">
<xsl:value-of select="@name"/>
</th>
<td>
<xsl:value-of select="$vocab[@name = current()/@name]"/>
</td>
<xsl:variable name="this-name" select="@name"/>
<xsl:for-each select="$vDisti nctLanguages">
<xsl:variable name="this-lang"
select="transla te(substring(., 1,2),$ucase,$lc ase)"/>
<xsl:variable name="dialects"
select="key('kD istinctLanguage s',$this-lang)[contains(.,'-')][generate-id()
= generate-id(key('kDistin ctLangDialect', translate(.,$uc ase,$lcase)))]"/>
<td>
<xsl:variable name="this-token"
select="/vocab/language[lang($this-lang)]/token[@name = $this-name]"/>
<xsl:choose>
<xsl:when test="$this-token">
<xsl:value-of select="$this-token"/>
</xsl:when>
<xsl:otherwis e>
<xsl:attribut e name="bgcolor">
<xsl:text>Red </xsl:text>
</xsl:attribute>
<xsl:text>(unde fined)</xsl:text>
</xsl:otherwise>
</xsl:choose>
</td>
<xsl:for-each select="$dialec ts">
<td>
<xsl:variable name="this-token"
select="/vocab/language[lang(current())]/token[@name = $this-name]"/>
<xsl:choose>
<xsl:when test="$this-token">
<xsl:value-of select="$this-token"/>
</xsl:when>
<xsl:otherwis e>
<xsl:attribut e name="bgcolor">
<xsl:text>Red </xsl:text>
</xsl:attribute>
<xsl:text>(unde fined)</xsl:text>
</xsl:otherwise>
</xsl:choose>
</td>
</xsl:for-each>
</xsl:for-each>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
== end of CheckVocab.xsl =============== =========
HTH
Marrow
http://www.marrowsoft.com - home of Xselerator (XSLT IDE and debugger)
http://www.topxml.com/Xselerator
"Sebastian Kerekes" <se************ ***@gmx.net> wrote in message
news:10******** *******@newsmas ter-03.atnet.at...
Marrow wrote:
Hi,

Using variables and including them? That seems a long way to do things?

Show a short example of what you are doing - perhaps there's a better way of achieving your goal. ;)


Ok, here's a very simple and short example:

Somewhere at the top of the document i have my variables. The variables
need to have different content depending on the language I want to use.
So my XSL is a JSP file that gets a "language" parameter and includes
the file with the right language.

When the JSP finishes processing, the result is a XSL with for the
specific language passed with "language". For "en" the result is:
<xsl:variable name="text.gree tings" select="'Userna me'" />
<b><xsl:value-of select="$text.g reetings" /></b>

for "de" it's:

<xsl:variable name="text.gree tings" select="'Benutz ername'" />
<b><xsl:value-of select="$text.g reetings" /></b>

and so on.

I found this approach in a book, and it seems ok to me, but if you have
any other (more common, more elegant) solutions, feel free to post them ;)
> To your original question...
> You could use XSLT itself to perform the checks to ensure that a word is > defined in each language.


Uuuhm .. how? How would you solve this?

Greetings, Sebastian

Jul 20 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
3015
by: vincent_delft | last post by:
I'm looking for a Web Tool kit to build web pages with the following criteria (in priority order) : - easy to use, develop (reuseability of code, ...) - flexible (ideally should run with Python CGIHTTPServer and/or with Apache (with or wihout mod_python) - possibility to have load balancing and/or caching (for very high loaded web pages) I've founded lot of tools ...
181
8742
by: Tom Anderson | last post by:
Comrades, During our current discussion of the fate of functional constructs in python, someone brought up Guido's bull on the matter: http://www.artima.com/weblogs/viewpost.jsp?thread=98196 He says he's going to dispose of map, filter, reduce and lambda. He's going to give us product, any and all, though, which is nice of him.
10
2975
by: Albretch | last post by:
.. Can you define the Character Set for particular tables instead of databases? . Which DBMSs would let you do that? . How do you store in a DBMS i18n'ed users' from input, coming over the web (basically from everywhere) store it and properly serve it back to users, . . .? . Can you point me to info on this? I would preferably use Java/JDBC drivers.
0
1252
by: Laszlo Zsolt Nagy | last post by:
Hello, I wonder if there is a standard for making i18n in Python projects. I have several Python projects that are internationalized. I also have Python packages with i18n. But it is still not clean to me what is the recommended way to do it. Currently, I use a module called 'localization.py' with this code: from i18n_domain import DOMAIN import gettext
3
1625
by: Darren Davison | last post by:
Hi, I have a documentation tool based on Java and XSLT that I want to add i18n capability to. There are around 8 stylesheets that process a Source generated by the Java code and some of the static labels across the stylesheets are the same. Ideally I'd like to import a set of variables into each template, and preferably based on an XSLT parameter (the locale) but this obviously doesn't work:
3
1618
by: fyleow | last post by:
I just spent hours trying to figure out why even after I set my SQL table attributes to UTF-8 only garbage kept adding into the database. Apparently you need to execute "SET NAMES 'utf8'" before inserting into the tables. Does anyone have experience working with other languages using Django or Turbogears? I just need to be able to retrieve and enter text to the database from my page without it being mangled. I know these frameworks...
0
1798
by: GreggTB | last post by:
I have written two custom providers for our Oracle 9i database...a Membershp provider and a Role provider. I've been testing these over the last few days and they seem to be working well. However, when I try to use the ASP.NET 2.0 Web Site Administration Tool in VS 2005, I get an error when I click on the "Create User" link. On the tool's Provider tab, I _have_ selected to use my custom providers! Also, I do not seem to have a problem...
8
3196
by: CptDondo | last post by:
I have a small, embedded app that uses a webserver to serve up pages showing status, etc. Right now all the pages are hard-coded in English. We need to provide multi-lingual support. All of the pages are PHP generated. Ideally, I'd like for the PHP backend to serve up the language based a) the user's locale, and if that is not set, its own locale.
2
3298
by: Norman Diamond | last post by:
My C# code is I18N'ed by appropriately naming and editing .resx files. At execution time, it works. My C++ code is somewhat I18N'ed. When I put UI code in C++ I use .rc files. When I link to a third party's DLLs I get what they supplied. When I link to Microsoft's CRT and MFC, um... Well anyway, at execution time it seems to be working, except when a third party's DLL has a secret dependency. But what about the installer? A Visual...
0
7876
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8372
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8003
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8234
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5408
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3859
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3897
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2385
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1478
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.