Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
simplesamlphp
Manage
Activity
Members
Labels
Plan
Jira
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Perun
Perun ProxyIdP
v1
simplesamlphp
Commits
61ecaba3
Commit
61ecaba3
authored
9 years ago
by
Jaime Perez Crespo
Browse files
Options
Downloads
Patches
Plain Diff
Fix phpdoc for \SimpleSAML\Locale\Translate.
parent
2a749ff8
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/SimpleSAML/Locale/Translate.php
+65
-58
65 additions, 58 deletions
lib/SimpleSAML/Locale/Translate.php
with
65 additions
and
58 deletions
lib/SimpleSAML/Locale/Translate.php
+
65
−
58
View file @
61ecaba3
...
@@ -32,8 +32,8 @@ class Translate {
...
@@ -32,8 +32,8 @@ class Translate {
/**
/**
* Constructor
* Constructor
*
*
* @param $configuration
Configuration object
* @param
\SimpleSAML_Configuration
$configuration Configuration object
* @param $defaultDictionary
The default dictionary where tags will come from.
* @param
string|null
$defaultDictionary The default dictionary where tags will come from.
*/
*/
function
__construct
(
\SimpleSAML_Configuration
$configuration
,
$defaultDictionary
=
NULL
)
{
function
__construct
(
\SimpleSAML_Configuration
$configuration
,
$defaultDictionary
=
NULL
)
{
$this
->
configuration
=
$configuration
;
$this
->
configuration
=
$configuration
;
...
@@ -54,13 +54,11 @@ class Translate {
...
@@ -54,13 +54,11 @@ class Translate {
/**
/**
*
R
etrieve a dictionary.
*
This method r
etrieve
s
a dictionary
with the name given
.
*
*
* This function retrieves a dictionary with the given name.
* @param string $name The name of the dictionary, as the filename in the dictionary directory, without the
*
* '.php' ending.
* @param $name The name of the dictionary, as the filename in the dictionary directory,
* @return array An associative array with the dictionary.
* without the '.php'-ending.
* @return An associative array with the dictionary.
*/
*/
private
function
getDictionary
(
$name
)
{
private
function
getDictionary
(
$name
)
{
assert
(
'is_string($name)'
);
assert
(
'is_string($name)'
);
...
@@ -84,13 +82,11 @@ class Translate {
...
@@ -84,13 +82,11 @@ class Translate {
/**
/**
* Retrieve a tag.
* This method retrieves a tag as an array with language => string mappings.
*
* This function retrieves a tag as an array with language => string mappings.
*
*
* @param $tag
The tag name. The tag name can also be on the form '{<dictionary>:<tag>}', to retrieve
* @param
string
$tag The tag name. The tag name can also be on the form '{<dictionary>:<tag>}', to retrieve
a tag
*
a tag
from the specific dictionary.
* from the specific dictionary.
* @return
As
associative array with language => string mappings, or
NULL
if the tag wasn't found.
* @return
array An
associative array with language => string mappings, or
null
if the tag wasn't found.
*/
*/
public
function
getTag
(
$tag
)
{
public
function
getTag
(
$tag
)
{
assert
(
'is_string($tag)'
);
assert
(
'is_string($tag)'
);
...
@@ -124,8 +120,10 @@ class Translate {
...
@@ -124,8 +120,10 @@ class Translate {
/**
/**
* Retrieve the preferred translation of a given text.
* Retrieve the preferred translation of a given text.
*
*
* @param $translations The translations, as an associative array with language => text mappings.
* @param array $translations The translations, as an associative array with language => text mappings.
* @return The preferred translation.
* @return string The preferred translation.
*
* @throws \Exception If there's no suitable translation.
*/
*/
public
function
getPreferredTranslation
(
$translations
)
{
public
function
getPreferredTranslation
(
$translations
)
{
assert
(
'is_array($translations)'
);
assert
(
'is_array($translations)'
);
...
@@ -154,15 +152,15 @@ class Translate {
...
@@ -154,15 +152,15 @@ class Translate {
}
}
/* We don't have anything to return. */
/* We don't have anything to return. */
throw
new
Exception
(
'Nothing to return from translation.'
);
throw
new
\
Exception
(
'Nothing to return from translation.'
);
}
}
/**
/**
* Translate
a
attribute
name
.
* Translate
the name of an
attribute.
*
*
* @param string $name
The attribute name.
* @param string $name The attribute name.
* @return string
The translated attribute name, or the original attribute name if no translation was found.
* @return string The translated attribute name, or the original attribute name if no translation was found.
*/
*/
public
function
getAttributeTranslation
(
$name
)
{
public
function
getAttributeTranslation
(
$name
)
{
...
@@ -193,24 +191,30 @@ class Translate {
...
@@ -193,24 +191,30 @@ class Translate {
/**
/**
* Translate a tag into the current language, with a fallback to english.
* Translate a tag into the current language, with a fallback to english.
*
*
* This function is used to look up a translation tag in dictionaries, and return the
* This function is used to look up a translation tag in dictionaries, and return the
translation into the current
*
translation into the current
language. If no translation into the current language can be
* language. If no translation into the current language can be
found, english will be tried, and if that fails,
*
found, english will be tried, and if that fails,
placeholder text will be returned.
* placeholder text will be returned.
*
*
* An array can be passed as the tag. In that case, the array will be assumed to be on the
* An array can be passed as the tag. In that case, the array will be assumed to be on the
form (language => text),
*
form (language => text),
and will be used as the source of translations.
* and will be used as the source of translations.
*
*
* This function can also do replacements into the translated tag. It will search the
* This function can also do replacements into the translated tag. It will search the translated tag for the keys
* translated tag for the keys provided in $replacements, and replace any found occurances
* provided in $replacements, and replace any found occurrences with the value of the key.
* with the value of the key.
*
*
* @param string|array $tag A tag name for the translation which should be looked up, or an
* @param string|array $tag A tag name for the translation which should be looked up, or an array with
* array with (language => text) mappings.
* (language => text) mappings.
* @param array $replacements An associative array of keys that should be replaced with
* @param array $replacements An associative array of keys that should be replaced with values in the translated
* values in the translated string.
* string.
* @param boolean $fallbackdefault Default translation to use as a fallback if no valid translation was found.
* @return string The translated tag, or a placeholder value if the tag wasn't found.
* @return string The translated tag, or a placeholder value if the tag wasn't found.
*/
*/
public
function
t
(
$tag
,
$replacements
=
array
(),
$fallbackdefault
=
true
,
$oldreplacements
=
array
(),
$striptags
=
FALSE
)
{
public
function
t
(
$tag
,
$replacements
=
array
(),
$fallbackdefault
=
true
,
$oldreplacements
=
array
(),
// TODO: remove this for 2.0
$striptags
=
FALSE
// TODO: remove this for 2.0
)
{
if
(
!
is_array
(
$replacements
))
{
if
(
!
is_array
(
$replacements
))
{
/* Old style call to t(...). Print warning to log. */
/* Old style call to t(...). Print warning to log. */
...
@@ -221,8 +225,8 @@ class Translate {
...
@@ -221,8 +225,8 @@ class Translate {
/* For backwards compatibility. */
/* For backwards compatibility. */
if
(
!
$replacements
&&
$this
->
getTag
(
$tag
)
===
NULL
)
{
if
(
!
$replacements
&&
$this
->
getTag
(
$tag
)
===
NULL
)
{
\SimpleSAML_Logger
::
warning
(
'Code which uses $fallbackdefault === FALSE shoul
s
be'
.
\SimpleSAML_Logger
::
warning
(
'Code which uses $fallbackdefault === FALSE shoul
d
be'
.
' updated to use the getTag
-
method instead.'
);
' updated to use the getTag
()
method instead.'
);
return
NULL
;
return
NULL
;
}
}
...
@@ -254,9 +258,11 @@ class Translate {
...
@@ -254,9 +258,11 @@ class Translate {
/**
/**
* Return the string that should be used when no translation was found.
* Return the string that should be used when no translation was found.
*
*
* @param $tag A name tag of the string that should be returned.
* @param string $tag A name tag of the string that should be returned.
* @param $fallbacktag If set to TRUE and string was not found in any languages, return
* @param boolean $fallbacktag If set to true and string was not found in any languages, return the tag itself. If
* the tag it self. If FALSE return NULL.
* false return null.
*
* @return string The string that should be used, or the tag name if $fallbacktag is set to false.
*/
*/
private
function
t_not_translated
(
$tag
,
$fallbacktag
)
{
private
function
t_not_translated
(
$tag
,
$fallbacktag
)
{
if
(
$fallbacktag
)
{
if
(
$fallbacktag
)
{
...
@@ -268,20 +274,21 @@ class Translate {
...
@@ -268,20 +274,21 @@ class Translate {
/**
/**
* You can include translation inline instead of putting translation
* Include a translation inline instead of putting translations in dictionaries. This function is recommended to be
* in dictionaries. This function is reccomended to only be used from dynamic
* used ONLU from variable data, or when the translation is already provided by an external source, as a database
* data, or when the translation is already provided from an external source, as
* or in metadata.
* a database or in metadata.
*
* @param string $tag The tag that has a translation
* @param array|string $translation The translation array
*
*
* @param $tag The tag that has a translation
* @throws \Exception If $translation is neither a string nor an array.
* @param $translation The translation array
*/
*/
public
function
includeInlineTranslation
(
$tag
,
$translation
)
{
public
function
includeInlineTranslation
(
$tag
,
$translation
)
{
if
(
is_string
(
$translation
))
{
if
(
is_string
(
$translation
))
{
$translation
=
array
(
'en'
=>
$translation
);
$translation
=
array
(
'en'
=>
$translation
);
}
elseif
(
!
is_array
(
$translation
))
{
}
elseif
(
!
is_array
(
$translation
))
{
throw
new
Exception
(
"Inline translation should be string or array. Is "
.
gettype
(
$translation
)
.
" now!"
);
throw
new
\
Exception
(
"Inline translation should be string or array. Is "
.
gettype
(
$translation
)
.
" now!"
);
}
}
\SimpleSAML_Logger
::
debug
(
'Template: Adding inline language translation for tag ['
.
$tag
.
']'
);
\SimpleSAML_Logger
::
debug
(
'Template: Adding inline language translation for tag ['
.
$tag
.
']'
);
...
@@ -289,13 +296,13 @@ class Translate {
...
@@ -289,13 +296,13 @@ class Translate {
}
}
/**
/**
* Include language file from the dictionaries directory.
* Include
a
language file from the dictionaries directory.
*
*
* @param
$file
File name of dictionary to include
* @param
string $file
File name of dictionary to include
* @param $otherConfig
Optionally provide a different configuration object than
* @param
\SimpleSAML_Configuration|null
$otherConfig Optionally provide a different configuration object than
the
*
the
one provided in the constructor to be used to find the di
ctionary directory.
* one provided in the constructor to be used to find the di
rectory of the dictionary. This allows to combine
*
This enables the possiblity of combining dictionaries inside simpleSAMLphp
*
dictionaries inside the SimpleSAMLphp main code distribution together with external dictionaries. Defaults to
*
distribution with external dictionaries
.
*
null
.
*/
*/
public
function
includeLanguageFile
(
$file
,
$otherConfig
=
null
)
{
public
function
includeLanguageFile
(
$file
,
$otherConfig
=
null
)
{
...
@@ -314,10 +321,10 @@ class Translate {
...
@@ -314,10 +321,10 @@ class Translate {
/**
/**
* Read a dictionary file in
json
format.
* Read a dictionary file in
JSON
format.
*
*
* @param string $filename
The absolute path to the dictionary file, minus the .definition.json ending.
* @param string $filename The absolute path to the dictionary file, minus the .definition.json ending.
* @return array
T
he translation
array from
the file.
* @return array
An array holding all t
he translation
s in
the file.
*/
*/
private
function
readDictionaryJSON
(
$filename
)
{
private
function
readDictionaryJSON
(
$filename
)
{
$definitionFile
=
$filename
.
'.definition.json'
;
$definitionFile
=
$filename
.
'.definition.json'
;
...
@@ -347,8 +354,8 @@ class Translate {
...
@@ -347,8 +354,8 @@ class Translate {
/**
/**
* Read a dictionary file in PHP format.
* Read a dictionary file in PHP format.
*
*
* @param string $filename
The absolute path to the dictionary file.
* @param string $filename The absolute path to the dictionary file.
* @return array
T
he translation
array from
the file.
* @return array
An array holding all t
he translation
s in
the file.
*/
*/
private
function
readDictionaryPHP
(
$filename
)
{
private
function
readDictionaryPHP
(
$filename
)
{
$phpFile
=
$filename
.
'.php'
;
$phpFile
=
$filename
.
'.php'
;
...
@@ -367,8 +374,8 @@ class Translate {
...
@@ -367,8 +374,8 @@ class Translate {
/**
/**
* Read a dictionary file.
* Read a dictionary file.
*
*
* @param $filename
The absolute path to the dictionary file.
* @param
string
$filename The absolute path to the dictionary file.
* @return
The translation array which was found in the dictionary
file.
* @return
array An array holding all the translations in the
file.
*/
*/
private
function
readDictionaryFile
(
$filename
)
{
private
function
readDictionaryFile
(
$filename
)
{
assert
(
'is_string($filename)'
);
assert
(
'is_string($filename)'
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment