Topics

Multilingual fields in GRID (since 4.5.0)

GRID can be configured to be multilingual. That means selected fields can be multiplied for each installed language and store different value for each language. This is how multilingual fields have to be configured in GRID:

  • additional table with the same name and suffix _language has to be created;
  • additional table has to have fields itemId of type int and language of type varchar(7) + all other fields you want to be multilingual;
  • all non multilingual fields as usual go to the main table and all multilingual fields go to the new table with suffix _language;
  • in GRID configuration, multilingual fields have to have option 'multilingual' set to 1

Example

Table for NON multilingual fields 

CREATE TABLE `ip_catalog_item` (
`id` int(11) NOT NULL AUTO_INCREMENT,
  `price` int(11) NOT NULL,
  `images` text,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

Table for multilingual fields 

CREATE TABLE `ip_catalog_item_language` (
  `itemId` int(11) NOT NULL,
  `language` varchar(7) NOT NULL,
  `title` varchar(255) DEFAULT NULL,
  `visible` tinyint(1) NOT NULL DEFAULT '1',
  PRIMARY KEY (`itemId`, `language`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

GRID configuration in Plugin's AdminController.php file

<?php

namespace Plugin\MyPlugin;


class AdminController
{

    public function index()
    {
        $config = array(
            'title' => 'Products',
            'table' => 'catalog_item',
            'fields' => array(
                array(
                    'label' => 'Title',
                    'field' => 'title',
                    'multilingual' => 1
                ),
                array(
                    'label' => 'Visible',
                    'field' => 'visible',
                    'multilingual' => 1,
                    'type' => 'Checkbox'
                ),
                array(
                    'label' => 'Price',
                    'field' => 'price',
                    'type' => 'Currency'
                ),
                array(
                    'type' => 'RepositoryFile',
                    'label' => 'Images',
                    'field' => 'images',
                    'fileLimit' => 0
                )
            )
        );
        return ipGridController($config);
    }
}

This is how the generated management is going to look like:

Search can be performed only on one language at the time. You can select preferred language next to the "search" button.

Advanced options

It is recommended to follow database table and field naming as proposed above. But if you need to name the language specific table in a different way, you are free to do so by adding additional configuration values

Configuration value Default Comment
languageTable ..._language Language specific table name
languageForeignKeyField itemId Name of foreign key field in language table
languageCodeField language Name of field holding language code in langaage table
comments powered by Disqus