From 73153cffed6ffcd58a381ce5361100bf1f0ab6a0 Mon Sep 17 00:00:00 2001 From: Fraenkiman Date: Tue, 18 Apr 2023 23:27:40 +0200 Subject: [PATCH] The setup, blog and admin area is automatically determined by the user agent Fixes #216 Fixes #197 The exchange between browser and server transmits information about the client and its capabilities in headers - user agent, what it accepts, and (what interests us) language. The browser sends the language information in a header. These values indicate that the browser accepts, for example, US English (en-us) or German (de-de). We make use of this. The setup of FlatPress now starts automatically in the language of the user. The determined language will also be used as default language for the FlatPressblog and the administration area until the user defines a language himself. For the setup the language files 'el-gr','es-es','fr-fr' are still missing. Therefore I limited the automatic determination of the language to 'cs-cz', 'de-de', 'en-us', 'it-it', 'ja-jp', 'nl-nl', 'pt-br'. See #239 --- defaults.php | 3 +- fp-defaults/settings-defaults.php | 6 ++- fp-interface/lang/browserlang.php | 64 +++++++++++++++++++++++++++++++ setup/main.php | 61 ----------------------------- 4 files changed, 70 insertions(+), 64 deletions(-) create mode 100644 fp-interface/lang/browserlang.php diff --git a/defaults.php b/defaults.php index 439c190..cf91023 100755 --- a/defaults.php +++ b/defaults.php @@ -93,7 +93,8 @@ define('IMAGES_DIR', FP_CONTENT . 'images/'); // here is where all the attachments will be saved define('ATTACHS_DIR', FP_CONTENT . 'attachs/'); -define('LANG_DEFAULT', 'en-us'); +include(LANG_DIR . 'browserlang.php'); +define('LANG_DEFAULT', $browserLang); define('BPT_SORT', SORT_DESC); set_include_path(ABS_PATH); diff --git a/fp-defaults/settings-defaults.php b/fp-defaults/settings-defaults.php index f8f2ac9..22cd99a 100755 --- a/fp-defaults/settings-defaults.php +++ b/fp-defaults/settings-defaults.php @@ -21,7 +21,7 @@ $fp_config = array( 'dateformat' => '%A, %B %e, %Y', 'dateformatshort' => '%Y-%m-%d', 'charset' => 'utf-8', - 'lang' => 'en-us' + 'lang' => '' ), 'plugins' => array( 'blockparser' => array( @@ -37,4 +37,6 @@ $fp_config = array( 'url-maxlen' => 40, ), ), -); \ No newline at end of file +); + +?> diff --git a/fp-interface/lang/browserlang.php b/fp-interface/lang/browserlang.php new file mode 100644 index 0000000..7305a60 --- /dev/null +++ b/fp-interface/lang/browserlang.php @@ -0,0 +1,64 @@ + $intCurrentQ) { + $strCurrentLanguage = strtolower (join ('-', $arrLangCode)); + $intCurrentQ = $intLangQuality; + break; + } + } + if ($boolStrictMode) break; + array_pop ($arrLangCode); + } + } + return $strCurrentLanguage; +} + +// accept the following languages, otherwise fall back to "en-us" +$browserLang = getBrowserLanguage(array('cs-cz', 'de-de', 'en-us', 'it-it', 'ja-jp', 'nl-nl', 'pt-br'), 'en-us'); + +?> diff --git a/setup/main.php b/setup/main.php index 38187d7..e796cb2 100644 --- a/setup/main.php +++ b/setup/main.php @@ -1,65 +1,4 @@ $intCurrentQ) { - $strCurrentLanguage = strtolower (join ('-', $arrLangCode)); - $intCurrentQ = $intLangQuality; - break; - } - } - if ($boolStrictMode) break; - array_pop ($arrLangCode); - } - } - return $strCurrentLanguage; -} - -// accept the following languages, otherwise fall back to "en-us" -$browserLang = getBrowserLanguage(array('cs-cz', 'de-de', 'en-us', 'it-it', 'ja-jp', 'nl-nl', 'pt-br'), 'en-us'); - $language = @$_POST ['language']? $_POST ['language'] : $browserLang; $lf = "lang.$language.php";