Overview

Namespaces

  • None
  • Peg
    • Cli
      • Commands
    • Config
    • Custom
      • Command
        • Action
          • Generate
          • Parse
      • CommandLine
      • Config
      • Localization
      • Utilities
    • Lib
      • Definitions
        • Element
      • Generator
      • Lexers
      • Plugins
      • Signals
        • Data
          • Definitions
          • Lexers
        • Type
  • PHP

Classes

  • Language
  • LanguageCode
  • Overview
  • Namespace
  • Class
  • Tree
  • Todo

Class Language

Defines the language class used for translating system strings by using po files for different languages.

Namespace: Peg\Custom\Localization
Located at src/Localization/Language.php
Methods summary
public
# __construct( string $directory, string $language = null )

Initialize the language class for translating strings.

Initialize the language class for translating strings.

Parameters

$directory
string
$directory Path to directory that holds po files.
$language
string
$language The language code from \Peg\Custom\Localization\LanguageCode

Throws

Exception
If language directory doesn't exists.
public string
# GetLanguage( )

Current language used for translation output.

Current language used for translation output.

Returns

string
One of the values from \Peg\Custom\Localization\LanguageCode
public string
# GetSystemLangauge( )

Gets the current system language.

Gets the current system language.

Returns

string
One of the values from \Peg\Custom\Localization\LanguageCode

Todo

Implement also for microsoft windows.
public
# SetLanguage( string $language = null )

Assings the language for translation output. If no language is given the system one is assigned.

Assings the language for translation output. If no language is given the system one is assigned.

Parameters

$language
string
$language One of the values from \Peg\Custom\Localization\LanguageCode
public string
# Translate( string $text )

Translates a given text to the currently language set.

Translates a given text to the currently language set.

Parameters

$text
string
$text String to translate.

Returns

string
Translated text or original if no translation found.
public array
# PoParser( string $file )

Parses a .po file generated by gettext tools.

Parses a .po file generated by gettext tools.

Parameters

$file
string
$file The path of the po translations file.

Returns

array
In the format array["original text"] = "translation"
PEG Api API documentation generated by ApiGen 2.8.0