Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
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
PSDI Army
yii2
Commits
b17ddcf7
Commit
b17ddcf7
authored
Jun 05, 2014
by
Klimov Paul
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Docs about handling missing translations added
parent
bcf71310
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
1 deletion
+47
-1
tutorial-i18n.md
docs/guide/tutorial-i18n.md
+47
-1
No files found.
docs/guide/tutorial-i18n.md
View file @
b17ddcf7
...
...
@@ -417,6 +417,52 @@ Sometimes you want to correct default framework message translation for your app
Now you can place your adjusted translations to
`/path/to/my/message/files`
.
### Handling missing translations
If the translation is missing at the source, Yii displays the requested message content. Such behavior very convenient
in case your raw message is a valid verbose text. However, sometimes it is not enough.
You may need to perform some custom processing of the situation, when requested translation is missing at the source.
This can be achieved via 'missingTranslation' event of the
[
[yii\i18n\MessageSource
]
].
For example: lets mark all missing translations with something notable, so they can be easily found at the page.
First we need to setup event handler, this can be done via configuration:
```
php
'components'
=>
[
// ...
'i18n'
=>
[
'translations'
=>
[
'app*'
=>
[
'class'
=>
'yii\i18n\PhpMessageSource'
,
'fileMap'
=>
[
'app'
=>
'app.php'
,
'app/error'
=>
'error.php'
,
],
'on missingTranslation'
=>
[
'TranslationEventHandler'
,
'handleMissingTranslation'
]
],
],
],
],
```
Now we need to implement own handler:
```
php
use
yii\i18n\MissingTranslationEvent
;
class
TranslationEventHandler
{
public
static
function
(
MissingTranslationEvent
$event
)
{
$event
->
translatedMessage
=
"@MISSING:
{
$event
->
category
}
.
{
$event
->
message
}
FOR LANGUAGE
{
$event
->
language
}
@"
;
}
}
```
If
[
[yii\i18n\MissingTranslationEvent::translatedMessage
]
] is set by event handler it will be displayed as translation result.
> Attention: each message source handles its missing translations separately. If you are using several message sources
and wish them treat missing translation in the same way, you should assign corresponding event handler to each of them.
Views
-----
...
...
@@ -444,7 +490,7 @@ return [
];
```
After cofiguring the component can be accessed as
`Yii::$app->formatter`
.
After co
n
figuring the component can be accessed as
`Yii::$app->formatter`
.
Note that in order to use i18n formatter you need to install and enable
[
intl
](
http://www.php.net/manual/en/intro.intl.php
)
PHP extension.
...
...
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