]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 126955 - Bugzilla should support translated/localized templates. This patch uses...
authorgerv%gerv.net <>
Sat, 10 Aug 2002 23:58:59 +0000 (23:58 +0000)
committergerv%gerv.net <>
Sat, 10 Aug 2002 23:58:59 +0000 (23:58 +0000)
defparams.pl
globals.pl

index 45e67d5322ac16ee49f190d7bef96348b35bc688..3e3fd441dc383a8b96e294a3ca77e168c1f06742 100644 (file)
@@ -139,6 +139,16 @@ sub check_urlbase {
     return "";
 }
 
+DefParam("languages",
+         "A comma-separated list of RFC 1766 language tags. These identify the languages in which you wish Bugzilla output to be displayed. Note that you must install the appropriate language pack before adding a language to this Param. The language used is the one in this list with the highest q-value in the user's Accept-Language header.",
+         "t",
+         "en");
+
+DefParam("defaultlanguage",
+         "The UI language Bugzilla falls back on if no suitable language is found in the user's Accept-Language header.",
+         "t",
+         "en");
+
 DefParam("cookiepath", 
   "Directory path under your document root that holds your Bugzilla installation. Make sure to begin with a /.",
   "t",
index cdaf845124d6e50d6cc813f890e20892b41e07a8..6f7b22d38ebeddd4d3ab22fa0e891876e2ff02a2 100644 (file)
@@ -1506,6 +1506,54 @@ sub trim {
     return $str;
 }
 
+# Make an ordered list out of a HTTP Accept-Language header see RFC 2616, 14.4
+# We ignore '*' and <language-range>;q=0
+# For languages with the same priority q the order remains unchanged.
+sub sortAcceptLanguage {
+    sub sortQvalue { $b->{'qvalue'} <=> $a->{'qvalue'} }
+    my $accept_language = $_[0];
+
+    # clean up string.
+    $accept_language =~ s/[^A-Za-z;q=0-9\.\-,]//g;
+    my @qlanguages;
+    my @languages;
+    foreach(split /,/, $accept_language) {
+        my ($lang, $qvalue) = split /;q=/;
+        next if not defined $lang;
+        $qvalue = 1 if not defined $qvalue;
+        next if $qvalue == 0;
+        $qvalue = 1 if $qvalue > 1;
+        push(@qlanguages, {'qvalue' => $qvalue, 'language' => $lang});
+    }
+
+    return map($_->{'language'}, (sort sortQvalue @qlanguages));
+}
+
+# Returns the path to the templates based on the Accept-Language
+# settings of the user and of the available languages
+# If no Accept-Language is present it uses the defined default
+sub getTemplateIncludePath () {
+    my @languages       = sortAcceptLanguage(Param('languages'));
+    my @accept_language = sortAcceptLanguage($ENV{'HTTP_ACCEPT_LANGUAGE'} || "");
+    my @usedlanguages;
+    foreach my $lang (@accept_language) {
+        # match exactly (case insensitive)
+        if(my @found = grep /^$lang$/i, @languages) {
+            push (@usedlanguages, $found[0]);
+        }
+        # Per RFC 1766 and RFC 2616 any language tag matches also its 
+        # primary tag. That is en-gb matches also en but not en-uk
+        $lang =~ s/(-.*)//;
+        if($1) {
+            if(my @found = grep /^$lang$/i, @languages) {
+                push (@usedlanguages, $found[0]);
+            }
+        }
+    }
+    push(@usedlanguages, Param('defaultlanguage'));
+    return join(':', map("template/$_/custom:template/$_/default",@usedlanguages)); 
+}
+
 ###############################################################################
 # Global Templatization Code
 
@@ -1523,7 +1571,7 @@ use Template;
 $::template ||= Template->new(
   {
     # Colon-separated list of directories containing templates.
-    INCLUDE_PATH => "template/en/custom:template/en/default" ,
+    INCLUDE_PATH => getTemplateIncludePath() ,
 
     # Remove white-space before template directives (PRE_CHOMP) and at the
     # beginning and end of templates and template blocks (TRIM) for better