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
76a04ac4
Commit
76a04ac4
authored
3 years ago
by
Tim van Dijen
Browse files
Options
Downloads
Patches
Plain Diff
Rewrite Localization using symfony/filesystem
parent
b326e5b3
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/SimpleSAML/Locale/Localization.php
+21
-8
21 additions, 8 deletions
lib/SimpleSAML/Locale/Localization.php
with
21 additions
and
8 deletions
lib/SimpleSAML/Locale/Localization.php
+
21
−
8
View file @
76a04ac4
...
...
@@ -10,10 +10,13 @@ declare(strict_types=1);
namespace
SimpleSAML\Locale
;
use
Exception
;
use
Gettext\Translations
;
use
Gettext\Translator
;
use
SimpleSAML\Configuration
;
use
SimpleSAML\Logger
;
use
Symfony\Component\Filesystem\Filesystem
;
use
Symfony\Component\HttpFoundation\File\File
;
class
Localization
{
...
...
@@ -66,6 +69,11 @@ class Localization
*/
private
string
$langcode
;
/**
* @var \Symfony\Component\Filesystem\Filesystem;
*/
private
Filesystem
$fileSystem
;
/**
* Constructor
...
...
@@ -74,6 +82,7 @@ class Localization
*/
public
function
__construct
(
Configuration
$configuration
)
{
$this
->
fileSystem
=
new
Filesystem
();
$this
->
configuration
=
$configuration
;
/** @var string $locales */
$locales
=
$this
->
configuration
->
resolvePath
(
'locales'
);
...
...
@@ -186,7 +195,7 @@ class Localization
// Locale for default language missing even, error out
$error
=
"Localization directory '
$langPath
' missing/broken for langcode '
$langcode
' and domain '
$domain
'"
;
Logger
::
critical
(
$_SERVER
[
'PHP_SELF'
]
.
' - '
.
$error
);
throw
new
\
Exception
(
$error
);
throw
new
Exception
(
$error
);
}
...
...
@@ -217,7 +226,7 @@ class Localization
):
void
{
try
{
$langPath
=
$this
->
getLangPath
(
$domain
);
}
catch
(
\
Exception
$e
)
{
}
catch
(
Exception
$e
)
{
$error
=
"Something went wrong when trying to get path to language file, cannot load domain '
$domain
'."
;
Logger
::
debug
(
$_SERVER
[
'PHP_SELF'
]
.
' - '
.
$error
);
if
(
$catchException
)
{
...
...
@@ -227,14 +236,18 @@ class Localization
throw
$e
;
}
}
$poFile
=
$domain
.
'.po'
;
$
poPath
=
$langPath
.
$poFile
;
if
(
file_exists
(
$po
Path
)
&&
is_r
eadable
(
$poPath
))
{
$translations
=
Translations
::
fromPoFile
(
$
po
Path
);
$
file
=
new
File
(
$langPath
.
$domain
.
'.po'
)
;
if
(
$this
->
fileSystem
->
exists
(
$file
->
getReal
Path
()
)
&&
$file
->
isR
eadable
())
{
$translations
=
Translations
::
fromPoFile
(
$
file
->
getReal
Path
()
);
$this
->
translator
->
loadTranslations
(
$translations
);
}
else
{
$error
=
"Localization file '
$poFile
' not found in '
$langPath
', falling back to default"
;
Logger
::
debug
(
$_SERVER
[
'PHP_SELF'
]
.
' - '
.
$error
);
Logger
::
debug
(
sprintf
(
"%s - Localization file '%s' not found or not readable in '%s', falling back to default"
,
$_SERVER
[
'PHP_SELF'
],
$file
->
getfileName
(),
$langPath
,
));
}
}
...
...
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