Skip to content

Commit

Permalink
Fixes for translations not working
Browse files Browse the repository at this point in the history
  • Loading branch information
craigk5n committed Sep 12, 2023
1 parent 5a07784 commit bb32cda
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
28 changes: 23 additions & 5 deletions includes/classes/WebCalendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,23 @@ class WebCalendar {
[
['InitFirstPhase', 'Config', 'PHPDBI', 'Functions'],
['User', 'Validate', 'Connect', 'SiteExtras', 'Access', 'InitSecondPhase']]];

// Provide translation of translation file (trimming the ".txt" to the proper value for mb_language)
private $mb_language_map = array(
'Arabic_utf8' => 'Arabic',
'Chinese-Big5' => 'Chinese',
'Chinese-GB2312' => 'Chinese',
'German' => 'German',
'German_utf8' => 'German',
'Hebrew_utf8' => 'Hebrew',
'Japanese-eucjp' => 'Japanese',
'Japanese-sjis' => 'Japanese',
'Japanese' => 'Japanese',
'Korean' => 'Korean',
'Russian' => 'Russian',
'Russian_utf8' => 'Russian',
'Spanish' => 'Spanish',
);

/**
* WebCalendar constructor.
*
Expand Down Expand Up @@ -920,12 +936,14 @@ function _initTranslate() {

if (extension_loaded('mbstring')) {
$mb_lang = strtok($lang, '-');
if (@mb_language($mb_lang) && mb_internal_encoding(translate('charset'))) {
$enable_mbstring = true;
// Check the language against the map, default to 'neutral' if not found
$mapped_lang = isset($this->mb_language_map[$mb_lang]) ? $this->mb_language_map[$mb_lang] : 'neutral';
if (@mb_language($mapped_lang) && mb_internal_encoding(translate('charset'))) {
$enable_mbstring = true;
} else {
$enable_mbstring = false;
$enable_mbstring = false;
}
}
}

$translation_loaded = false;

Expand Down
4 changes: 2 additions & 2 deletions includes/translate.php
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,8 @@ function translate ( $str, $decode = '', $type = '' ) {
if ( $type != '' ) {
// Translate number symbols.
for ( $i = 0; $i < 10; $i++ ) {
$tmp = $i . '';
if ( $tmp != $translations[$tmp] )
$tmp = (string) $i;
if (! empty($translations[$tmp]) && $tmp != $translations[$tmp])
$str = str_replace ( $tmp, $translations[$tmp], $str );
}
}
Expand Down

0 comments on commit bb32cda

Please sign in to comment.