package ONO::ToolBox::DomainLang;
################################################################################
# COPYRIGHT / LICENSE #
################################################################################
#
# This file is part of the ONO Software Project.
#
# Copyright (C) 2000-2025 Jos KIRPS [ www.kirps.com | jos_AT_kirps_DOT_com ]
# and The Joopita Project [ www.joopita.org | contact_AT_joopita_DOT_com ]
#
# This file, as well as other parts of the ONO Software Project or related
# elements, are FREE SOFTWARE available under the ARTISTIC LICENSE 2.0.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# For the full license, see /ono/osr/license/LICENSE.txt, or write to
# jos_AT_kirps_DOT_com or contact_AT_joopita_DOT_com.
#
################################################################################
# END OF COPYRIGHT / LICENSE, HERE COMES THE CODE ... #
################################################################################
use strict;
use ONO::Lib::Web::Cookie;
###############################################################################
# ONO
###############################################################################
sub get {
#: Detect the website / platform language, based on a number of factors such
#: as the domain TLD or subdomain, subdirectories, or cookies.
#:
#: The default language is "en" (english).
# english is default language
my $lang = "en";
# first we'll check the TLD
if ($ENV{'HTTP_HOST'} =~ /\.(de|at|ch|fr|be|lu|lb|nl|es|pt|it|no|fi|da|dk|sv|se)$/) {
$lang = $1;
}
# then we'll check sub-domains - from this point, we'll need to include EN, US and UK (switch-back)
if ($ENV{'HTTP_HOST'} =~ /^(en|us|uk|de|at|ch|fr|be|lu|lb|nl|es|pt|it|no|fi|dk|se)\./) {
$lang = "de";
}
# then we'll check first-level-dirs
if ($ENV{'REQUEST_URI'} =~ m~^/(en|us|uk|de|at|ch|fr|be|lu|lb|nl|es|pt|it|no|fi|da|dk|sv|se)/~) {
$lang = $1;
}
# then we'll check second-level-dirs (base)
if ($ENV{'REQUEST_URI'} =~ m~^/(.*?)/(en|us|uk|de|at|ch|fr|be|lu|lb|nl|es|pt|it|no|fi|da|dk|sv|se)/~) {
$lang = $2;
}
# then we'll check cookies -- this will overwrite all previous checks
if (ONO::Lib::Web::Cookie->get("ono_default_lang") =~ m~^(en|us|uk|de|at|ch|fr|be|lu|lb|nl|es|pt|it|no|fi|da|dk|sv|se)$~) {
$lang = $1;
}
# fixes...
if ($lang eq "us" || $lang eq "uk") {
$lang = "en";
}
if ($lang eq "at" || $lang eq "ch") {
$lang = "de";
}
if ($lang eq "be") {
$lang = "fr";
}
if ($lang eq "lb") {
$lang = "lu";
}
if ($lang eq "da") {
$lang = "dk";
}
if ($lang eq "sv") {
$lang = "se";
}
# custom code, currently supporting the following platform(s):
#
# - oli.education.lu and sites.schoul.lu
# if ("$ENV{'HTTP_HOST'}$ENV{'REQUEST_URI'}" =~ m~^(ssl|ssldev|sites)\.(education|schoul)\.lu/oli/(.*?)/~) {
### THIS SHOULD BE OBSOLETE NOW !!!
# $lang = $3;
# }
return $lang;
}
###############################################################################
# end of script
###############################################################################
1;
__END__