Skip to content

Commit

Permalink
Added a new tutorial about translating the backend
Browse files Browse the repository at this point in the history
  • Loading branch information
javiereguiluz committed Dec 30, 2015
1 parent ffc5d35 commit 69eb264
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 83 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -51,6 +51,7 @@ Documentation
* [Customizing Backend Actions](https://github.com/javiereguiluz/EasyAdminBundle/blob/master/Resources/doc/tutorials/customizing-backend-actions.md)
* [Customizing AdminController](https://github.com/javiereguiluz/EasyAdminBundle/blob/master/Resources/doc/tutorials/customizing-admin-controller.md)
* [Advanced Design Customization](https://github.com/javiereguiluz/EasyAdminBundle/blob/master/Resources/doc/tutorials/advanced-design-customization.md)
* [How to Translate the Backend](https://github.com/javiereguiluz/EasyAdminBundle/blob/master/Resources/doc/tutorials/i18n.md)
* [How to Use a WYSIWYG Editor](https://github.com/javiereguiluz/EasyAdminBundle/blob/master/Resources/doc/tutorials/wysiwyg-editor.md)
* [How to Upload Files and Images](https://github.com/javiereguiluz/EasyAdminBundle/blob/master/Resources/doc/tutorials/upload-files-and-images.md)
* [Tips and Tricks](https://github.com/javiereguiluz/EasyAdminBundle/blob/master/Resources/doc/tutorials/tips-and-tricks.md)
Expand Down
46 changes: 0 additions & 46 deletions Resources/doc/getting-started/3-backend-configuration.md
Expand Up @@ -127,52 +127,6 @@ easy_admin:
class: AppBundle\Entity\Order
```

Translate the Backend Interface
-------------------------------

The backend uses the same language as the underlying Symfony application, which
is usually configured in the `locale` option of the `app/config/parameters.yml`
file. The current version of EasyAdmin supports tens of languages and we're
actively looking for more translations contributed by the community.

The strings that belong to the bundle interface are translated using the
special `EasyAdminBundle` translation domain. The rest of the strings, such as
the property names, are translated using the default `messages` domain.

In addition, 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: [ "%locale%" ] }
```

Customize the Translation of the Main Menu Items
------------------------------------------------

In addition to the built-in backend elements, you may need to translate the
labels of your entities, because they are displayed in the main menu. To do so,
use translation keys instead of contents in the configuration file:

```yaml
# app/config/config.yml
easy_admin:
entities:
Customers:
label: app.customers
class: AppBundle\Entity\Customer
Orders:
label: app.orders
class: AppBundle\Entity\Order
```

The `app.customers` and `app.orders` values are not the real entity names but
the translation keys. If your application includes a translation file which
defines the value of those keys for the active language, you'll see the main
menu items translated.

Restrict the Access to the Backend
----------------------------------

Expand Down
37 changes: 0 additions & 37 deletions Resources/doc/getting-started/4-views-and-actions.md
Expand Up @@ -313,43 +313,6 @@ to learn about all the available options, their usage and allowed values.
> customizations, as explained in the
> [Advanced Design Customization] [advanced-design-customization] tutorial.
### Translate Property Labels

Before translating the labels, 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: [ "%locale%" ] }
```

Then, in order to translate the labels to the application language, use
translation keys instead of contents for the `label` option:

```yaml
# app/config/config.yml
easy_admin:
entities:
Customer:
class: AppBundle\Entity\Customer
list:
fields:
- 'id'
- { property: 'firstname', label: 'app.users.firstname' }
- { property: 'lastname', label: 'app.users.firstname' }
# ...
```

Now, instead of displaying the label content, EasyAdmin will look for any
translation file available in the application which defines the value of those
keys for the current language.

If there is no translation available, it will try to look for those values for
the default application language. In case no translation is available, the key
will be displayed so you can easily spot any missing translation.

### Customize Date Format

By default, these are the formats applied to date properties (read the
Expand Down
93 changes: 93 additions & 0 deletions Resources/doc/tutorials/i18n.md
@@ -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.

0 comments on commit 69eb264

Please sign in to comment.