5 ## try to detect the language from a parameter
6 my %args = $m->request_args();
7 if (exists $args{'__language'} && $args{'__language'})
9 $session_cache{$session_id}->{language} = $args{"__language"}
10 if (defined $session_id);
11 return set_language ($args{"__language"});
14 ## check for a session
15 ## try to detect the language from the session
17 exists $session_cache{$session_id}->{language} and
18 length $session_cache{$session_id}->{language})
20 return set_language ($session_cache{$session_id}->{language});
23 ## try to detect the language from the browser env
24 #my $browser = $args{'HTTP_ACCEPT_LANGUAGE'};
25 my $browser = $ENV{'HTTP_ACCEPT_LANGUAGE'};
27 ## supported languages so far
28 my %possible_translations = (
29 C => 'C', ## this should only be used for debugging and testing
37 my @configured_translations = $m->comp('/lib/configured_languages.mhtml');
38 foreach my $lang (@configured_translations) {
39 $translations{$lang} = $possible_translations{$lang};
44 ## language: en,en-us;q=0.8,de;q=0.7,de-de;q=0.5,ja;q=0.3,ar;q=0.2
45 ## charset : ISO-8859-1,utf-8;q=0.7,*;q=0.7
47 ## language: de,de-at;q=0.7,ja;q=0.3
50 ## if first lang matches one of our support chooes it
52 ## if none matches - choose default C
54 ## BTW we enforce utf8 as charset
57 @list = split (/,/ , $browser);
60 ## check every browser supported lang until one matches our supported ones
62 foreach my $lang (@list){
63 ## get only the firt two characters for each supported language
64 ## skip country details and rating q=0.7 or something
65 ## since they are usally in order from first to last supported
66 my $choose = substr($lang,0,2);
67 if ($translations{$choose})
69 #print "LANG: ".$translations{$choose}."\n";
70 set_language($translations{$choose});
71 $session_cache{$session_id}->{language} = $translations{$choose}
72 if (defined $session_id);
77 ## use the system default language
78 my $default_lang = 'en_US';
79 set_language($default_lang);
80 $session_cache{$session_id}->{language} = $default_lang
81 if (defined $session_id);