Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drupal
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
drupal
Commits
49a45db6
Commit
49a45db6
authored
7 years ago
by
catch
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#2979944
by alexpott: Remove t() usage in Drupal\Core\Validation
parent
3b6be4d7
No related branches found
No related tags found
2 merge requests
!7452
Issue #1797438. HTML5 validation is preventing form submit and not fully...
,
!789
Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
core/lib/Drupal/Core/Validation/DrupalTranslator.php
+10
-5
10 additions, 5 deletions
core/lib/Drupal/Core/Validation/DrupalTranslator.php
core/tests/Drupal/Tests/Core/Plugin/Context/ContextDefinitionIsSatisfiedTest.php
+0
-10
0 additions, 10 deletions
.../Core/Plugin/Context/ContextDefinitionIsSatisfiedTest.php
with
10 additions
and
15 deletions
core/lib/Drupal/Core/Validation/DrupalTranslator.php
+
10
−
5
View file @
49a45db6
...
...
@@ -25,7 +25,10 @@ class DrupalTranslator implements TranslatorInterface {
public
function
trans
(
$id
,
array
$parameters
=
[],
$domain
=
NULL
,
$locale
=
NULL
)
{
// If a TranslatableMarkup object is passed in as $id, return it since the
// message has already been translated.
return
$id
instanceof
TranslatableMarkup
?
$id
:
t
(
$id
,
$this
->
processParameters
(
$parameters
),
$this
->
getOptions
(
$domain
,
$locale
));
if
(
$id
instanceof
TranslatableMarkup
)
{
return
$id
;
}
return
new
TranslatableMarkup
(
$id
,
$this
->
processParameters
(
$parameters
),
$this
->
getOptions
(
$domain
,
$locale
));
}
/**
...
...
@@ -67,7 +70,7 @@ public function getLocale() {
}
/**
* Processes the parameters array for use with
t()
.
* Processes the parameters array for use with
TranslatableMarkup
.
*/
protected
function
processParameters
(
array
$parameters
)
{
$return
=
[];
...
...
@@ -79,7 +82,8 @@ protected function processParameters(array $parameters) {
$value
=
(
string
)
$value
;
}
if
(
is_object
(
$value
))
{
// t() does not work with objects being passed as replacement strings.
// TranslatableMarkup does not work with objects being passed as
// replacement strings.
}
// Check for symfony replacement patterns in the form "{{ name }}".
elseif
(
strpos
(
$key
,
'{{ '
)
===
0
&&
strrpos
(
$key
,
' }}'
)
==
strlen
(
$key
)
-
3
)
{
...
...
@@ -95,11 +99,12 @@ protected function processParameters(array $parameters) {
}
/**
* Returns options suitable for use with
t()
.
* Returns options suitable for use with
TranslatableMarkup
.
*/
protected
function
getOptions
(
$domain
=
NULL
,
$locale
=
NULL
)
{
// We do not support domains, so we ignore this parameter.
// If locale is left NULL, t() will default to the interface language.
// If locale is left NULL, TranslatableMarkup will default to the interface
// language.
$locale
=
isset
(
$locale
)
?
$locale
:
$this
->
locale
;
return
[
'langcode'
=>
$locale
];
}
...
...
This diff is collapsed.
Click to expand it.
core/tests/Drupal/Tests/Core/Plugin/Context/ContextDefinitionIsSatisfiedTest.php
+
0
−
10
View file @
49a45db6
...
...
@@ -342,13 +342,3 @@ public function providerTestIsSatisfiedByPassBundledEntity() {
}
}
namespace
Drupal\Core\Validation
;
if
(
!
function_exists
(
't'
))
{
function
t
(
$string
,
array
$args
=
[])
{
return
strtr
(
$string
,
$args
);
}
}
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