Skip to content

Commit

Permalink
Fixes #158 | Localize Smarty function {html_select_date}
Browse files Browse the repository at this point in the history
- use LC_TIME
  • Loading branch information
Fraenkiman authored Sep 26, 2024
2 parents 9c8689e + 07eeeec commit f3340ba
Show file tree
Hide file tree
Showing 15 changed files with 201 additions and 1 deletion.
56 changes: 55 additions & 1 deletion fp-includes/core/core.language.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ function lang_load($postfix = null) {
// checks if we already loaded this lang file
$old_lang = &$GLOBALS ['lang'];

if (!$old_lang)
if (!$old_lang) {
$old_lang = array();
}

if ($postfix) {

Expand Down Expand Up @@ -109,4 +110,57 @@ function lang_list() {
return $obj->getList();
}

/**
* Localize Smarty function {html_select_date} with LC_TIME
*
* Hint: The character set and coding must be installed on the web server (locale -a),
* otherwise there will be display problems with non-ASCII characters.
*/
function set_locale() {
global $fp_config;

$langId = $fp_config ['locale'] ['lang'];

$langConfFile = LANG_DIR . $langId . '/lang.conf.php';
if (file_exists($langConfFile)) {
include_once $langConfFile;
}

// As entered in the admin area in the configuration panel -> International settings -> Character set.
$charset = $fp_config ['locale'] ['charset'];

// Read different possible locale names from lang.conf file
$localeCountry_a = $langconf ['localecountry_a']; // de_DE
$localeCountry_b = $langconf ['localecountry_b']; // de-DE

// Entered character set coding available in the lang.conf file?
if (preg_match('/\b' . $langconf ['charsets'] [0] . '\b/i', $charset)) {
$localeCharset_a = $langconf ['localecharset_a']; // .UTF-8
$localeCharset_b = $langconf ['localecharset_b']; // .utf8
} else {
$localeCharset_a = '';
$localeCharset_b = '';
}

if (preg_match('/\b' . $langconf ['charsets'] [1] . '\b/i', $charset)) {
$localeCharset_c = $langconf ['localecharset_c']; // .ISO-8859-15
$localeCharset_d = $langconf ['localecharset_d']; // .iso885915
} else {
$localeCharset_c = '';
$localeCharset_d = '';
}

$localeShort = $langconf ['localeshort']; // de

// Check if LC_TIME is set and returns the current locale
$currentLocale = @setlocale(LC_TIME, 0);

// If LC_TIME is not set or contains something else, but not the correct locale,
if ($currentLocale === false || (!preg_match('/\b' . $localeShort . '\b/i', $currentLocale))) {
// then try different possible locale names.
$currentLocale = @setlocale(LC_TIME, $localeCountry_a . $localeCharset_a, $localeCountry_a . $localeCharset_b, $localeCountry_a . $localeCharset_c, $localeCountry_a . $localeCharset_d, $localeCountry_a, $localeCountry_b, $localeShort);
}

//echo '<pre>' . strftime_replacement("%B") . '</pre>';
}
?>
11 changes: 11 additions & 0 deletions fp-interface/lang/cs-cz/lang.conf.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,15 @@
$langconf ['locale'] = 'cs-cz';
$langconf ['charsets'] [0] = 'utf-8';
$langconf ['charsets'] [1] = 'iso-8859-15';

// Different possible locale names
$langconf ['localecountry_a'] = 'cs_CZ';
$langconf ['localecountry_b'] = 'cs-CZ';
$langconf ['localeshort'] = 'cs';

// Different possible coding names
$langconf ['localecharset_a'] = '.UTF-8';
$langconf ['localecharset_b'] = '.utf8';
$langconf ['localecharset_c'] = '.ISO-8859-15';
$langconf ['localecharset_d'] = '.iso885915';
?>
11 changes: 11 additions & 0 deletions fp-interface/lang/da-dk/lang.conf.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,15 @@
$langconf ['locale'] = 'da-dk';
$langconf ['charsets'] [0] = 'utf-8';
$langconf ['charsets'] [1] = 'iso-8859-15';

// Different possible locale names
$langconf ['localecountry_a'] = 'da_DK';
$langconf ['localecountry_b'] = 'da-DK';
$langconf ['localeshort'] = 'da';

// Different possible coding names
$langconf ['localecharset_a'] = '.UTF-8';
$langconf ['localecharset_b'] = '.utf8';
$langconf ['localecharset_c'] = '.ISO-8859-15';
$langconf ['localecharset_d'] = '.iso885915';
?>
11 changes: 11 additions & 0 deletions fp-interface/lang/de-de/lang.conf.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,15 @@
$langconf ['locale'] = 'de-de';
$langconf ['charsets'] [0] = 'utf-8';
$langconf ['charsets'] [1] = 'iso-8859-15';

// Different possible locale names
$langconf ['localecountry_a'] = 'de_DE';
$langconf ['localecountry_b'] = 'de-DE';
$langconf ['localeshort'] = 'de';

// Different possible coding names
$langconf ['localecharset_a'] = '.UTF-8';
$langconf ['localecharset_b'] = '.utf8';
$langconf ['localecharset_c'] = '.ISO-8859-15';
$langconf ['localecharset_d'] = '.iso885915';
?>
11 changes: 11 additions & 0 deletions fp-interface/lang/el-gr/lang.conf.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,15 @@
$langconf ['locale'] = 'el-gr';
$langconf ['charsets'] [0] = 'utf-8';
$langconf ['charsets'] [1] = 'iso-8859-7';

// Different possible locale names
$langconf ['localecountry_a'] = 'el_GR';
$langconf ['localecountry_b'] = 'el-GR';
$langconf ['localeshort'] = 'el';

// Different possible coding names
$langconf ['localecharset_a'] = '.UTF-8';
$langconf ['localecharset_b'] = '.utf8';
$langconf ['localecharset_c'] = '.ISO-8859-7';
$langconf ['localecharset_d'] = '.iso88597';
?>
11 changes: 11 additions & 0 deletions fp-interface/lang/en-us/lang.conf.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,15 @@
$langconf ['locale'] = 'en-us';
$langconf ['charsets'] [0] = 'utf-8';
$langconf ['charsets'] [1] = 'iso-8859-15';

// Different possible locale names
$langconf ['localecountry_a'] = 'en_US';
$langconf ['localecountry_b'] = 'en-US';
$langconf ['localeshort'] = 'en';

// Different possible coding names
$langconf ['localecharset_a'] = '.UTF-8';
$langconf ['localecharset_b'] = '.utf8';
$langconf ['localecharset_c'] = '.ISO-8859-15';
$langconf ['localecharset_d'] = '.iso885915';
?>
11 changes: 11 additions & 0 deletions fp-interface/lang/es-es/lang.conf.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,15 @@
$langconf ['locale'] = 'es-es';
$langconf ['charsets'] [0] = 'utf-8';
$langconf ['charsets'] [1] = 'iso-8859-15';

// Different possible locale names
$langconf ['localecountry_a'] = 'es_ES';
$langconf ['localecountry_b'] = 'es-ES';
$langconf ['localeshort'] = 'es';

// Different possible coding names
$langconf ['localecharset_a'] = '.UTF-8';
$langconf ['localecharset_b'] = '.utf8';
$langconf ['localecharset_c'] = '.ISO-8859-15';
$langconf ['localecharset_d'] = '.iso885915';
?>
11 changes: 11 additions & 0 deletions fp-interface/lang/fr-fr/lang.conf.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,15 @@
$langconf ['locale'] = 'fr-fr';
$langconf ['charsets'] [0] = 'utf-8';
$langconf ['charsets'] [1] = 'iso-8859-15';

// Different possible locale names
$langconf ['localecountry_a'] = 'fr_FR';
$langconf ['localecountry_b'] = 'fr-FR';
$langconf ['localeshort'] = 'fr';

// Different possible coding names
$langconf ['localecharset_a'] = '.UTF-8';
$langconf ['localecharset_b'] = '.utf8';
$langconf ['localecharset_c'] = '.ISO-8859-15';
$langconf ['localecharset_d'] = '.iso885915';
?>
11 changes: 11 additions & 0 deletions fp-interface/lang/it-it/lang.conf.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,15 @@
$langconf ['locale'] = 'it-it';
$langconf ['charsets'] [0] = 'utf-8';
$langconf ['charsets'] [1] = 'iso-8859-15';

// Different possible locale names
$langconf ['localecountry_a'] = 'it_IT';
$langconf ['localecountry_b'] = 'it-IT';
$langconf ['localeshort'] = 'it';

// Different possible coding names
$langconf ['localecharset_a'] = '.UTF-8';
$langconf ['localecharset_b'] = '.utf8';
$langconf ['localecharset_c'] = '.ISO-8859-15';
$langconf ['localecharset_d'] = '.iso885915';
?>
11 changes: 11 additions & 0 deletions fp-interface/lang/ja-jp/lang.conf.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,15 @@
$langconf ['locale'] = 'ja-jp';
$langconf ['charsets'] [0] = 'utf-8';
$langconf ['charsets'] [1] = 'iso-8859-15';

// Different possible locale names
$langconf ['localecountry_a'] = 'ja_JP';
$langconf ['localecountry_b'] = 'ja-JP';
$langconf ['localeshort'] = 'ja';

// Different possible coding names
$langconf ['localecharset_a'] = '.UTF-8';
$langconf ['localecharset_b'] = '.utf8';
$langconf ['localecharset_c'] = '.ISO-8859-15';
$langconf ['localecharset_d'] = '.iso885915';
?>
11 changes: 11 additions & 0 deletions fp-interface/lang/nl-nl/lang.conf.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,15 @@
$langconf ['locale'] = 'nl-nl';
$langconf ['charsets'] [0] = 'utf-8';
$langconf ['charsets'] [1] = 'iso-8859-15';

// Different possible locale names
$langconf ['localecountry_a'] = 'nl_NL';
$langconf ['localecountry_b'] = 'nl-NL';
$langconf ['localeshort'] = 'nl';

// Different possible coding names
$langconf ['localecharset_a'] = '.UTF-8';
$langconf ['localecharset_b'] = '.utf8';
$langconf ['localecharset_c'] = '.ISO-8859-15';
$langconf ['localecharset_d'] = '.iso885915';
?>
11 changes: 11 additions & 0 deletions fp-interface/lang/pt-br/lang.conf.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,15 @@
$langconf ['locale'] = 'pt-br';
$langconf ['charsets'] [0] = 'utf-8';
$langconf ['charsets'] [1] = 'iso-8859-15';

// Different possible locale names
$langconf ['localecountry_a'] = 'pt_BR';
$langconf ['localecountry_b'] = 'pt-BR';
$langconf ['localeshort'] = 'pt';

// Different possible coding names
$langconf ['localecharset_a'] = '.UTF-8';
$langconf ['localecharset_b'] = '.utf8';
$langconf ['localecharset_c'] = '.ISO-8859-15';
$langconf ['localecharset_d'] = '.iso885915';
?>
11 changes: 11 additions & 0 deletions fp-interface/lang/ru-ru/lang.conf.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,15 @@
$langconf ['locale'] = 'ru-ru';
$langconf ['charsets'] [0] = 'utf-8';
$langconf ['charsets'] [1] = 'iso-8859-5';

// Different possible locale names
$langconf ['localecountry_a'] = 'ru_RU';
$langconf ['localecountry_b'] = 'ru-RU';
$langconf ['localeshort'] = 'ru';

// Different possible coding names
$langconf ['localecharset_a'] = '.UTF-8';
$langconf ['localecharset_b'] = '.utf8';
$langconf ['localecharset_c'] = '.ISO-8859-5';
$langconf ['localecharset_d'] = '.iso88595';
?>
11 changes: 11 additions & 0 deletions fp-interface/lang/sl-si/lang.conf.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,15 @@
$langconf ['locale'] = 'sl-si';
$langconf ['charsets'] [0] = 'utf-8';
$langconf ['charsets'] [1] = 'iso-8859-15';

// Different possible locale names
$langconf ['localecountry_a'] = 'sl_SI';
$langconf ['localecountry_b'] = 'sl-SI';
$langconf ['localeshort'] = 'sl';

// Different possible coding names
$langconf ['localecharset_a'] = '.UTF-8';
$langconf ['localecharset_b'] = '.utf8';
$langconf ['localecharset_c'] = '.ISO-8859-15';
$langconf ['localecharset_d'] = '.iso885915';
?>
3 changes: 3 additions & 0 deletions search.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ function search_display() {
function search_main() {
global $lang, $smarty;

// Localize Smarty function {html_select_date}
set_locale();

// register Smarty modifier functions
$smarty->registerPlugin('modifier', 'function_exists', 'function_exists');
$smarty->registerPlugin('modifier', 'is_numeric', 'is_numeric');
Expand Down

0 comments on commit f3340ba

Please sign in to comment.