package ONO::ToolBox::DomainLang;
################################################################################
# COPYRIGHT / LICENSE #
################################################################################
#
# This file is part of the ONO Software Project.
#
# Copyright (C) 2022-2026 Jos Kirps and The Joopita Project [ASBL]
# Copyright (C) 2011-2022 Jos Kirps and Joopita Research ASBL
# Copyright (C) 2006-2011 Jos Kirps and The Joopita Project
# Copyright (C) 2001-2006 Jos Kirps and The WobbleWolf Project
#
# This file, as well as many 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";
}
return $lang;
}
###############################################################################
# end of script
###############################################################################
1;
__END__