web commit by NicolasLimare: updated comment; $config{lang} is a nice default value
[ikiwiki] / doc / todo / language_definition_for_the_meta_plugin.mdwn
1 Here is a patch for the [[plugins/meta]] plugin. It adds the possibility to define the language 
2 used for a page, with \[[meta lang="ja"]]
3
4 It doesn't insert the langage information in the xhtml meta elements, but defines a LANG
5 variable to use in the templates, for example with
6
7     <html xmlns="http://www.w3.org/1999/xhtml"
8           lang="<TMPL_IF NAME="LANG"><TMPL_VAR LANG><TMPL_ELSE>fr</TMPL_IF>"
9           xml:lang="<TMPL_IF NAME="LANG"><TMPL_VAR LANG><TMPL_ELSE>fr</TMPL_IF>">
10
11 This way also allows to define a language for a subset of the final page, with custom
12 templates and inclusion. 
13
14 This may be useful for sites with a few pages in different languages, but no full i18n.
15
16 > Looks good, but the need to modify the template and include a default
17 > language in it is a bit problimatic, I think. --[[Joey]]
18
19 >> --lang=XX could be a setup option, with a default value, then the template would be 
20
21                 <html xmlns="http://www.w3.org/1999/xhtml" lang="<TMPL_VAR LANG>" xml:lang="<TMPL_VAR LANG>">
22
23 >>> Yes, that seems reasonable. I guess there's no problem with defaulting
24 >>> to en if it can be overridden in the setup. --[[Joey]]
25
26 >>>> Yes, english default makes sense. I guess we should use the `$config{lang}`, 
27 >>>> defined from the setup file or command-line options to define the default language
28 >>>> (`$config{lang}` defaults to `en` which is fine) if the html pages, and override
29 >>>> it from the `meta` directive.
30 >>>> — [[NicolasLimare]]
31
32 <pre>
33 --- meta.orig.pm  2007-07-27 00:19:51.000000000 +0200
34 +++ meta.pm       2007-08-05 22:37:40.000000000 +0200
35 @@ -11,6 +11,7 @@
36  my %permalink;
37  my %author;
38  my %authorurl;
39 +my %lang;
40  
41  sub import { #{{{
42         hook(type => "preprocess", id => "meta", call => \&preprocess, scan => 1);
43 @@ -100,6 +101,11 @@
44                 $meta{$page}.='<link href="'.encode_entities($value).
45                         "\" rel=\"openid.delegate\" />\n";
46         }
47 +       elsif ($key eq 'lang') {
48 +           if ($value =~ /^[A-Za-z]{2}$/) {
49 +               $lang{$page}=$value;
50 +           }
51 +       }
52         else {
53                 $meta{$page}.=scrub("<meta name=\"".encode_entities($key).
54                         "\" content=\"".encode_entities($value)."\" />\n");
55 @@ -131,6 +137,8 @@
56                 if exists $author{$page} && $template->query(name => "author");
57         $template->param(authorurl => $authorurl{$page})
58                 if exists $authorurl{$page} && $template->query(name => "authorurl");
59 +       $template->param(lang => $lang{$page})
60 +               if exists $lang{$page} && $template->query(name => "lang");
61  
62  } # }}}
63 </pre>
64
65
66 [[tag wishlist patch plugin/meta translation]]