Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
S
Silex
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
common
Silex
Commits
49874395
Commit
49874395
authored
May 24, 2012
by
Fabien Potencier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added a way to register translations when the domain is not the default one (closes #185)
parent
e3113f97
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
49 additions
and
0 deletions
+49
-0
doc/providers/translation.rst
doc/providers/translation.rst
+29
-0
doc/providers/validator.rst
doc/providers/validator.rst
+14
-0
src/Silex/Provider/TranslationServiceProvider.php
src/Silex/Provider/TranslationServiceProvider.php
+6
-0
No files found.
doc/providers/translation.rst
View file @
49874395
...
...
@@ -10,6 +10,8 @@ Parameters
* **translator.messages**: A mapping of locales to message arrays. This
parameter contains the translation data in all languages.
* **translator.domains**: Same as above but stored by domains.
* **locale** (optional): The locale for the translator. You will most likely
want to set this based on some request parameter. Defaults to ``en``.
...
...
@@ -93,6 +95,33 @@ The above example will result in following routes:
* ``/it/hello/igor`` will return ``Hello igor`` (because of the fallback).
The messages defined with ``translator.messages`` are automatically stored in
the default domain. When you need to explicitly set the translation domain
(for the validation error messages for instance), use the
``translator.domains`` parameter instead::
$app['translator.domains'] = array(
'messages' => array(
'en' => array(
'hello' => 'Hello %name%',
'goodbye' => 'Goodbye %name%',
),
'de' => array(
'hello' => 'Hallo %name%',
'goodbye' => 'Tschüss %name%',
),
'fr' => array(
'hello' => 'Bonjour %name%',
'goodbye' => 'Au revoir %name%',
),
),
'validators' => array(
'fr' => array(
'This value should be a valid number.' => 'Cette valeur doit être un nombre.',
),
),
);
Recipes
-------
...
...
doc/providers/validator.rst
View file @
49874395
...
...
@@ -102,5 +102,19 @@ getters::
You will have to handle the display of these violations yourself. You can
however use the *FormServiceProvider* which can make use of the *ValidatorServiceProvider*.
Translation
~~~~~~~~~~~
To be able to translate the error messages, you can use the translator
provider and register the messages under the ``validators`` domain::
$app['translator.domains'] = array(
'validators' => array(
'fr' => array(
'This value should be a valid number.' => 'Cette valeur doit être un nombre.',
),
),
);
For more information, consult the `Symfony2 Validation documentation
<http://symfony.com/doc/2.0/book/validation.html>`_.
src/Silex/Provider/TranslationServiceProvider.php
View file @
49874395
...
...
@@ -39,6 +39,12 @@ class TranslationServiceProvider implements ServiceProviderInterface
$translator
->
addResource
(
'array'
,
$messages
,
$locale
);
}
foreach
(
$app
[
'translator.domains'
]
as
$domain
=>
$data
)
{
foreach
(
$data
as
$locale
=>
$messages
)
{
$translator
->
addResource
(
'array'
,
$messages
,
$locale
,
$domain
);
}
}
return
$translator
;
});
...
...
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