Translatable type
This translatable type makes reference to Softspring\CmsBundle\Form\Type\TranslatableType form type.
This form type provides multiple language values for any field and type.
The CMS translation context supplies the languages and default language. It starts from the Symfony enabled locales and can be narrowed to the content currently being edited.
Translate texts
The most common use of this type is to translate texts.
The "translatedText" type is deprecated. You should use this method.
module:
module_options:
form_fields:
description:
type: "translatable"
type_options:
type: "text"
The values are stored as a json object with locale as key:
{
"description": {
"en": "Product",
"es": "Producto",
"de": "Produkt"
}
}
Render values
The way to render translated values is using it as an array, accessing it by the locale:
{{ description|sfs_cms_trans }}
Also is posible to render it using description[app.request.locale]|default but it's not recommended because it
does not take into account the default locale.
Preview values
Preview values works in the same way as contained type does, but accessing it by the locale:
module:
module_options:
form_fields:
description:
type: "translatable"
type_options:
type: "text"
type_options:
attr:
data-edit-content-input: 'description'
{% for locale,localeField in form.description.vars.localeFields %}
<p data-edit-content-target="description.{{ locale }}" data-lang="{{ locale }}" contenteditable="true">{{ localeField.vars.data|default('') }}</p>
{% endfor %}
Translate medias
Wrap a mediaVersion field in translatable when each language needs a different image:
module:
module_options:
form_fields:
image:
type: translatable
type_options:
type: mediaVersion
type_options:
media_types:
background:
image: [sm]
The media type and version must already exist. Resolve the translated selection before rendering:
{% set selection = image|sfs_cms_trans %}
{% if selection.media|default(false) %}
{{ selection.media|sfs_media_render(selection.version) }}
{% endif %}
Options
type
type: string required
Form type for children elements. You can use any type in the way that CMS modules use them:
Using short names
module:
module_options:
form_fields:
description:
type: "translatable"
type_options:
type: "text"
Keep in mind that it translates this type names as follows (this preference order):
- App\Form\Type\
Type - Softspring\CmsBundle\Form\Type\
Type - Symfony\Component\Form\Extension\Core\Type\
Type
Using fully qualified class names
You can specify a fully qualified class name to use an specific form type,
module:
module_options:
form_fields:
description:
type: "translatable"
type_options:
type: 'Symfony\Component\Form\Extension\Core\Type\ColorType'
or other namespace type:
module:
module_options:
form_fields:
description:
type: "translatable"
type_options:
type: 'Vendor\FeatureBundle\Type\ExampleType'
type_options
type: array default: []
Configures the selected type options:
module:
module_options:
form_fields:
description:
type: "translatable"
type_options:
type: "choice"
type_options:
multiple: true
expanded: true
choices:
example1: 1
example2: 2
languages
type: array default: %kernel.enabled_locales%
default_language
type: string default: %kernel.default_locale%
children_attr
type: array default: []