180 likes | 297 Views
Localizing XML documents (at source level) using XSLT. Presented by: Yijun Yu yijun@cs.toronto.edu http://cxsl.sourceforge.net. Overview. Motivated by an example Localizing engine: an XSL style sheet XML documents localized HTML, XSL, DocBook, etc. Applications of l10n and i18n
E N D
Localizing XML documents (at source level) using XSLT Presented by: Yijun Yu yijun@cs.toronto.edu http://cxsl.sourceforge.net AI'2003 Software Engineering
Overview • Motivated by an example • Localizing engine: an XSL style sheet • XML documents localized • HTML, XSL, DocBook, etc. • Applications of l10n and i18n • Program source code localization • Document localization • Summary • Future work AI'2003 Software Engineering
Hyper Text Markup Language English tag English words 1.1 An HTML document <html> <head> <title>A HTML document</title> </head> <body> <h1>Hello, world!</h1> </body> </html> AI'2003 Software Engineering
English tags Chinese characters 1.2 Presentation level localization <html> <head> <title>HTML文档</title> </head> <body> <h1>你好,世界!</h1> </body> </html> AI'2003 Software Engineering
1.3 Source level localization • Presentation level localization still requires user’s competence in English to express the HTML tags • Source level localization is feasible, because: • HTML can be represented using XHTML, which is a dialect of XML • XML allows unicode tags and attributes • Given a mapping dictionary, XSLT can transform one set of tags/attributes into another language AI'2003 Software Engineering
SOURCE XML documentin English:XHTMLXSL … TARGETlocalized XML document:CHTMLCXSL… Localize XSLT dictionary HTML CHTML XSL CXSL …… …… 2. The localizing engine AI'2003 Software Engineering
LocalizeXSLT for-each attributecall-template $str AI'2003 Software Engineering
2. (cont) using a dictionary <dictionary> <entry type=“element”> <html>HTML</html> <chtml>超文本标注语言</chtml> </entry> … </dictionary> AI'2003 Software Engineering
3. XML document localized <超文本标注语言> <文本首> <标题>超文本文档</标题> </文本首> <文本体> <标题一>你好,世界!</标题一> </文本体> </超文本标注语言> Chinese tags Chinese characters AI'2003 Software Engineering
Demo 1 • Inversing the source-target namespace, the same localizing XSLT can be regarded as an internationalizing XSLT C:>xsltproc l10n.xsl l10n.xsl> l10n.xml C:>xsltproc i10n.xsl l10n.xml> i18n.xml • The localization (l10n) and internationalization (i18n) at source level instead of presentation level makes the translation thorough AI'2003 Software Engineering
4. Applications • Source code localization • C, Java, Fortran, PL/IX, etc. • Documentation localization • LaTeX, RTF, PDF, Postscript, etc. AI'2003 Software Engineering
4.1 Source code localization Program source code level localization • Given the program grammar in YACC, the program syntax tree can be automatically XMLized into an XML document using YAXX • The localization of the generated XML leads to a localized program after applying another XSLT transformation AI'2003 Software Engineering
A program in L, e.g. C program, or localized C An XML syntax tree A YACC grammar of a language L, e.g. ANSI C, YACC, … Localize XSLT Localized XML syntax tree Parser for L YACC YAXX Code generation XSLT A program in localizedL AI'2003 Software Engineering
Demo 2 (offline) • ANSIC grammar in YACC • An example C program • Syntax XML document and DTD generated by YAXX, in “ansic-dictionary.xml”, the <yaxx> entries can be generated from YAXX too • The localized CYAXX document • The code generation XSLT’s for YAXX and CYAXX outputs identical program because the leaf tokens are the same! One can also choose to localize the text() content. AI'2003 Software Engineering
LocalizeXSLT DocBook LocalizedDocBook DB2LaTeX XSLT DB2CLaTeX XSLT LaTeX CJK LaTeX 4.2 DocBook localization AI'2003 Software Engineering
Demo 3 (offline) • The DocBook version of the paper • Clues for LaTeX users • Tricks of using DocBook to write an article • \usepackage{CJKLatex} for localized Chinese-Japanese-Korean LaTeX users • openjade is a SGML tool that converts DocBook into LaTeX and HTML. It is chosen for the HTML generation of the paper. • db2Latex is a set of XSL stylesheets, they are adapted to use CJKLaTeX with minor changes. AI'2003 Software Engineering
5. Summary • L10n & i18n through an XSLT style sheet • Separate multi-lingual dictionaries from the common automatic XSLT translator • The localization is at the source level instead of at the presentation level • Not only the XML dialects (HTML, XSL, DocBook, etc. ) can be localized, an arbitrary programming language can be as well • Helps not only web-designers, but also programmers and document authors AI'2003 Software Engineering
6. Future work • Future improvements • One-to-many translation selection using context clues • Text2speech markup and translations • Consider natural language translation • We hope someday the Unite Nations will use a similar tool to process multi-lingual speeches and documents AI'2003 Software Engineering