]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blobdiff - config/cfgroot/lang.pl
Merge branch 'haproxy' into next
[people/pmueller/ipfire-2.x.git] / config / cfgroot / lang.pl
index 707b28d11e2b3c237c5c9cad072b20a705b50f34..2b09c4a9ff44ab4baf05b3e7439b218c35a28d2b 100644 (file)
@@ -50,8 +50,8 @@ $language = $settings{'LANGUAGE'};
 # (it is a developper options)
 #
 sub reload {
+    my $LG = &FindWebLanguage(shift);
 
-    my ($LG) = @_;
     %Lang::tr = ();    # start with a clean array
 
     # Use CacheLang if present & not empty.
@@ -157,4 +157,40 @@ sub BuildCacheLang {
     &General::log ("WARNING: cannot build cachelang file for [$missed].") if ($error);
     return $error;
 }
+
+sub FindWebLanguage() {
+       my $lang = shift;
+
+       my @options = ($lang);
+
+       my ($shortlang, $encoding) = split(/\./, $lang);
+       push(@options, $shortlang);
+
+       my ($language, $country) = split(/_/, $shortlang);
+       push(@options, $language);
+
+       # Add English as fallback
+       push(@options, "en");
+
+       foreach my $option (@options) {
+               return $option if (-e "${General::swroot}/langs/$option.pl");
+       }
+
+       return undef;
+}
+
+sub DetectBrowserLanguages() {
+       my $langs = $ENV{"HTTP_ACCEPT_LANGUAGE"};
+       my @results = ();
+
+       foreach my $lang (split /[,;]/, $langs) {
+               # Drop all q= arguments
+               next if ($lang =~ m/^q=/);
+
+               push(@results, $lang);
+       }
+
+       return @results;
+}
+
 1;