PHP Class Pop\I18n\I18n

Author: Nick Sagona, III ([email protected])
显示文件 Open project: nicksagona/PopPHP Class Usage Examples

Protected Properties

Property Type Description
$content array Language content
$language string Default system language
$locale string Default system locale

Public Methods

Method Description
__ ( string $str, string | array $params = null ) Return the translated string
__construct ( string $lang = null ) : I18n Constructor
_e ( string $str, string | array $params = null ) : void Echo the translated string.
createXmlFile ( array $lang, array $locales, string $file ) : void Create an XML language file from an array of data.
createXmlFromText ( string $source, string $output, string $target = null ) : void Create an XML document fragment from a source file and an output file, each entry separated by a new line
factory ( string $lang = null ) : I18n Static method to load the I18n object.
getLanguage ( ) : string Get current language setting.
getLanguages ( string $dir = null ) : array Get languages from the XML files.
getLocale ( ) : string Get current locale setting.
loadFile ( string $langFile ) : void Load language content from an XML file.

Protected Methods

Method Description
loadCurrentLanguage ( ) : void Get language content from the XML file.
translate ( string $str, string | array $params = null ) : mixed Translate and return the string.

Method Details

__() public method

Return the translated string
public __ ( string $str, string | array $params = null )
$str string
$params string | array

__construct() public method

Instantiate the I18n object.
public __construct ( string $lang = null ) : I18n
$lang string
return I18n

_e() public method

Echo the translated string.
public _e ( string $str, string | array $params = null ) : void
$str string
$params string | array
return void

createXmlFile() public static method

The format of the parameters should be as follows: $lang = array( 'src' => 'en', 'output' => 'de', 'name' => 'German', 'native' => 'Deutsch' ); $locales = array( array( 'region' => 'DE', 'name' => 'Germany', 'native' => 'Deutschland', 'text' => array( array( 'source' => 'This field is required.', 'output' => 'Dieses Feld ist erforderlich.' ), ... ) ), ... );
public static createXmlFile ( array $lang, array $locales, string $file ) : void
$lang array
$locales array
$file string
return void

createXmlFromText() public static method

Create an XML document fragment from a source file and an output file, each entry separated by a new line
public static createXmlFromText ( string $source, string $output, string $target = null ) : void
$source string
$output string
$target string
return void

factory() public static method

Static method to load the I18n object.
public static factory ( string $lang = null ) : I18n
$lang string
return I18n

getLanguage() public method

Get current language setting.
public getLanguage ( ) : string
return string

getLanguages() public static method

Get languages from the XML files.
public static getLanguages ( string $dir = null ) : array
$dir string
return array

getLocale() public method

Get current locale setting.
public getLocale ( ) : string
return string

loadCurrentLanguage() protected method

Get language content from the XML file.
protected loadCurrentLanguage ( ) : void
return void

loadFile() public method

Load language content from an XML file.
public loadFile ( string $langFile ) : void
$langFile string
return void

translate() protected method

Translate and return the string.
protected translate ( string $str, string | array $params = null ) : mixed
$str string
$params string | array
return mixed

Property Details

$content protected_oe property

Language content
protected array $content
return array

$language protected_oe property

Default system language
protected string $language
return string

$locale protected_oe property

Default system locale
protected string $locale
return string