ultimix
lang_1_0_0 Class Reference

Public Member Functions

 __construct ()
 get_client_language ()
 pre_generation ($Options)
 dispatch_string_data ($RawData)
 include_strings ($PackageName, $PackageVersion= 'last')
 include_strings_js ($PackageName, $PackageVersion= 'last')
 get_list_of_languages ()
 get_locale ()
 load_data ($RawData)
 load_translations_from_file ($LanguageFilePath)
 load_translations_from_package ($PackageName, $PackageVersion)
 load_translations ()
 get_string ($StringAlias, $Value= 'default')

Data Fields

 $LangList = false
 $StringSet = array()
 $Language = false
 $AutoTranslationsWereLoaded = false
 $BlockSettings = false
 $Cache = false
 $CachedMultyFS = false
 $PageJS = false
 $Security = false
 $String = false

Detailed Description

Class provides language dependent substitutions for strings.

Author
Dodonov A.A.

Definition at line 26 of file lang.php.

Constructor & Destructor Documentation

__construct ( )

Constructor.

Exceptions
ExceptionAn exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 107 of file lang.php.

{
try
{
$this->BlockSettings = get_package_object( 'settings::settings' , 'last' , __FILE__ );
$this->Cache = get_package( 'cache' , 'last' , __FILE__ );
$this->CachedMultyFS = get_package( 'cached_multy_fs' , 'last' , __FILE__ );
$this->PageJS = get_package( 'page::page_js' , 'last' , __FILE__ );
$this->Security = get_package( 'security' , 'last' , __FILE__ );
$this->String = get_package( 'string' , 'last' , __FILE__ );
$this->get_locale();
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}

Member Function Documentation

dispatch_string_data (   $RawData)

Function processes localisation string.

Parameters
$RawData- Content of the string file.
Returns
list( $StringAlias , $Condition , $Translation )
Exceptions
ExceptionAn exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 228 of file lang.php.

{
try
{
$tmp1 = explode( '=' , $RawData );
return( array( $tmp1[ 0 ] , 'default' , $tmp1[ 1 ] ) );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
get_client_language ( )

Function retrieves client's language from the HTTP request.

Returns
Signature of the language.
Exceptions
ExceptionAn exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 144 of file lang.php.

{
$Splits = array();
foreach( explode( ',' , @$_SERVER[ 'HTTP_ACCEPT_LANGUAGE' ] ) as $Lang )
{
$Pattern = '/^(?P<primarytag>[a-zA-Z]{2,8})'.
'(?:-(?P<subtag>[a-zA-Z]{2,8}))?(?:(?:;q=)'.
'(?P<quantifier>\d\.\d))?$/';
if( preg_match( $Pattern , $Lang , $Splits ) )
{
return( $Splits[ 'primarytag' ] );
}
}
return( false );
}
get_list_of_languages ( )

Function returns list of supported languages.

Returns
Array of languages.
Exceptions
ExceptionAn exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 445 of file lang.php.

{
try
{
$Languages = file_get_contents( dirname( __FILE__ ).'/conf/cf_lang_list' );
$Languages = str_replace( "\r" , "\n" , $Languages );
$Languages = str_replace( "\n\n" , "\n" , $Languages );
$Languages = explode( "\n" , $Languages );
return( $Languages );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
get_locale ( )

Function returns current language.

Returns
Signature of the language.
Exceptions
ExceptionAn exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 480 of file lang.php.

{
try
{
if( $this->Language === false )
{
if( $this->LangList === false )
{
$this->LangList = $this->get_list_of_languages();
}
if( $this->Security->get_c( 'client_lang' ) )
{
$this->Language = $this->Security->get_c( 'client_lang' , 'command' );
}
elseif( ( $Key = array_search( $this->get_client_language() , $this->LangList ) ) !== false )
{
$this->Language = $this->LangList[ $Key ];
}
else
{
$this->Language = $this->CachedMultyFS->get_config( __FILE__ , 'cf_locale_conf' );
}
}
return( $this->Language );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
get_string (   $StringAlias,
  $Value = 'default' 
)

Function returns real string according to alias.

Parameters
$StringAlias- Alias of the requested string.
$Value- Default value.
Returns
Language dependent real string.
Exceptions
ExceptionAn exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 731 of file lang.php.

{
try
{
if( isset( $this->StringSet[ $StringAlias ] ) === false ||
( $Value == 'default' && isset( $this->StringSet[ $StringAlias ][ $Value ] ) === false ) )
{
return( $StringAlias );
}
if( $Value == 'default' && isset( $this->StringSet[ $StringAlias ][ 'default' ] ) !== false )
{
return( $this->StringSet[ $StringAlias ][ 'default' ] );
}
return( $StringAlias );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
include_strings (   $PackageName,
  $PackageVersion = 'last' 
)

Function includes list of string constants.

Parameters
$PackageName- Package name.
$PackageVersion- Package version.
Exceptions
Exception- An exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 264 of file lang.php.

{
try
{
$Path = _get_package_relative_path_ex( $PackageName , $PackageVersion );
$TopPackageName = _get_top_package_name( $PackageName );
$LanguageFilePath = $Path.'/res/lang/'.$TopPackageName.'.'.$this->Language;
if( file_exists( $LanguageFilePath ) )
{
$RawData = $this->CachedMultyFS->file_get_contents( $LanguageFilePath , 'cleaned' );
$this->load_data( $RawData );
}
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
include_strings_js (   $PackageName,
  $PackageVersion = 'last' 
)

Function includes list of string constants.

Parameters
$PackageName- Package name.
$PackageVersion- Package version.
Exceptions
ExceptionAn exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 401 of file lang.php.

{
try
{
$Path = _get_package_relative_path_ex( $PackageName , $PackageVersion );
$TopPackageName = _get_top_package_name( $PackageName );
$LangFilePath = $Path.'/res/lang/'.$TopPackageName.'.'.$this->Language;
if( $this->CachedMultyFS->file_exists( $LangFilePath ) )
{
$ScriptPath = $Path.'/include/js/'.$TopPackageName.'.'.$this->Language.'.js';
mkdir_ex( $Path.'/include/' );
mkdir_ex( $Path.'/include/js/' );
$this->compile_lang_javascript( $LangFilePath , $ScriptPath );
$this->PageJS->add_javascript( '{http_host}/'.$ScriptPath );
}
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
load_data (   $RawData)

Function loads language data.

Parameters
$RawData- Content of the string file.
Exceptions
ExceptionAn exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 530 of file lang.php.

{
try
{
if( strlen( $RawData ) )
{
$RawData = explode( "\n" , $RawData );
foreach( $RawData as $rd )
{
list( $StringAlias , $Condition , $Translation ) = $this->dispatch_string_data( $rd );
if( isset( $this->StringSet[ $StringAlias ] ) === false )
{
$this->StringSet[ $StringAlias ] = array();
}
$this->StringSet[ $StringAlias ][ $Condition ] = $Translation;
}
}
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
load_translations ( )

Function loads all language data of the page.

Exceptions
ExceptionAn exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 686 of file lang.php.

{
try
{
if( $this->AutoTranslationsWereLoaded === false )
{
$this->get_locale();
$this->force_load_translations();
$this->AutoTranslationsWereLoaded = true;
}
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
load_translations_from_file (   $LanguageFilePath)

Function loads language data from file.

Parameters
$LanguageFilePath- Path to file.
Exceptions
ExceptionAn exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 575 of file lang.php.

{
try
{
if( file_exists( $LanguageFilePath ) )
{
$RawData = $this->CachedMultyFS->file_get_contents( $LanguageFilePath , 'cleaned' );
$this->load_data( $RawData );
}
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
load_translations_from_package (   $PackageName,
  $PackageVersion 
)

Function loads language data from file.

Parameters
$PackageName- Package name.
$PackageVersion- Package version.
Exceptions
ExceptionAn exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 613 of file lang.php.

{
try
{
$PackagePath = _get_package_relative_path_ex( $PackageName , $PackageVersion );
$TopPackageName = _get_top_package_name( $PackageName );
$this->load_translations_from_file( "$PackageName/res/lang/$TopPackageName.$this->Language" );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}
pre_generation (   $Options)

Function executes before any page generating actions took place.

Parameters
$Options- Settings.
Exceptions
ExceptionAn exception of this type is thrown.
Author
Dodonov A.A.

Definition at line 181 of file lang.php.

{
try
{
$Path = _get_package_relative_path_ex( 'lang' , '1.0.0' );
$Path = $Path.'/include/js/lang.core.'.$this->Language.'.js';
if( $this->CachedMultyFS->file_exists( $Path ) === false )
{
$this->PageJS->add_javascript( '{http_host}/'.$Path );
$Content = $this->CachedMultyFS->get_template( __FILE__ , 'lang.core.js.tpl' );
$Content = str_replace( '{locale}' , $this->Language , $Content );
$this->CachedMultyFS->file_put_contents( $Path , $Content );
}
$this->PageJS->add_javascript( '{http_host}/'.$Path );
$this->include_strings_js( 'lang' );
}
catch( Exception $e )
{
$a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
}
}

Field Documentation

$AutoTranslationsWereLoaded = false

Were fetched package's translation loaded.

Author
Dodonov A.A.

Definition at line 74 of file lang.php.

$BlockSettings = false

Cached packages.

Author
Dodonov A.A.

Definition at line 86 of file lang.php.

$Cache = false

Definition at line 87 of file lang.php.

$CachedMultyFS = false

Definition at line 88 of file lang.php.

$LangList = false

List of languages.

Author
Dodonov A.A.

Definition at line 38 of file lang.php.

$Language = false

Language's signature.

Author
Dodonov A.A.

Definition at line 62 of file lang.php.

$PageJS = false

Definition at line 89 of file lang.php.

$Security = false

Definition at line 90 of file lang.php.

$String = false

Definition at line 91 of file lang.php.

$StringSet = array()

List of the localized strings.

Author
Dodonov A.A.

Definition at line 50 of file lang.php.


The documentation for this class was generated from the following file: