summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid A. Madore <david+git@madore.org>2010-03-27 23:24:34 (GMT)
committerDavid A. Madore <david+git@madore.org>2010-03-27 23:24:34 (GMT)
commitdd14e78fef672acf2361416ac9eb17857ec55df7 (patch)
tree0e482839abffe111218662429d5dcf6e4ce8cfb2
parentfb32832d22bbd42b33d9ef5f23d66950730f498c (diff)
downloadblogengine-dd14e78fef672acf2361416ac9eb17857ec55df7.zip
blogengine-dd14e78fef672acf2361416ac9eb17857ec55df7.tar.gz
blogengine-dd14e78fef672acf2361416ac9eb17857ec55df7.tar.bz2
Handle translation links.
-rwxr-xr-xdaml2html.pl78
1 files changed, 75 insertions, 3 deletions
diff --git a/daml2html.pl b/daml2html.pl
index 59d9525..a672101 100755
--- a/daml2html.pl
+++ b/daml2html.pl
@@ -157,6 +157,7 @@ my $html_node;
my $head_node;
my ($src_title, $src_title_lang);
my ($src_subtitle, $src_subtitle_lang);
+my @translations;
my $style_content = "";
my $script_content = "";
@@ -235,6 +236,48 @@ sub do_subtitle_handler {
do_title_or_subtitle_handler $node, $optref, "subtitle", $src_subtitle, $src_subtitle_lang;
}
+sub do_translations_handler {
+ my $node = shift;
+ my $optref = shift;
+ my $parent = $node->parentNode;
+ foreach my $lang ( @translations ) {
+ my $p = $doc->createElementNS(XHTML_NS, "p");
+ set_node_lang_norec $p, $lang;
+ $parent->insertBefore($p, $node);
+ $parent->insertBefore($doc->createTextNode("\n"), $node);
+ my $str = "[";
+ if ( $lang eq "en" ) {
+ $str = "[An ";
+ } elsif ( $lang eq "fr" ) {
+ $str = "[Une ";
+ }
+ $p->appendChild($doc->createTextNode($str));
+ my $a = $doc->createElementNS(XHTML_NS, "a");
+ $p->appendChild($a);
+ $a->setAttributeNS("", "hreflang", $lang);
+ $a->setAttributeNS("", "href", "FIXME.".$lang);
+ $str = $lang;
+ if ( $lang eq "en" ) {
+ $str = "English version";
+ } elsif ( $lang eq "fr" ) {
+ $str = "version française";
+ }
+ $a->appendChild($doc->createTextNode($str));
+ $str = "]";
+ if ( $lang eq "en" ) {
+ $str = " of this page is also available.]";
+ } elsif ( $lang eq "fr" ) {
+ $str = " de cette page est également diponible.]";
+ }
+ $p->appendChild($doc->createTextNode($str));
+ }
+ if ( ($node->nextSibling)->nodeType == XML_TEXT_NODE
+ && ($node->nextSibling)->data =~ m/^\s*$/s ) {
+ $node->nextSibling->unbindNode;
+ }
+ $node->unbindNode;
+}
+
sub create_meta_element_helper {
my $src_node = shift; # May be undef
my $name_or_http_equiv = shift;
@@ -251,7 +294,7 @@ sub create_meta_element_helper {
$meta->setAttributeNS("", $name_or_http_equiv, $meta_name);
$meta->setAttributeNS("", "content", $meta_content);
if ( defined($src_node) ) {
- ($doc->documentElement)->appendChild($meta); # Work around libxml2 bug <URL: https://bugzilla.gnome.org/show_bug.cgi?id=614068 >
+# ($doc->documentElement)->appendChild($meta); # Work around libxml2 bug <URL: https://bugzilla.gnome.org/show_bug.cgi?id=614068 >
$src_node->replaceNode($meta);
} else {
die "\$head_node should have been defined at this point"
@@ -346,7 +389,7 @@ sub body_handler {
set_node_lang_norec $body_node, $lang;
}
$body_node->setAttributeNS("", "onload", "onLoad()");
- ($doc->documentElement)->appendChild($body_node); # Work around libxml2 bug <URL: https://bugzilla.gnome.org/show_bug.cgi?id=614068 >
+# ($doc->documentElement)->appendChild($body_node); # Work around libxml2 bug <URL: https://bugzilla.gnome.org/show_bug.cgi?id=614068 >
$node->replaceNode($body_node);
my @child_nodes = $node->childNodes;
my @to_process;
@@ -372,6 +415,14 @@ sub body_handler {
$body_node->appendChild($token);
# unshift @to_process, [\&do_navbar_handler, $token, {implicit=>1}];
}
+ unless ( $node->getAttributeNS("", "notranslations") ) {
+ if ( @translations ) {
+ my $token = $doc->createElementNS(DAML_NS, "d:implicit-do-translations");
+ $body_node->appendChild($doc->createTextNode("\n"));
+ $body_node->appendChild($token);
+ unshift @to_process, [\&do_translations_handler, $token, {implicit=>1}];
+ }
+ }
foreach my $child ( @child_nodes ) {
if ( $child->nodeType == XML_TEXT_NODE
|| $child->nodeType == XML_CDATA_SECTION_NODE ) {
@@ -408,7 +459,7 @@ sub title_handler {
# Note here this is with norec, earlier with rec...
set_node_lang_norec $title_node, $src_title_explicit_lang;
}
- ($doc->documentElement)->appendChild($title_node); # Work around libxml2 bug <URL: https://bugzilla.gnome.org/show_bug.cgi?id=614068 >
+# ($doc->documentElement)->appendChild($title_node); # Work around libxml2 bug <URL: https://bugzilla.gnome.org/show_bug.cgi?id=614068 >
$node->replaceNode($title_node);
$title_node->appendChild($doc->createTextNode($title_text));
create_meta_element_helper undef, "name", "Title", $title_text, $src_title_explicit_lang;
@@ -442,6 +493,26 @@ sub meta_handler {
}
}
+sub translation_handler {
+ my $node = shift;
+ my $optref = shift;
+ print STDERR "warning: translation handler doesn't handle arguments\n" if @_;
+ my $lang = get_node_lang_norec $node;
+ die "missing xml:lang attribute on translation" unless $lang;
+ push @translations, $lang;
+ my $link = $doc->createElementNS(XHTML_NS, "link");
+ set_node_lang_norec $link, $lang;
+ $link->setAttributeNS("", "rel", "Alternate");
+ if ( $lang eq "en" ) {
+ $link->setAttributeNS("", "title", "English version");
+ } elsif ( $lang eq "fr" ) {
+ $link->setAttributeNS("", "title", "Version française");
+ }
+ $link->setAttributeNS("", "hreflang", $lang);
+ $link->setAttributeNS("", "href", "FIXME.".$lang);
+ $node->replaceNode($link);
+}
+
sub extra_style_handler {
my $node = shift;
my $optref = shift;
@@ -461,6 +532,7 @@ my %daml_handler = (
"subtitle" => \&subtitle_handler,
"meta-description" => \&meta_handler,
"meta-keywords" => \&meta_handler,
+ "translation" => \&translation_handler,
"extra-style" => \&extra_style_handler,
);