57 $backtrace = debug_backtrace();
58 $where = $backtrace[0][
'file'].
':'.$backtrace[0][
'line'];
60 'Deprecated use of new SimpleSAML\Locale\Translate(...) at '.$where.
61 '. The last parameter is now a dictionary name, which should not end in ".php".' 92 assert(is_string(
$name));
94 if (!array_key_exists(
$name, $this->dictionaries)) {
95 $sepPos = strpos(
$name,
':');
96 if ($sepPos !==
false) {
98 $fileName = substr(
$name, $sepPos + 1);
101 $dictDir = $this->configuration->getPathValue(
'dictionarydir',
'dictionaries/');
108 return $this->dictionaries[
$name];
122 assert(is_string(
$tag));
125 if (array_key_exists(
$tag, $this->langtext)) {
126 return $this->langtext[
$tag];
130 if (substr(
$tag, 0, 1) ===
'{' && preg_match(
'/^{((?:\w+:)?\w+?):(.*)}$/D',
$tag, $matches)) {
131 $dictionary = $matches[1];
135 if ($dictionary === null) {
142 if (!array_key_exists(
$tag, $dictionary)) {
146 return $dictionary[
$tag];
161 assert(is_array($translations));
164 $selected_language = $this->
language->getLanguage();
165 if (array_key_exists($selected_language, $translations)) {
166 return $translations[$selected_language];
170 $default_language = $this->
language->getDefaultLanguage();
171 if (array_key_exists($default_language, $translations)) {
172 return $translations[$default_language];
176 if (array_key_exists(
'en', $translations)) {
177 return $translations[
'en'];
181 if (count($translations) > 0) {
187 throw new \Exception(
'Nothing to return from translation.');
201 $normName = strtolower(
$name);
202 $normName = str_replace(
":",
"_", $normName);
205 $extraDict = $this->configuration->getString(
'attributes.extradictionary', null);
206 if ($extraDict !== null) {
208 if (array_key_exists($normName, $dict)) {
215 if (array_key_exists(
'attribute_'.$normName, $dict)) {
261 $replacements = array(),
263 $fallbackdefault =
true,
265 $oldreplacements = array(),
269 $backtrace = debug_backtrace();
270 $where = $backtrace[0][
'file'].
':'.$backtrace[0][
'line'];
271 if (!$fallbackdefault) {
273 'Deprecated use of new SimpleSAML\Locale\Translate::t(...) at '.$where.
274 '. This parameter will go away, the fallback will become' .
275 ' identical to the $tag in 2.0.' 278 if (!is_array($replacements)) {
283 'Deprecated use of SimpleSAML\Locale\Translate::t(...) at '.$where.
284 '. Please update the code to use the new style of parameters.' 288 if (!$replacements && $this->
getTag(
$tag) === null) {
290 'Code which uses $fallbackdefault === FALSE should be updated to use the getTag() method instead.' 295 $replacements = $oldreplacements;
298 if (is_array(
$tag)) {
301 'Deprecated use of new SimpleSAML\Locale\Translate::t(...) at '.$where.
302 '. The $tag-parameter can only be a string in 2.0.' 306 if ($tagData === null) {
315 foreach ($replacements as $k => $v) {
320 $translated = str_replace($k, $v, $translated);
338 return 'not translated ('.$tag.
')';
357 if (is_string($translation)) {
358 $translation = array(
'en' => $translation);
359 } elseif (!is_array($translation)) {
360 throw new \Exception(
"Inline translation should be string or array. Is ".gettype($translation).
" now!");
364 $this->langtext[
$tag] = $translation;
379 if (!empty($otherConfig)) {
380 $filebase = $otherConfig->getPathValue(
'dictionarydir',
'dictionaries/');
382 $filebase = $this->configuration->getPathValue(
'dictionarydir',
'dictionaries/');
387 $this->langtext = array_merge($this->langtext,
$lang);
400 $definitionFile =
$filename.
'.definition.json';
401 assert(file_exists($definitionFile));
403 $fileContent = file_get_contents($definitionFile);
404 $lang = json_decode($fileContent,
true);
411 $translationFile =
$filename.
'.translation.json';
412 if (file_exists($translationFile)) {
413 $fileContent = file_get_contents($translationFile);
414 $moreTrans = json_decode($fileContent,
true);
415 if (!empty($moreTrans)) {
416 $lang = array_merge_recursive(
$lang, $moreTrans);
434 assert(file_exists($phpFile));
459 $jsonFile =
$filename.
'.definition.json';
460 if (file_exists($jsonFile)) {
465 if (file_exists($phpFile)) {
470 $_SERVER[
'PHP_SELF'].
' - Template: Could not find dictionary file at ['.
$filename.
']' 480 if (func_num_args() === 1) {
484 $args = array_slice(func_get_args(), 1);
486 return strtr(
$text, is_array($args[0]) ? $args[0] : $args);
494 if (func_num_args() === 3) {
498 $args = array_slice(func_get_args(), 3);
500 return strtr(
$text, is_array($args[0]) ? $args[0] : $args);
517 if (!is_array($translations) || $translations === null) {
525 if (isset($translations[
$context[
'currentLanguage']])) {
526 return $translations[$context[
'currentLanguage']];
531 $langcfg = $sspcfg->getConfigItem(
'language', null);
532 $priorities = array();
534 $priorities = $langcfg->getArray(
'priorities', array());
537 foreach ($priorities[$context[
'currentLanguage']] as
$lang) {
538 if (isset($translations[$lang])) {
539 return $translations[
$lang];
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']
$dictionaries
Associative array of dictionaries.
static noop($tag)
Mark a string for translation without translating it.
readDictionaryJSON($filename)
Read a dictionary file in JSON format.
static getModuleDir($module)
Retrieve the base directory for a module.
$defaultDictionary
The default dictionary.
includeInlineTranslation($tag, $translation)
Include a translation inline instead of putting translations in dictionaries.
if($modEnd===false) $module
static translateSingularGettext($original)
getStringNotTranslated($tag, $fallbacktag)
Return the string that should be used when no translation was found.
readDictionaryPHP($filename)
Read a dictionary file in PHP format.
static translatePluralGettext($original, $plural, $value)
getPreferredTranslation($translations)
Retrieve the preferred translation of a given text.
includeLanguageFile($file, $otherConfig=null)
Include a language file from the dictionaries directory.
__construct(\SimpleSAML_Configuration $configuration, $defaultDictionary=null)
Constructor.
t( $tag, $replacements=array(), $fallbackdefault=true, $oldreplacements=array(), $striptags=false)
Translate a tag into the current language, with a fallback to english.
getTag($tag)
This method retrieves a tag as an array with language => string mappings.
readDictionaryFile($filename)
Read a dictionary file.
getDictionary($name)
This method retrieves a dictionary with the name given.
for($i=1; $i<=count($kw_cases_sel); $i+=1) $lang
if(function_exists('posix_getuid') &&posix_getuid()===0) if(!array_key_exists('t', $options)) $tag
static getInstance($instancename='simplesaml')
Get a configuration file by its instance name.
getAttributeTranslation($name)
Translate the name of an attribute.
static translateFromArray($context, $translations)
Pick a translation from a given array of translations for the current language.
getLanguage()
Return the internal language object used by this translator.