Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
our_own_cloud_project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
die_coolen_jungs
our_own_cloud_project
Commits
d4044d02
Commit
d4044d02
authored
12 years ago
by
Bart Visscher
Browse files
Options
Downloads
Patches
Plain Diff
Delay loading of translations until they are used
parent
a1364c97
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/l10n.php
+23
-7
23 additions, 7 deletions
lib/l10n.php
lib/l10n/string.php
+25
-0
25 additions, 0 deletions
lib/l10n/string.php
with
48 additions
and
7 deletions
lib/l10n.php
+
23
−
7
View file @
d4044d02
...
...
@@ -39,6 +39,16 @@ class OC_L10N{
*/
protected
static
$language
=
''
;
/**
* App of this object
*/
protected
$app
;
/**
* Language of this object
*/
protected
$lang
;
/**
* Translations
*/
...
...
@@ -77,10 +87,17 @@ class OC_L10N{
* language.
*/
public
function
__construct
(
$app
,
$lang
=
null
){
$this
->
init
(
$app
,
$lang
);
$this
->
app
=
$app
;
$this
->
lang
=
$lang
;
}
protected
function
init
(
$app
,
$lang
=
null
){
protected
function
init
(){
if
(
$this
->
app
===
true
)
{
return
;
}
$app
=
$this
->
app
;
$lang
=
$this
->
lang
;
$this
->
app
=
true
;
// Find the right language
if
(
is_null
(
$lang
)){
$lang
=
self
::
findLanguage
(
$app
);
...
...
@@ -127,10 +144,7 @@ class OC_L10N{
* returned.
*/
public
function
t
(
$text
,
$parameters
=
array
()){
if
(
array_key_exists
(
$text
,
$this
->
translations
)){
return
vsprintf
(
$this
->
translations
[
$text
],
$parameters
);
}
return
vsprintf
(
$text
,
$parameters
);
return
new
OC_L10N_String
(
$this
,
$text
,
$parameters
);
}
/**
...
...
@@ -144,7 +158,7 @@ class OC_L10N{
public
function
tA
(
$textArray
){
$result
=
array
();
foreach
(
$textArray
as
$key
=>
$text
){
$result
[
$key
]
=
$this
->
t
(
$text
);
$result
[
$key
]
=
(
string
)
$this
->
t
(
$text
);
}
return
$result
;
}
...
...
@@ -156,6 +170,7 @@ class OC_L10N{
* Returns an associative array with all translations
*/
public
function
getTranslations
(){
$this
->
init
();
return
$this
->
translations
;
}
...
...
@@ -182,6 +197,7 @@ class OC_L10N{
* - params: timestamp (int/string)
*/
public
function
l
(
$type
,
$data
){
$this
->
init
();
switch
(
$type
){
// If you add something don't forget to add it to $localizations
// at the top of the page
...
...
This diff is collapsed.
Click to expand it.
lib/l10n/string.php
0 → 100644
+
25
−
0
View file @
d4044d02
<?php
/**
* Copyright (c) 2012 Bart Visscher <bartv@thisnet.nl>
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*/
class
OC_L10N_String
{
protected
$l10n
;
public
function
__construct
(
$l10n
,
$text
,
$parameters
){
$this
->
l10n
=
$l10n
;
$this
->
text
=
$text
;
$this
->
parameters
=
$parameters
;
}
public
function
__toString
(){
$translations
=
$this
->
l10n
->
getTranslations
();
if
(
array_key_exists
(
$this
->
text
,
$translations
)){
return
vsprintf
(
$translations
[
$this
->
text
],
$this
->
parameters
);
}
return
vsprintf
(
$this
->
text
,
$this
->
parameters
);
}
}
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