forked from EasyCorp/EasyAdminBundle
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a new tutorial about translating the backend
- Loading branch information
1 parent
ffc5d35
commit 69eb264
Showing
4 changed files
with
94 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
How to Translate the Backend | ||
============================ | ||
|
||
EasyAdmin leverages the Symfony Translation component to provide built-in support | ||
for translating backends into any language. The translation process is divided | ||
into two steps: | ||
|
||
* Translating the elements of the EasyAdmin interface; | ||
* Translating your own contents (such as the main menu and the property labels). | ||
|
||
The elements of the interface are translated using the `EasyAdminBundle` domain. | ||
The rest of the elements are translated using the default `messages` domain. | ||
|
||
Before translating your backend, make sure that the `translator` service is | ||
enabled in the application (projects based on the Symfony Standard Edition have | ||
it disabled by default): | ||
|
||
```yaml | ||
# app/config/config.yml | ||
framework: | ||
translator: { fallbacks: [ "en" ] } | ||
``` | ||
|
||
Translate the Backend Interface | ||
------------------------------- | ||
|
||
The backend interface uses the same language as the underlying Symfony | ||
application. If you want to change it, update the value of the `locale` option | ||
in the `app/config/parameters.yml` file. | ||
|
||
If you want to change any of the built-in translations defined under the | ||
`EasyAdminBundle` domain, use the [translation override mechanism](http://symfony.com/doc/current/cookbook/bundles/override.html#translations) | ||
provided by Symfony. | ||
|
||
EasyAdmin is already translated into tens of languages thanks to the generosity | ||
of its community. We're actively looking for more translations, so please | ||
consider contributing a translation for your own language. | ||
|
||
Translate the Main Menu Labels | ||
------------------------------ | ||
|
||
The main menu labels are defined in the `label` configuration option of each | ||
entity. In order to translate these labels, use translation keys instead of their | ||
real contents in the configuration file: | ||
|
||
```yaml | ||
# app/config/config.yml | ||
easy_admin: | ||
entities: | ||
Customers: | ||
label: app.menu.customers | ||
class: AppBundle\Entity\Customer | ||
Orders: | ||
label: app.menu.orders | ||
class: AppBundle\Entity\Order | ||
``` | ||
|
||
If your application contains a translation file which defines the value of those | ||
keys for the active language, you'll see the main menu labels translated. | ||
Otherwise you'll see `app.menu.customers` and `app.menu.orders` as the menu labels. | ||
|
||
Translate Property Labels | ||
------------------------- | ||
|
||
By default, the label of each property is the "humanized" version of its name | ||
(e.g. `propertyname` -> `Propertyname`; `propertyName` -> `Property name`; | ||
`property_name` -> `Property name`). Before rendering the labels, their contents | ||
are also translated. | ||
|
||
Therefore, if you define the translation of these "humanized" property names | ||
anywhere in your application, these translations will be automatically used by | ||
the backend. | ||
|
||
Alternatively, you can use the `label` option of each property to define its | ||
label explicitly. The trick to make the labels translatable is to put the | ||
translation key as the content of the `label` option: | ||
|
||
```yaml | ||
# app/config/config.yml | ||
easy_admin: | ||
entities: | ||
Customer: | ||
class: AppBundle\Entity\Customer | ||
list: | ||
fields: | ||
- { property: 'firstName', label: 'app.users.firstName' } | ||
- { property: 'lastName', label: 'app.users.lastName' } | ||
# ... | ||
``` | ||
|
||
If your application contains a translation file which defines the value of those | ||
keys for the active language, you'll see these labels translated. Otherwise | ||
you'll see `app.users.firstName` and `app.users.lastName` as the labels. |