Commit 950c60aa authored by gerd's avatar gerd

HTML backend support some I18N features.


git-svn-id: https://godirepo.camlcity.org/svn/app-presentation/trunk@22 50e5f3cf-a9f2-0310-83d8-d11ec64cb5ab
parent a3667388
----------------------------------------------------------------------
Internationalization
----------------------------------------------------------------------
(1) Declaration of available languages:
<languages>de en</languages>
(2) Localization of layouts:
- The @LANG@ variable contains the language suffix.
Example: Using @LANG@ to select a localized image:
<layout name="foo">
<![CDATA[ ... <img src="prefix-@LANG@.png"> ... ]]>
</layout>
- Message catalogs:
First, define the messages:
<msg name="foo" lang="en">To Page Start</msg>
<msh name="foo" lang="de">Zum Seitenanfang</msg>
Refer to messages from layouts:
<layout name="bar">
<![CDATA[ ... <img ... title="@MSG:foo@"> ... ]]>
</layout>
(3) Localization of pages:
- One does the language selection on section and/or paragraph level:
<page id="foo">
<title lang="en">...</title>
<title lang="de">...</title>
<sect1 lang="en">...</sect1>
<sect1 lang="de">...</sect1>
<sect1>
<title lang="en">...</title>
<title lang="de">...</title>
<p lang="en">...</p>
<p lang="de">...</p>
</sect1>
</page>
(4) Cross-language links
<a idref="foo" lang="en">...</a>
(5) Localization of "related" links:
<related idref="foo">The Title of The Book</related>
Generates a language-independent link
<related idref="foo" lang="en">The sun</related>
<related idref="foo" lang="de">Die Sonne</related>
Language-specific related links
----------------------------------------------------------------------
Language Representation in HTML
----------------------------------------------------------------------
- Generate type map files for Apache
- Generate foo.html.LANG instead of foo.html
- All languages are generated by default.
If no <languages> element exists, the whole I18N stuff is disabled.
- Include language code also in the HTML element:
<html lang="en">...</html>
- Hyperlinks: Are always expanded and use foo.html.LANG syntax
......@@ -41,7 +41,18 @@ let parse_document idx tag_map filename =
;;
let convert_to_html no_gifs remove_prefix filename =
let languages_of_doc node =
try
let n =
find_element "languages" node in
Pcre.split n#data
with
Not_found ->
[]
;;
let convert_to_html no_gifs remove_prefix langs filename =
(* read in style definition *)
let idx = (new hash_index :> To_html.shared index) in
let document = parse_document idx To_html.tag_map filename in
......@@ -52,7 +63,13 @@ let convert_to_html no_gifs remove_prefix filename =
ignore(root # extension # enumerate_pictures 1);
let hier = root # extension # collect_hierarchy true idx in
store # set_hierarchy hier;
root # extension # print_pages store idx
let langs' =
if langs = [] then
languages_of_doc root
else
langs
in
root # extension # print_pages langs' store idx
;;
......@@ -82,8 +99,9 @@ let main() =
let remove = ref "" in
let ocamldoc = ref false in
let front_file = ref None in
let langs = ref [] in
let filename = ref None in
let action = ref (fun filename -> convert_to_html !no_gifs !remove filename) in
let action = ref (fun filename -> convert_to_html !no_gifs !remove !langs filename) in
Arg.parse
[ "-nogifs", Arg.Set no_gifs,
" do not invoke THE GIMP to create icons";
......@@ -96,6 +114,8 @@ let main() =
" [Latex:] include the ocamldoc package";
"-front", Arg.String (fun s -> front_file := Some s),
"<file> [Latex:] include this file first";
"-lang", Arg.String (fun s -> langs := !langs @ [s]),
"<ls> Generate only for language suffix <ls>";
]
(fun s ->
match !filename with
......
......@@ -7,9 +7,12 @@
<!ENTITY % p.like "p|ul|picture">
<!ENTITY % text "br|code|c|em|footnote|a|numref|nameref|html|latex">
<!ENTITY % layout "layout|headline-layout">
<!ENTITY % layout "layout|headline-layout|msg">
<!ELEMENT presentation ((%layout;)*,hierarchy,page+)>
<!ELEMENT presentation (languages?,(%layout;)*,hierarchy,page+)>
<!ELEMENT languages (#PCDATA)>
<!-- Contains the list of language suffixes, delimited by whitespace -->
<!ELEMENT layout (#PCDATA)>
<!ATTLIST layout
......@@ -27,6 +30,11 @@
bg-color CDATA #REQUIRED
>
<!ELEMENT msg (#PCDATA)>
<!ATTLIST msg name CDATA #REQUIRED
lang CDATA #REQUIRED
>
<!ELEMENT hierarchy (plevel)>
<!ATTLIST hierarchy
parent-href CDATA #IMPLIED
......@@ -44,81 +52,93 @@
<!ATTLIST related
href CDATA #IMPLIED
idref CDATA #IMPLIED
lang CDATA #IMPLIED
>
<!ELEMENT page (sect1+)>
<!ELEMENT page (title*,sect1+)>
<!ATTLIST page
title CDATA #REQUIRED
title CDATA #IMPLIED
id ID #IMPLIED
file CDATA #IMPLIED
for-latex (yes|no) "yes"
>
<!-- Title:
- The _attribute_ "title" is only meaningful when I18N is disabled
(no <languages/>). This is for backwards compatibility.
- Otherwise, the first matching title element is taken (matching =
has the right language)
-->
<!-- Layout customizable:
"page":
CHILDREN, TITLE, UPURL, UPTITLE, LEVEL, RELATED, FOOTER
CHILDREN, TITLE, UPURL, UPTITLE, LEVEL, RELATED, FOOTER, LANG
"navigator.topurl":
-
"navigator.toptitle":
-
LANG
"navigator.child":
LEVELTITLE, LEVELURL
LEVELTITLE, LEVELURL, LANG
"navigator.current", "navigator.level":
LEVELTITLE, LEVELURL, SUBLEVELS
LEVELTITLE, LEVELURL, SUBLEVELS, LANG
"related.link":
TEXT, HREF
TEXT, HREF, LANG
"related":
LINK
LINK, LANG
-->
<!ELEMENT sect1 (title,(sect2|%p.like;)+)>
<!-- Layout customizable: CHILDREN, TITLE, GIFURL -->
<!ELEMENT sect1 (title*,(sect2|%p.like;)+)>
<!-- Layout customizable: CHILDREN, TITLE, GIFURL, LANG -->
<!ELEMENT sect2 (title,(sect3|%p.like;)+)>
<!-- Layout customizable: CHILDREN, TITLE, GIFURL -->
<!ELEMENT sect2 (title*,(sect3|%p.like;)+)>
<!-- Layout customizable: CHILDREN, TITLE, GIFURL, LANG -->
<!ELEMENT sect3 (title,(%p.like;)+)>
<!-- Layout customizable: CHILDREN, TITLE, GIFURL -->
<!ELEMENT sect3 (title*,(%p.like;)+)>
<!-- Layout customizable: CHILDREN, TITLE, GIFURL, LANG -->
<!ELEMENT title (#PCDATA|br)*>
<!ATTLIST title lang CDATA #IMPLIED>
<!ELEMENT p (#PCDATA|%text;)*>
<!-- Layout customizable: CHILDREN -->
<!-- Layout customizable: CHILDREN, LANG -->
<!ATTLIST p lang CDATA #IMPLIED>
<!ELEMENT br EMPTY>
<!-- Layout customizable -->
<!-- Layout customizable: LANG -->
<!ELEMENT code (#PCDATA)>
<!-- Formatted as a new block -->
<!-- Layout customizable: CHILDREN -->
<!-- Layout customizable: CHILDREN, LANG -->
<!ELEMENT c (#PCDATA)>
<!-- Inline -->
<!-- Layout customizable: CHILDREN -->
<!-- Layout customizable: CHILDREN, LANG -->
<!ELEMENT em (#PCDATA|%text;)*>
<!-- Layout customizable: CHILDREN -->
<!-- Layout customizable: CHILDREN, LANG -->
<!ELEMENT ul (li+)>
<!-- Layout customizable: CHILDREN -->
<!-- Layout customizable: CHILDREN, LANG -->
<!ATTLIST ul lang CDATA #IMPLIED>
<!ELEMENT li (%p.like;)*>
<!-- Layout customizable: CHILDREN -->
<!-- Layout customizable: CHILDREN, LANG -->
<!ELEMENT footnote (#PCDATA|%text;)*>
<!-- Two customizable layouts:
"footnote.text": SYMBOL, TEXTANCHOR, FOOTANCHOR
"footnote.foot": SYMBOL, TEXTANCHOR, FOOTANCHOR, CHILDREN
"footnote.text": SYMBOL, TEXTANCHOR, FOOTANCHOR, LANG
"footnote.foot": SYMBOL, TEXTANCHOR, FOOTANCHOR, CHILDREN, LANG
-->
<!ELEMENT picture EMPTY>
......@@ -127,13 +147,17 @@
id ID #IMPLIED
caption CDATA #REQUIRED
map CDATA #IMPLIED
lang CDATA #IMPLIED
>
<!-- Layout customizable: SRC, ANCHOR, CAPTION, NUMBER, MAP -->
<!-- Layout customizable: SRC, ANCHOR, CAPTION, NUMBER, MAP, LANG -->
<!-- The attribute map is the name of a file containing a client-side
image map. The file consists of lines with three columns, separated
by space: idref shape coords. The generated <MAP><AREA>...</MAP>
sequence is appended to the generated picture.
-->
<!-- I18N problem: It is not possible to have several pictures in different
languages for a single id
-->
<!ELEMENT a (#PCDATA)*>
......@@ -141,6 +165,7 @@
href CDATA #IMPLIED
idref IDREF #IMPLIED
type CDATA "default"
langref CDATA #IMPLIED
>
<!-- Generic hyperlink. Either href or idref must be specified.
The name "a" (anchor) is historical; you cannot define anchors
......@@ -149,6 +174,9 @@
The layout option is called "a.TYPE" where TYPE is the string
given in the "type" attribute. When the href is missing, TYPE
is always "emptyref". The layout has access to vars HREF and CHILDREN.
LANG, too.
The "langref" attribute can be used to do cross-language hyperlinks.
-->
......@@ -160,7 +188,7 @@
(or page).
The layout option is "numref.emptyref" if the href is missing,
but normally "numref.default". Vars HREF and NUMBER.
but normally "numref.default". Vars HREF and NUMBER. LANG, too.
-->
<!ELEMENT nameref EMPTY>
......@@ -172,7 +200,7 @@
For pictures: The caption of the picture.
The layout option is "nameref.emptyref" if the href is missing,
but normally "nameref.default". Vars HREF and TITLE.
but normally "nameref.default". Vars HREF, TITLE, LANG.
-->
<!ELEMENT html (#PCDATA)*>
......
......@@ -3,9 +3,11 @@ all:
cd fulltree_out && make
cd partialtree_out && make
cd fixedmenu_out && make
cd lang_out && make
clean:
cd simple_out && make clean
cd fulltree_out && make clean
cd partialtree_out && make clean
cd fixedmenu_out && make clean
cd lang_out && make clean
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE presentation PUBLIC "-//GERD STOLPMANN//DTD PRESENTATION 1.0//EN" "">
<presentation>
<languages>de en</languages>
<msg name="Contact" lang="de">Kontakt</msg>
<msg name="Contact" lang="en">Contact</msg>
<layout name="indent"><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp;]]></layout>
<layout name="page"><![CDATA[<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<!-- WARNING! This is a generated file, do not edit! -->
<html lang="@LANG@">
<head>
<title>@TITLE@</title>
@PREVLINK@
@NEXTLINK@
</head>
<body bgcolor="#ffffcc"
text="black"
link="#4a708b"
alink="#4a708b"
vlink="#4a708b"
marginwidth="0"
marginheight="0"
style="margin:0px"
>
<table cellpadding="0" bgcolor="#ffffcc">
<tr><td height="20">&nbsp;</td></tr>
<tr>
<td width="10">&nbsp;</td>
<td width="200" valign="top" nowrap>
<font size=2><b>NAVIGATION</b></font><br><br>
<font size=2><a href="@UPURL@">@UPTITLE@</a></font>
<br>
<table border=0 cellpadding=0 cellspacing=0>
@LEVEL@
</table><br><br>
@RELATED@
<br><br><font size=1><a href="/imprint.html">@MSG:Contact@</a>
</td>
<td width="1" valign="top" bgcolor="#2f4f4f">&nbsp;</td>
<td width="10">&nbsp;</td>
<td valign="top">
@CHILDREN@
@FOOTER@
</td>
<td width="10">&nbsp;</td>
</tr>
</table>
</body>
</html>
]]>
</layout>
<layout name="navigator.topurl">/TOPURL</layout>
<layout name="navigator.toptitle">Top</layout>
<layout name="navigator.level"><![CDATA[<tr><td width="20">&nbsp;</td><td><a
href="@LEVELURL@"><font size=2>@LEVELTITLE@</font></a></td></tr>
]]></layout>
<layout name="navigator.current"><![CDATA[<tr><td width="20"><a href="@UPURL@">-&gt;</a></td><td><font color="#8b3626" size=2>@LEVELTITLE@</font></td></tr><tr><td></td><td><table border=0 cellpadding=0 cellspacing=0>@SUBLEVELS@</table></td></tr>
]]></layout>
<layout name="navigator.child"><![CDATA[<tr><td width="20">&nbsp;</td><td><a href="@LEVELURL@"><font size=2>@LEVELTITLE@</font></a></td></tr>
]]></layout>
<layout name="footer"><![CDATA[
<hr align=left noshade=noshade width="30%">
<dl>
@FOOTNOTES@
</dl>
]]></layout>
<!-- ************************************************************ -->
<hierarchy>
<plevel idref="book">
<plevel idref="chapter1">
<plevel idref="ch1sect1"/>
<plevel idref="ch1sect2"/>
</plevel>
<plevel idref="chapter2">
<plevel idref="ch2sect1"/>
<plevel idref="ch2sect2"/>
</plevel>
</plevel>
</hierarchy>
<!-- ************************************************************ -->
<page id="book" file="index.html">
<title lang="en">Book</title>
<title lang="de">Buch</title>
<sect1>
<title lang="en">Book</title>
<title lang="de">Buch</title>
<p>Blah Blah Blah</p>
<ul lang="en">
<li><p><a langref="en">This page in English</a></p></li>
<li><p><a langref="de">This page in German</a></p></li>
</ul>
<ul lang="de">
<li><p><a langref="en">Diese Seite auf Englisch</a></p></li>
<li><p><a langref="de">Diese Seite auf Deutsch</a></p></li>
</ul>
</sect1>
</page>
<!-- ************************************************************ -->
<page id="chapter1">
<title lang="en">Chapter 1</title>
<title lang="de">Kapitel 1</title>
<sect1>
<title lang="en">Chapter 1</title>
<title lang="de">Kapitel 1</title>
<p>Blah Blah Blah</p>
</sect1>
</page>
<!-- ************************************************************ -->
<page id="ch1sect1">
<title lang="en">Chapter 1 Section 1</title>
<title lang="de">Kapitel 1 Abschnitt 1</title>
<sect1>
<title lang="en">Chapter 1 Section 1</title>
<title lang="de">Kapitel 1 Abschnitt 1</title>
<p>Blah Blah Blah</p>
</sect1>
</page>
<!-- ************************************************************ -->
<page id="ch1sect2">
<title lang="en">Chapter 1 Section 2</title>
<title lang="de">Kapitel 1 Abschnitt 2</title>
<sect1>
<title lang="en">Chapter 1 Section 2</title>
<title lang="de">Kapitel 1 Abschnitt 2</title>
<p>Blah Blah Blah</p>
</sect1>
</page>
<!-- ************************************************************ -->
<page id="chapter2">
<title lang="en">Chapter 2</title>
<title lang="de">Kapitel 2</title>
<sect1>
<title lang="en">Chapter 2</title>
<title lang="de">Kapitel 2</title>
<p>Blah Blah Blah</p>
</sect1>
</page>
<!-- ************************************************************ -->
<page id="ch2sect1">
<title lang="en">Chapter 2 Section 1</title>
<title lang="de">Kapitel 2 Abschnitt 1</title>
<sect1>
<title lang="en">Chapter 2 Section 1</title>
<title lang="de">Kapitel 2 Abschnitt 1</title>
<p>Blah Blah Blah</p>
</sect1>
</page>
<!-- ************************************************************ -->
<page id="ch2sect2">
<title lang="en">Chapter 2 Section 2</title>
<title lang="de">Kapitel 2 Abschnitt 2</title>
<sect1>
<title lang="en">Chapter 2 Section 2</title>
<title lang="de">Kapitel 2 Abschnitt 2</title>
<p>Blah Blah Blah</p>
</sect1>
</page>
</presentation>
all:
../../presentation ../lang.xml
clean:
rm -f *.html *.html.* *.var *.gif
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment