Commit 3653bea4 authored by gerd's avatar gerd

Support for the language selection box (HTML only).


git-svn-id: https://godirepo.camlcity.org/svn/app-presentation/trunk@23 50e5f3cf-a9f2-0310-83d8-d11ec64cb5ab
parent 950c60aa
......@@ -4,7 +4,12 @@ Internationalization
(1) Declaration of available languages:
<languages>de en</languages>
<languages>
<language code="de">Deutsch</language>
<language code="en">English</language>
</languages>
Optional image for every language.
(2) Localization of layouts:
......
......@@ -3,7 +3,8 @@ Intro
----------------------------------------------------------------------
This document describes briefly the configuration options to specify
the layout of the generated HTML pages.
the layout of the generated HTML pages. (Layouts are only available in
the HTML generator, not in the Latex generator.)
In general, the layout string for the document element is taken and
evaluated. The string may contain variables (written @VARNAME@) which
......@@ -19,6 +20,23 @@ texts of the children nodes of <em>.
For many simple elements, the layout options are described in the DTD.
For the syntax @MSG:foo@ see the document I18N.txt.
----------------------------------------------------------------------
Layout as macros
----------------------------------------------------------------------
Layouts are also a simple form of macros.
<layout name="foo">FOO</layout>
<layout name="bar">@foo@ @foo@</layout>
This would expand to "FOO FOO".
By convention, names of custom layouts are all lowercase, whereas the
parameters of the built-in layouts are all uppercase.
----------------------------------------------------------------------
The layout for <page>
----------------------------------------------------------------------
......@@ -50,6 +68,9 @@ The page layout has the following variables:
- NEXTLINK: The LINK element of the next page
- LANGSELECT: The language selector box. See below for how it is
constructed.
----------------------------------------------------------------------
The navigation tree
----------------------------------------------------------------------
......@@ -206,6 +227,27 @@ handled by applying the layout "related.link". They may contain the
variables TEXT, replaced by the name of the link, and HREF, replaced
by the URL.
----------------------------------------------------------------------
The language selection box
----------------------------------------------------------------------
In the layout "page", the variable "LANGSELECT" is substituted by
the language selection box. This box may contain links to view
the current page in different languages. LANGSELECT is only
generated when the <languages> element declares languages.
The layout "langselect" defines the environment for the link list.
It can contain the variable LINK which is substituted by the
concatenated links. The individual links are generated by
applying the layout "langselect.link". Allowed variables:
- CODE: the two-letter language code
- TEXT: The description of the language
- IMGURL: The URL of the optional image (or "")
- HREF: The URL switching the language
- LANG: The current language (two-letter code)
----------------------------------------------------------------------
Footer
----------------------------------------------------------------------
......
......@@ -42,13 +42,11 @@ let parse_document idx tag_map filename =
let languages_of_doc node =
try
let n =
find_element "languages" node in
Pcre.split n#data
with
Not_found ->
[]
let l =
find_all_elements ~deeply:true "language" node in
List.map
(fun n -> n # required_string_attribute "code")
l
;;
......
......@@ -11,8 +11,12 @@
<!ELEMENT presentation (languages?,(%layout;)*,hierarchy,page+)>
<!ELEMENT languages (#PCDATA)>
<!-- Contains the list of language suffixes, delimited by whitespace -->
<!ELEMENT languages (language+)>
<!ELEMENT language (#PCDATA)> <!-- Description of language -->
<!ATTLIST language code CDATA #REQUIRED
image CDATA #IMPLIED
>
<!ELEMENT layout (#PCDATA)>
<!ATTLIST layout
......
......@@ -4,7 +4,10 @@
<presentation>
<languages>de en</languages>
<languages>
<language code="de">Deutsch</language>
<language code="en">English</language>
</languages>
<msg name="Contact" lang="de">Kontakt</msg>
<msg name="Contact" lang="en">Contact</msg>
......@@ -43,6 +46,8 @@
@LEVEL@
</table><br><br>
@RELATED@
<br><br>
@LANGSELECT@
<br><br><font size=1><a href="/imprint.html">@MSG:Contact@</a>
</td>
<td width="1" valign="top" bgcolor="#2f4f4f">&nbsp;</td>
......
......@@ -80,6 +80,12 @@ let run script_name args =
type lang =
[ `Any | `Lang of string ]
type lang_descr =
{ lang_code : string;
lang_description : string;
lang_image : string option;
}
type page_hierarchy =
{ pageid : string;
......@@ -106,8 +112,8 @@ class type footnote_printer =
and store_type =
object
method set_languages : string list -> unit
method languages : string list (* [] when I18N is disabled *)
method set_languages : lang_descr list -> unit
method languages : lang_descr list (* [] when I18N is disabled *)
method alloc_footnote : footnote_printer -> int
method print_footnotes : lang:lang -> unit -> string
method add_msg : lang:lang -> string -> string -> unit
......@@ -180,6 +186,8 @@ Hashtbl.add std_layout_decls "navigator.start" "@SUBLEVELS@";
Hashtbl.add std_layout_decls "navigator.onpath" "@navigator.level@";
Hashtbl.add std_layout_decls "navigator.topurl" "";
Hashtbl.add std_layout_decls "navigator.toptitle" "";
Hashtbl.add std_layout_decls "langselect" "<ul>@LINK@</ul>";
Hashtbl.add std_layout_decls "langselect.link" "<li><a href=\"@HREF@\">@TEXT@</a></li>";
;;
......@@ -633,7 +641,16 @@ class languages =
""
method print_pages langs store idx =
let langs = Pcre.split (self # node # data) in
let langs =
List.map
(fun n ->
assert( n # node_type = T_element "language" );
{ lang_code = n # required_string_attribute "code";
lang_description = n # data;
lang_image = n # optional_string_attribute "image"
}
)
self # node # sub_nodes in
store # set_languages langs
end
......@@ -1010,6 +1027,34 @@ class page =
end else ""
in
let langselect() =
if store # languages <> [] then (
let link() =
map'n'concat
(fun l ->
store # instantiate_layout "langselect.link"
~lang
[ "CODE", lazy l.lang_code;
"TEXT", lazy l.lang_description;
"IMGURL", lazy (match l.lang_image with
| None -> ""
| Some u ->
escape_html (store # url u));
"HREF", (lazy (escape_html
(store # url
(self # url_of_object
(`Lang l.lang_code)))));
]
)
store#languages in
store # instantiate_layout "langselect"
~lang
[ "LINK", lazy (link());
]
)
else ""
in
let prev_url, prev_title =
match store # prev_id id with
None -> ("", "")
......@@ -1095,6 +1140,7 @@ class page =
"LEVEL", lazy (levels());
"NAVIGATION", lazy (levels());
"RELATED", lazy (related());
"LANGSELECT", lazy (langselect());
"FOOTER", lazy (footer());
"CHILDREN", lazy main;
]
......
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