111 $this->BlockSettings =
get_package_object(
'settings::settings' ,
'last' , __FILE__ );
112 $this->Cache =
get_package(
'cache' ,
'last' , __FILE__ );
113 $this->CachedMultyFS =
get_package(
'cached_multy_fs' ,
'last' , __FILE__ );
114 $this->PageJS =
get_package(
'page::page_js' ,
'last' , __FILE__ );
115 $this->Security =
get_package(
'security' ,
'last' , __FILE__ );
116 $this->String =
get_package(
'string' ,
'last' , __FILE__ );
120 catch( Exception $e )
148 foreach( explode(
',' , @$_SERVER[
'HTTP_ACCEPT_LANGUAGE' ] ) as $Lang )
150 $Pattern =
'/^(?P<primarytag>[a-zA-Z]{2,8})'.
151 '(?:-(?P<subtag>[a-zA-Z]{2,8}))?(?:(?:;q=)'.
152 '(?P<quantifier>\d\.\d))?$/';
154 if( preg_match( $Pattern , $Lang , $Splits ) )
156 return( $Splits[
'primarytag' ] );
186 $Path = $Path.
'/include/js/lang.core.'.$this->Language.
'.js';
188 if( $this->CachedMultyFS->file_exists( $Path ) === false )
190 $this->PageJS->add_javascript(
'{http_host}/'.$Path );
191 $Content = $this->CachedMultyFS->get_template( __FILE__ ,
'lang.core.js.tpl' );
192 $Content = str_replace(
'{locale}' , $this->Language , $Content );
193 $this->CachedMultyFS->file_put_contents( $Path , $Content );
196 $this->PageJS->add_javascript(
'{http_host}/'.$Path );
200 catch( Exception $e )
232 $tmp1 = explode(
'=' , $RawData );
234 return( array( $tmp1[ 0 ] ,
'default' , $tmp1[ 1 ] ) );
236 catch( Exception $e )
270 $LanguageFilePath = $Path.
'/res/lang/'.$TopPackageName.
'.'.
$this->Language;
272 if( file_exists( $LanguageFilePath ) )
274 $RawData = $this->CachedMultyFS->file_get_contents( $LanguageFilePath ,
'cleaned' );
278 catch( Exception $e )
314 private function compile_script_line( $StringAlias , $Condition , $Translation )
319 "if( !ultimix.lang.Strings[ ultimix.lang.Locale ][ '$StringAlias' ] ) ".
320 "ultimix.lang.Strings[ ultimix.lang.Locale ][ '$StringAlias' ] = {};\r\n".
321 "ultimix.lang.Strings[ ultimix.lang.Locale ]".
322 "[ '$StringAlias' ][ '$Condition' ] = '".trim( $Translation ,
'/' ).
"';\r\n"
325 catch( Exception $e )
353 private function compile_lang_javascript( $LangFilePath , $ScriptPath )
357 if( $this->CachedMultyFS->file_exists( $ScriptPath ) ===
false ||
358 $this->Cache->get_data( $ScriptPath ) === false )
360 $Strings = $this->CachedMultyFS->file_get_contents( $LangFilePath ,
'exploded' );
363 foreach( $Strings as $k => $v )
366 $Translation = str_replace(
"'" ,
"\\'" , $Translation );
367 $Script .= $this->compile_script_line( $StringAlias , $Condition , $Translation );
370 $this->CachedMultyFS->file_put_contents( $ScriptPath , $Script );
373 catch( Exception $e )
407 $LangFilePath = $Path.
'/res/lang/'.$TopPackageName.
'.'.
$this->Language;
409 if( $this->CachedMultyFS->file_exists( $LangFilePath ) )
411 $ScriptPath = $Path.
'/include/js/'.$TopPackageName.
'.'.$this->Language.
'.js';
416 $this->compile_lang_javascript( $LangFilePath , $ScriptPath );
418 $this->PageJS->add_javascript(
'{http_host}/'.$ScriptPath );
421 catch( Exception $e )
449 $Languages = file_get_contents( dirname( __FILE__ ).
'/conf/cf_lang_list' );
450 $Languages = str_replace(
"\r" ,
"\n" , $Languages );
451 $Languages = str_replace(
"\n\n" ,
"\n" , $Languages );
452 $Languages = explode(
"\n" , $Languages );
454 return( $Languages );
456 catch( Exception $e )
484 if( $this->Language ===
false )
486 if( $this->LangList ===
false )
490 if( $this->Security->get_c(
'client_lang' ) )
492 $this->Language = $this->Security->get_c(
'client_lang' ,
'command' );
494 elseif( ( $Key = array_search( $this->
get_client_language() , $this->LangList ) ) !==
false )
496 $this->Language = $this->LangList[ $Key ];
500 $this->Language = $this->CachedMultyFS->get_config( __FILE__ ,
'cf_locale_conf' );
504 return( $this->Language );
506 catch( Exception $e )
534 if( strlen( $RawData ) )
536 $RawData = explode(
"\n" , $RawData );
538 foreach( $RawData as $rd )
542 if( isset( $this->StringSet[ $StringAlias ] ) ===
false )
544 $this->StringSet[ $StringAlias ] = array();
547 $this->StringSet[ $StringAlias ][ $Condition ] = $Translation;
551 catch( Exception $e )
579 if( file_exists( $LanguageFilePath ) )
581 $RawData = $this->CachedMultyFS->file_get_contents( $LanguageFilePath ,
'cleaned' );
585 catch( Exception $e )
622 catch( Exception $e )
642 private function force_load_translations()
648 $Paths [] = array(
'directory' =>
'.' ,
'package_name' =>
'lang' );
649 $Key =
implode_ex(
'' , $Paths ,
'directory' );
650 if( $this->Cache->data_exists( $Key ) === true )
652 $this->StringSet = unserialize( $this->Cache->get_data( $Key ) );
656 foreach( $Paths as $p )
659 $Path = $p[
'directory' ].
"/res/lang/$Name.$this->Language";
663 $this->Cache->add_data( $Key , serialize( $this->StringSet ) );
666 catch( Exception $e )
690 if( $this->AutoTranslationsWereLoaded ===
false )
694 $this->force_load_translations();
696 $this->AutoTranslationsWereLoaded =
true;
699 catch( Exception $e )
735 if( isset( $this->StringSet[ $StringAlias ] ) ===
false ||
736 ( $Value ==
'default' && isset( $this->StringSet[ $StringAlias ][ $Value ] ) ===
false ) )
738 return( $StringAlias );
741 if( $Value ==
'default' && isset( $this->StringSet[ $StringAlias ][
'default' ] ) !==
false )
743 return( $this->StringSet[ $StringAlias ][
'default' ] );
746 return( $StringAlias );
748 catch( Exception $e )