ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
SimpleSAML\Locale\Localization Class Reference
+ Collaboration diagram for SimpleSAML\Locale\Localization:

Public Member Functions

 __construct (\SimpleSAML_Configuration $configuration)
 Constructor. More...
 
 getLocaleDir ()
 Dump the default locale directory. More...
 
 getDomainLocaleDir ($domain)
 Get the default locale dir for a specific module aka. More...
 
 addModuleDomain ($module, $localeDir=null)
 
 addDomain ($localeDir, $domain)
 
 getLangPath ($domain=self::DEFAULT_DOMAIN)
 
 isI18NBackendDefault ()
 Test to check if backend is set to default. More...
 
 getRegisteredDomains ()
 Show which domains are registered. More...
 

Data Fields

const DEFAULT_DOMAIN = 'messages'
 The default gettext domain. More...
 
const SSP_I18N_BACKEND = 'SimpleSAMLphp'
 Old internationalization backend included in SimpleSAMLphp. More...
 
const GETTEXT_I18N_BACKEND = 'gettext/gettext'
 An internationalization backend implemented purely in PHP. More...
 
 $i18nBackend
 The language backend to use. More...
 

Private Member Functions

 setupTranslator ()
 Setup the translator. More...
 
 loadGettextGettextFromPO ($domain=self::DEFAULT_DOMAIN, $catchException=true)
 Load translation domain from Gettext/Gettext using .po. More...
 
 setupL10N ()
 Set up L18N if configured or fallback to old system. More...
 

Private Attributes

 $configuration
 
 $localeDir
 The default locale directory. More...
 
 $localeDomainMap = array()
 Where specific domains are stored. More...
 
 $translator
 Pointer to currently active translator. More...
 
 $language
 Pointer to current Language. More...
 
 $langcode
 Language code representing the current Language. More...
 

Detailed Description

Definition at line 15 of file Localization.php.

Constructor & Destructor Documentation

◆ __construct()

SimpleSAML\Locale\Localization::__construct ( \SimpleSAML_Configuration  $configuration)

Constructor.

Parameters
\SimpleSAML_Configuration$configurationConfiguration object

Definition at line 75 of file Localization.php.

76 {
77 $this->configuration = $configuration;
78 $this->localeDir = $this->configuration->resolvePath('locales');
79 $this->language = new Language($configuration);
80 $this->langcode = $this->language->getPosixLanguage($this->language->getLanguage());
81 $this->i18nBackend = $this->configuration->getString('language.i18n.backend', self::SSP_I18N_BACKEND);
82 $this->setupL10N();
83 }
setupL10N()
Set up L18N if configured or fallback to old system.

References SimpleSAML\Locale\Localization\$configuration, and SimpleSAML\Locale\Localization\setupL10N().

+ Here is the call graph for this function:

Member Function Documentation

◆ addDomain()

SimpleSAML\Locale\Localization::addDomain (   $localeDir,
  $domain 
)

Definition at line 130 of file Localization.php.

131 {
132 $this->localeDomainMap[$domain] = $localeDir;
133 \SimpleSAML\Logger::debug("Localization: load domain '$domain' at '$localeDir'");
135 }
if(!array_key_exists('domain', $_REQUEST)) $domain
Definition: resume.php:8
loadGettextGettextFromPO($domain=self::DEFAULT_DOMAIN, $catchException=true)
Load translation domain from Gettext/Gettext using .po.
$localeDir
The default locale directory.
static debug($string)
Definition: Logger.php:211

References $domain, SimpleSAML\Locale\Localization\$localeDir, SimpleSAML\Logger\debug(), and SimpleSAML\Locale\Localization\loadGettextGettextFromPO().

Referenced by SimpleSAML\Locale\Localization\addModuleDomain(), and SimpleSAML\Locale\Localization\setupL10N().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addModuleDomain()

SimpleSAML\Locale\Localization::addModuleDomain (   $module,
  $localeDir = null 
)

Definition at line 114 of file Localization.php.

115 {
116 if (!$localeDir) {
118 }
120 }
addDomain($localeDir, $domain)
getDomainLocaleDir($domain)
Get the default locale dir for a specific module aka.
if($modEnd===false) $module
Definition: module.php:59

References SimpleSAML\Locale\Localization\$localeDir, $module, SimpleSAML\Locale\Localization\addDomain(), and SimpleSAML\Locale\Localization\getDomainLocaleDir().

+ Here is the call graph for this function:

◆ getDomainLocaleDir()

SimpleSAML\Locale\Localization::getDomainLocaleDir (   $domain)

Get the default locale dir for a specific module aka.

domain

Parameters
string$domainName of module/domain

Definition at line 100 of file Localization.php.

101 {
102 $localeDir = $this->configuration->resolvePath('modules') . '/' . $domain . '/locales';
103 return $localeDir;
104 }

References $domain, and SimpleSAML\Locale\Localization\$localeDir.

Referenced by SimpleSAML\Locale\Localization\addModuleDomain().

+ Here is the caller graph for this function:

◆ getLangPath()

SimpleSAML\Locale\Localization::getLangPath (   $domain = self::DEFAULT_DOMAIN)

Definition at line 143 of file Localization.php.

144 {
145 $langcode = explode('_', $this->langcode);
146 $langcode = $langcode[0];
147 $localeDir = $this->localeDomainMap[$domain];
148 $langPath = $localeDir.'/'.$langcode.'/LC_MESSAGES/';
149 \SimpleSAML\Logger::debug("Trying langpath for '$langcode' as '$langPath'");
150 if (is_dir($langPath) && is_readable($langPath)) {
151 return $langPath;
152 }
153
154 // Some langcodes have aliases..
155 $alias = $this->language->getLanguageCodeAlias($langcode);
156 if (isset($alias)) {
157 $langPath = $localeDir.'/'.$alias.'/LC_MESSAGES/';
158 \SimpleSAML\Logger::debug("Trying langpath for alternative '$alias' as '$langPath'");
159 if (is_dir($langPath) && is_readable($langPath)) {
160 return $langPath;
161 }
162 }
163
164 // Language not found, fall back to default
165 $defLangcode = $this->language->getDefaultLanguage();
166 $langPath = $localeDir.'/'.$defLangcode.'/LC_MESSAGES/';
167 if (is_dir($langPath) && is_readable($langPath)) {
168 // Report that the localization for the preferred language is missing
169 $error = "Localization not found for langcode '$langcode' at '$langPath', falling back to langcode '".
170 $defLangcode."'";
171 \SimpleSAML\Logger::error($_SERVER['PHP_SELF'].' - '.$error);
172 return $langPath;
173 }
174
175 // Locale for default language missing even, error out
176 $error = "Localization directory missing/broken for langcode '$langcode' and domain '$domain'";
177 \SimpleSAML\Logger::critical($_SERVER['PHP_SELF'].' - '.$error);
178 throw new \Exception($error);
179 }
$langcode
Language code representing the current Language.
static critical($string)
Definition: Logger.php:144
static error($string)
Definition: Logger.php:166
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']

References $_SERVER, $domain, SimpleSAML\Locale\Localization\$langcode, SimpleSAML\Locale\Localization\$localeDir, SimpleSAML\Logger\critical(), SimpleSAML\Logger\debug(), and SimpleSAML\Logger\error().

Referenced by SimpleSAML\Locale\Localization\loadGettextGettextFromPO().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getLocaleDir()

SimpleSAML\Locale\Localization::getLocaleDir ( )

Dump the default locale directory.

Definition at line 89 of file Localization.php.

90 {
91 return $this->localeDir;
92 }

References SimpleSAML\Locale\Localization\$localeDir.

◆ getRegisteredDomains()

SimpleSAML\Locale\Localization::getRegisteredDomains ( )

Show which domains are registered.

Definition at line 261 of file Localization.php.

262 {
264 }
$localeDomainMap
Where specific domains are stored.

References SimpleSAML\Locale\Localization\$localeDomainMap.

◆ isI18NBackendDefault()

SimpleSAML\Locale\Localization::isI18NBackendDefault ( )

Test to check if backend is set to default.

(if false: backend unset/there's an error)

Definition at line 234 of file Localization.php.

235 {
236 if ($this->i18nBackend === $this::SSP_I18N_BACKEND) {
237 return true;
238 }
239 return false;
240 }

◆ loadGettextGettextFromPO()

SimpleSAML\Locale\Localization::loadGettextGettextFromPO (   $domain = self::DEFAULT_DOMAIN,
  $catchException = true 
)
private

Load translation domain from Gettext/Gettext using .po.

Note: Since Twig I18N does not support domains, all loaded files are merged. Use contexts if identical strings need to be disambiguated.

Parameters
string$domainName of domain
boolean$catchExceptionWhether to catch an exception on error or return early
Exceptions

Exception If something is wrong with the locale file for the domain and activated language

Definition at line 203 of file Localization.php.

204 {
205 try {
206 $langPath = $this->getLangPath($domain);
207 } catch (\Exception $e) {
208 $error = "Something went wrong when trying to get path to language file, cannot load domain '$domain'.";
209 \SimpleSAML\Logger::error($_SERVER['PHP_SELF'].' - '.$error);
210 if ($catchException) {
211 // bail out!
212 return;
213 } else {
214 throw $e;
215 }
216 }
217 $poFile = $domain.'.po';
218 $poPath = $langPath.$poFile;
219 if (file_exists($poPath) && is_readable($poPath)) {
220 $translations = Translations::fromPoFile($poPath);
221 $this->translator->loadTranslations($translations);
222 } else {
223 $error = "Localization file '$poFile' not found in '$langPath', falling back to default";
224 \SimpleSAML\Logger::error($_SERVER['PHP_SELF'].' - '.$error);
225 }
226 }
getLangPath($domain=self::DEFAULT_DOMAIN)

References $_SERVER, $domain, SimpleSAML\Logger\error(), and SimpleSAML\Locale\Localization\getLangPath().

Referenced by SimpleSAML\Locale\Localization\addDomain().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setupL10N()

SimpleSAML\Locale\Localization::setupL10N ( )
private

Set up L18N if configured or fallback to old system.

Definition at line 246 of file Localization.php.

247 {
248 if ($this->i18nBackend === self::SSP_I18N_BACKEND) {
249 \SimpleSAML\Logger::debug("Localization: using old system");
250 return;
251 }
252
253 $this->setupTranslator();
254 // setup default domain
255 $this->addDomain($this->localeDir, self::DEFAULT_DOMAIN);
256 }
setupTranslator()
Setup the translator.

References SimpleSAML\Locale\Localization\addDomain(), SimpleSAML\Logger\debug(), and SimpleSAML\Locale\Localization\setupTranslator().

Referenced by SimpleSAML\Locale\Localization\__construct().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setupTranslator()

SimpleSAML\Locale\Localization::setupTranslator ( )
private

Setup the translator.

Definition at line 185 of file Localization.php.

186 {
187 $this->translator = new Translator();
188 $this->translator->register();
189 }

Referenced by SimpleSAML\Locale\Localization\setupL10N().

+ Here is the caller graph for this function:

Field Documentation

◆ $configuration

SimpleSAML\Locale\Localization::$configuration
private

Definition at line 22 of file Localization.php.

Referenced by SimpleSAML\Locale\Localization\__construct().

◆ $i18nBackend

SimpleSAML\Locale\Localization::$i18nBackend

The language backend to use.

Definition at line 68 of file Localization.php.

◆ $langcode

SimpleSAML\Locale\Localization::$langcode
private

Language code representing the current Language.

Definition at line 62 of file Localization.php.

Referenced by SimpleSAML\Locale\Localization\getLangPath().

◆ $language

SimpleSAML\Locale\Localization::$language
private

Pointer to current Language.

Definition at line 57 of file Localization.php.

◆ $localeDir

◆ $localeDomainMap

SimpleSAML\Locale\Localization::$localeDomainMap = array()
private

Where specific domains are stored.

Definition at line 47 of file Localization.php.

Referenced by SimpleSAML\Locale\Localization\getRegisteredDomains().

◆ $translator

SimpleSAML\Locale\Localization::$translator
private

Pointer to currently active translator.

Definition at line 52 of file Localization.php.

◆ DEFAULT_DOMAIN

const SimpleSAML\Locale\Localization::DEFAULT_DOMAIN = 'messages'

The default gettext domain.

Definition at line 27 of file Localization.php.

◆ GETTEXT_I18N_BACKEND

const SimpleSAML\Locale\Localization::GETTEXT_I18N_BACKEND = 'gettext/gettext'

An internationalization backend implemented purely in PHP.

Definition at line 37 of file Localization.php.

◆ SSP_I18N_BACKEND

const SimpleSAML\Locale\Localization::SSP_I18N_BACKEND = 'SimpleSAMLphp'

Old internationalization backend included in SimpleSAMLphp.

Definition at line 32 of file Localization.php.


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