Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
SchwarzesBrettPlugin
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
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
Show more breadcrumbs
Uni Vechta
Plugins
SchwarzesBrettPlugin
Commits
96e01c1b
Commit
96e01c1b
authored
4 years ago
by
Jan-Hendrik Willms
Browse files
Options
Downloads
Patches
Plain Diff
testing for stud.ip 5.0's generic translation methods
parent
fdf9d6ca
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
classes/Controller.php
+2
-49
2 additions, 49 deletions
classes/Controller.php
classes/Plugin.php
+5
-54
5 additions, 54 deletions
classes/Plugin.php
with
7 additions
and
103 deletions
classes/Controller.php
+
2
−
49
View file @
96e01c1b
...
@@ -18,62 +18,15 @@ use SearchWidget;
...
@@ -18,62 +18,15 @@ use SearchWidget;
use
SelectElement
;
use
SelectElement
;
use
SelectWidget
;
use
SelectWidget
;
use
Sidebar
;
use
Sidebar
;
use
Studip
Controller
;
use
Plugin
Controller
;
use
Trails_Flash
;
use
Trails_Flash
;
use
URLHelper
;
use
URLHelper
;
class
Controller
extends
Studip
Controller
class
Controller
extends
Plugin
Controller
{
{
protected
$allow_nobody
=
false
;
protected
$allow_nobody
=
false
;
protected
$temp_storage
;
protected
$temp_storage
;
/**
* Constructs the controller and provide translations methods.
*
* @param object $dispatcher
* @see https://stackoverflow.com/a/12583603/982902 if you need to overwrite
* the constructor of the controller
*/
public
function
__construct
(
$dispatcher
)
{
parent
::
__construct
(
$dispatcher
);
$this
->
plugin
=
$dispatcher
->
current_plugin
;
// Localization
$this
->
_
=
function
(
$string
)
use
(
$dispatcher
)
{
return
call_user_func_array
(
[
$dispatcher
->
current_plugin
,
'_'
],
func_get_args
()
);
};
$this
->
_n
=
function
(
$string0
,
$tring1
,
$n
)
use
(
$dispatcher
)
{
return
call_user_func_array
(
[
$dispatcher
->
current_plugin
,
'_n'
],
func_get_args
()
);
};
}
/**
* Intercepts all non-resolvable method calls in order to correctly handle
* calls to _ and _n.
*
* @param string $method
* @param array $arguments
* @return mixed
* @throws RuntimeException when method is not found
*/
public
function
__call
(
$method
,
$arguments
)
{
$variables
=
get_object_vars
(
$this
);
if
(
isset
(
$variables
[
$method
])
&&
is_callable
(
$variables
[
$method
]))
{
return
call_user_func_array
(
$variables
[
$method
],
$arguments
);
}
return
parent
::
__call
(
$method
,
$arguments
);
}
public
function
before_filter
(
&
$action
,
&
$args
)
public
function
before_filter
(
&
$action
,
&
$args
)
{
{
$this
->
flash
=
Trails_Flash
::
instance
();
$this
->
flash
=
Trails_Flash
::
instance
();
...
...
This diff is collapsed.
Click to expand it.
classes/Plugin.php
+
5
−
54
View file @
96e01c1b
...
@@ -7,15 +7,12 @@ use StudIPPlugin;
...
@@ -7,15 +7,12 @@ use StudIPPlugin;
abstract
class
Plugin
extends
StudIPPlugin
abstract
class
Plugin
extends
StudIPPlugin
{
{
const
GETTEXT_DOMAIN
=
'schwarzes-brett'
;
use
\TranslatablePluginTrait
;
public
function
__construct
()
public
function
__construct
()
{
{
parent
::
__construct
();
parent
::
__construct
();
bindtextdomain
(
static
::
GETTEXT_DOMAIN
,
$this
->
getPluginPath
()
.
'/locale'
);
bind_textdomain_codeset
(
static
::
GETTEXT_DOMAIN
,
'UTF-8'
);
foreach
(
get_class_methods
(
$this
)
as
$method
)
{
foreach
(
get_class_methods
(
$this
)
as
$method
)
{
if
(
!
preg_match
(
'/^on\w+(Did|Will)\w+$/'
,
$method
))
{
if
(
!
preg_match
(
'/^on\w+(Did|Will)\w+$/'
,
$method
))
{
continue
;
continue
;
...
@@ -26,60 +23,14 @@ abstract class Plugin extends StudIPPlugin
...
@@ -26,60 +23,14 @@ abstract class Plugin extends StudIPPlugin
}
}
}
}
/**
public
static
function
getTranslationDomain
()
* Plugin localization for a single string.
* This method supports sprintf()-like execution if you pass additional
* parameters.
*
* @param String $string String to translate
* @return translated string
*/
public
function
_
(
$string
)
{
{
$result
=
static
::
GETTEXT_DOMAIN
===
null
return
'schwarzes-brett'
;
?
$string
:
dcgettext
(
static
::
GETTEXT_DOMAIN
,
$string
,
LC_MESSAGES
);
if
(
$result
===
$string
)
{
$result
=
_
(
$string
);
}
}
if
(
func_num_args
()
>
1
)
{
public
function
getTranslationPath
()
$arguments
=
array_slice
(
func_get_args
(),
1
);
$result
=
vsprintf
(
$result
,
$arguments
);
}
return
$result
;
}
/**
* Plugin localization for plural strings.
* This method supports sprintf()-like execution if you pass additional
* parameters.
*
* @param String $string0 String to translate (singular)
* @param String $string1 String to translate (plural)
* @param mixed $n Quantity factor (may be an array or array-like)
* @return translated string
*/
public
function
_n
(
$string0
,
$string1
,
$n
)
{
{
if
(
is_array
(
$n
))
{
return
$this
->
getPluginPath
()
.
'/locale'
;
$n
=
count
(
$n
);
}
$result
=
static
::
GETTEXT_DOMAIN
===
null
?
$string0
:
dngettext
(
static
::
GETTEXT_DOMAIN
,
$string0
,
$string1
,
$n
);
if
(
$result
===
$string0
||
$result
===
$string1
)
{
$result
=
ngettext
(
$string0
,
$string1
,
$n
);
}
if
(
func_num_args
()
>
3
)
{
$arguments
=
array_slice
(
func_get_args
(),
3
);
$result
=
vsprintf
(
$result
,
$arguments
);
}
return
$result
;
}
}
/**
/**
...
...
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