Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
syncEnrollments
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Yeray Santana Hualde
syncEnrollments
Commits
a536ceae
Commit
a536ceae
authored
Jun 22, 2011
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added default value to Lang::line()->get().
parent
eb3a5b0d
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
31 deletions
+18
-31
lang.php
system/lang.php
+18
-31
No files found.
system/lang.php
View file @
a536ceae
...
@@ -2,13 +2,6 @@
...
@@ -2,13 +2,6 @@
class
Lang
{
class
Lang
{
/**
* All of the loaded language files.
*
* @var array
*/
private
static
$loaded
=
array
();
/**
/**
* All of the loaded language lines.
* All of the loaded language lines.
*
*
...
@@ -55,24 +48,30 @@ class Lang {
...
@@ -55,24 +48,30 @@ class Lang {
}
}
/**
/**
* Get the language line
for a given language
.
* Get the language line.
*
*
* @param
string $language
* @param
mixed $default
* @return string
* @return string
*/
*/
public
function
get
(
$language
=
null
)
public
function
get
(
$default
=
null
)
{
if
(
is_null
(
$language
))
{
{
$language
=
Config
::
get
(
'application.language'
);
$language
=
Config
::
get
(
'application.language'
);
}
list
(
$file
,
$line
)
=
$this
->
parse
(
$this
->
key
);
list
(
$file
,
$line
)
=
$this
->
parse
(
$this
->
key
);
$this
->
load
(
$file
,
$language
);
$this
->
load
(
$file
,
$language
);
// --------------------------------------------------------------
// If the language file did not exist, return the default value.
// --------------------------------------------------------------
if
(
!
array_key_exists
(
$language
.
$file
,
static
::
$lines
))
{
return
$default
;
}
// --------------------------------------------------------------
// --------------------------------------------------------------
// Get the language line from the appropriate file array.
// Get the language line from the appropriate file array.
// If the line doesn't exist, return the default value.
// --------------------------------------------------------------
// --------------------------------------------------------------
if
(
array_key_exists
(
$line
,
static
::
$lines
[
$language
.
$file
]))
if
(
array_key_exists
(
$line
,
static
::
$lines
[
$language
.
$file
]))
{
{
...
@@ -80,7 +79,7 @@ class Lang {
...
@@ -80,7 +79,7 @@ class Lang {
}
}
else
else
{
{
throw
new
\Exception
(
"Language line [
$line
] does not exist for language [
$language
]"
)
;
return
$default
;
}
}
// --------------------------------------------------------------
// --------------------------------------------------------------
...
@@ -127,28 +126,16 @@ class Lang {
...
@@ -127,28 +126,16 @@ class Lang {
private
function
load
(
$file
,
$language
)
private
function
load
(
$file
,
$language
)
{
{
// --------------------------------------------------------------
// --------------------------------------------------------------
// If we have already loaded the language file, bail out.
// If we have already loaded the language file or the file
// doesn't exist, bail out.
// --------------------------------------------------------------
// --------------------------------------------------------------
if
(
in_array
(
$language
.
$file
,
static
::
$loaded
))
if
(
array_key_exists
(
$language
.
$file
,
static
::
$lines
)
or
!
file_exists
(
$path
=
APP_PATH
.
'lang/'
.
$language
.
'/'
.
$file
.
EXT
))
{
{
return
;
return
;
}
}
// --------------------------------------------------------------
// Load the language file into the array of lines. The array
// is keyed by the language and file name.
// --------------------------------------------------------------
if
(
file_exists
(
$path
=
APP_PATH
.
'lang/'
.
$language
.
'/'
.
$file
.
EXT
))
{
static
::
$lines
[
$language
.
$file
]
=
require
$path
;
static
::
$lines
[
$language
.
$file
]
=
require
$path
;
}
}
else
{
throw
new
\Exception
(
"Language file [
$file
] does not exist for language [
$language
]."
);
}
static
::
$loaded
[]
=
$language
.
$file
;
}
/**
/**
* Set the place-holder replacements.
* Set the place-holder replacements.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment