Localized fields allow the definition of attributes, that should be translated into multiple languages within an object. They can be filled with selected data types and layouts - due to technical and data storage reasons not all data types are available.
The advantage of this, is to make it very easy to translate fields to the configured languages.
Definition of localized fields
First of all, you have to configure your localized fields and layouts within your class. This can be easily done in the class editor.
Then add attributes, that need to be translated, into this container.
Pimcore generated the input widgets for every configured language. The result in your object editor will look like below:
By default, tabs are used if the number of languages does not exceed 15. This limit can be changed via the field settings in the class configurator.
Definition of available Languages
If it's not already configured, please specify the valid languages for your website.
You can do this in
System Settings ->
Localization & Internationalization
Working with PHP API
Getting available languages
The following code will create an array containing the available languages for the front end (the user facing website).
$languages = \Pimcore\Tool::getValidLanguages();
Disable Fallback languages
You can disable the Fallbacklanguages
Accessing the data
Accessing the data is simple as below:
// with global registered locale $object = DataObject::getById(234); $object->getInput1(); // will return the en_US data for the field "input1" // get specific localized data, regardless which locale is globally registered $object->getInput1("de") // will return the German value for the field "input1"
It works in the similar way as getting the data.
$object = DataObject::getById(234); $object->setInput1("My Name", "fr") // set the French value for the field "input1"
Warning: Please note that moving a field from outside (normal object field) into the localizedfield container means the loss of data from the field in all objects using this class.