• Hello Fabrik Community

    Fabrik is now in the hands of the development team that brought you Fabrik for Joomla 4. We have recently transitioned the Fabrik site over to a new server and are busy trying to clean it up. We have upgraded the site to Joomla 4 and are running the latest version of Fabrik 4. We have also upgraded the Xenforo forum software to the latest version. Many of the widgets you might have been used to on the forum are no longer operational, many abandoned by the developers. We hope to bring back some of the important ones as we have time.

    Exciting times to be sure.

    The Fabrik 4.0 Official release is now available. In addition, the Fabrik codebase is now available in a public repository. See the notices about these in the announcements section

    We wish to shout out a very big Thank You to all of you who have made donations. They have really helped. But we can always use more...wink..wink..

    Also a big Thank You to those of you who have been assisting others in the forum. This takes a very big burden off of us as we work on bugs, the website and the future of Fabrik.

Make Fabrik multilingual with Fabrik itself

  • Views Views: 9,260
  • Last updated Last updated:
  • Multilingual data​

    The data in Fabrik Lists can be made multilingual with (pre)filters. In each list we just must have at least one element that represents the language and that we could filter data with. When we want the Joomla multilingual site would make the work then at least one language element must represent language url code (like 'en', 'fr', 'fi', 'et', ...) and list prefilters should be set to "WHERE `your_language_element`= '{lang}' "
    Multilingual databasejoin element​
    Create special table for labels. It should be a child table at this one that the databasejoin element points to. So with a similar fk like your databasejoin element. It should also contain a language field (like described above). Fill it with data.
    Change your databasejoin element settings. Assuming all your label data is now in special table write in "..or concat label" box something like:
    Code:
    (SELECT label_table.label from label_table WHERE label_table.fk_field = {thistable}.id AND label_table.language_field = '{lang}'),''
    In case your default language is not displayed in url you need after "AND" this code instead:
    IF('{lang}' = '', label_table.language_field = 'xx', label_table.language_field = '{lang}')
    replace xx with your default language code.​
    '

    Multilingual element labels​

    The labels could be displayed in different languages using Joomla language override function. It's done by language files yoursiteurl/language/overrides/xx-XX'.override.ini (instead xx-XX the needed language code like en-GB) where the syntax is like in all other language files -
    MY_LABEL_TEXT="My translated text"
    To manage these Translations you can use Joomla builtin method (ready to use but lot of copypastes one by one) or build by yourself a special application with Fabrik (which is more userfriendly and semiautomatic).
    "Override" in Joomla language manager​
    Edit your element which has the label you wish to translate
    Copy its element label text and replace it with a language constant string. E.g. if your label text was 'This is my label text', replace that with 'FABRIK_LABEL_THIS_IS_MY_LABEL_TEXT'
    Save the element
    Go to Extensions->language
    Select overrides
    Press new
    In the "language constant" field enter 'FABRIK_LABEL_THIS_IS_MY_LABEL_TEXT' (without the quotes)
    Then in the enter the translation in "Text"
    Finally select the language and press save
    Create a new language override for each language you wish to translate.
    Create and use your own language override app with Fabrik​
    We can still take advantage of Fabrik even though Joomla's translation override strings are stored in a text file and not in a database table. Initally, we have to do some work directly in MySQL (i.e via phpmyadmin) and the rest in Joomla / Fabrik.
    Steps in MySQL​
    NOTE: Replace everywhere #_ with your real prefix.
    First create the table for the label Translations. Let's say it's fabrik_labels
    Code:
    CREATE TABLE IF NOT EXISTS `#__fabrik_labels` (
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `label` varchar(255) NOT NULL,
    `lang_code` varchar(10) NOT NULL,
    `override` varchar(255) NOT NULL,
    PRIMARY KEY (`id`),
    UNIQUE KEY `label` (`label`,`lang_code`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
    Now you probably want to set up your database to automatically fill in the #__fabrik_labels table when a Fabrik meta object (e.g. an element) is updated or created. To do so create triggers in your database by running this SQL:

    Code:

    CREATE TRIGGER `new_element_labels` AFTER INSERT ON `#__fabrik_elements`
    FOR EACH ROW INSERT IGNORE INTO `#__fabrik_labels`(`label`, `lang_code`)
    SELECT `#__fabrik_elements`.`label` , `#__languages`.`lang_code`
    FROM `#__fabrik_elements` , `#__languages`
    WHERE `#__fabrik_elements`.`label` NOT LIKE '%{%'
    GROUP BY `#__fabrik_elements`.`label` , `#__languages`.`lang_code`;

    CREATE TRIGGER `new_list_labels` AFTER INSERT ON `#__fabrik_lists`
    FOR EACH ROW INSERT IGNORE INTO `#__fabrik_labels`(`label`, `lang_code`)
    SELECT `#__fabrik_lists`.`label` , `#__languages`.`lang_code`
    FROM `#__fabrik_lists` , `#__languages`
    WHERE `#__fabrik_lists`.`label` NOT LIKE '%{%'
    GROUP BY `#__fabrik_lists`.`label` , `#__languages`.`lang_code`;

    CREATE TRIGGER `new_form_labels` AFTER INSERT ON `#__fabrik_forms`
    FOR EACH ROW INSERT IGNORE INTO `#__fabrik_labels`(`label`, `lang_code`)
    SELECT `#__fabrik_forms`.`label` , `#__languages`.`lang_code`
    FROM `#__fabrik_forms` , `#__languages`
    WHERE `#__fabrik_forms`.`label` NOT LIKE '%{%'
    GROUP BY `#__fabrik_forms`.`label` , `#__languages`.`lang_code`;

    CREATE TRIGGER `new_group_labels` AFTER INSERT ON `#__fabrik_groups`
    FOR EACH ROW INSERT IGNORE INTO `#__fabrik_labels`(`label`, `lang_code`)
    SELECT `#__fabrik_groups`.`label` , `#__languages`.`lang_code`
    FROM `#__fabrik_groups` , `#__languages`
    WHERE `#__fabrik_groups`.`label` NOT LIKE '%{%'
    GROUP BY `#__fabrik_groups`.`label` , `#__languages`.`lang_code`;
    These WHERE clauses are added to avoid submission of {Placeholders} if any is used in labels; you can of course modify them or not use at all.
    Please ensure that all your labels are written as YOUR_LABEL_NAME or at least your_label_name. Messages in lowercase could be also translated, but in language.ini files they must be in uppercase and the following php code ensures that the label will be written in correct case.
    Only simple characters and _ are allowed (so never write i.e Y??R_F?RM-L?B?L NAME_4). Instead numbers you can use letters, e.g replace 4 with IV.

    Steps in Joomla​

    1) create new Fabrik list+form on the #__fabrik_labels table
    2) in the list
    - add an inline plugin so that you can edit inline (from the list view) the element #__fabrik_labels___override
    - good idea would be to show filters at least for the language element! So you can make list to show only the needed rows.
    3) in the form
    - add a "php" plugin and set it to work on edit at the end of form submission (onAfterProcess)
    - add the following code to execute

    PHP:
    $lab = strtoupper('{#__fabrik_labels___label}');
    $ln = '{#__fabrik_labels___lang_code_raw}';
    $override = '{#__fabrik_labels___override}';
    $msg = $lab . '="' . $override . '"
    ';
    $file = JPATH_SITE . '/language/overrides/' . $ln . '.override.ini';

    if (!file_exists($file))
    {
    fopen($file, 'x+');
    }

    $current = file($file);

    if($override != '' && !in_array($msg, $current))
    {
    foreach($current as $line)
    {
    $fmsg = explode('=', $line);

    if($fmsg[0] == $lab)
    {
    $newtext = str_replace($line, null, $current);
    file_put_contents($file, $newtext);
    }
    }

    file_put_contents($file, $msg, FILE_APPEND | LOCK_EX);
    }
    That means: the file in overrides folder has the name containing a language code (like en-GB). In case if it doesn't yet exist it should be created as a readable and writable one. If the field with override word is not empty and the file doesn't contain any line with this label and this override word, then the rest may happen:
    - if this label has an old translation (the label already exist) then we should delete this line first and put the rest back into file
    - anyway we put the new label and message pair at the very end of the file.​

    Multilingual tips and dropdown/radio/checkbox option labels​


    You can use also translation override function to translate such things like option labels in Elements with multiple Options like dropdown, radiobuttun or checkbox. Equally you can make tips multilingual. Both option labels and tips must then have needed format (OPTION_LABELS_AND_TIPS)
    You can principally use both Joomla language override form and the application built with Fabrik, but with one important difference: there is no automated way to write them into #__fabrik_labels table, you have to do it manually. If anyone have ideas how to involve the element params into this proposed automation, feel free to work it out!

    Alternate way - copying lists, forms and menu items​

    See - Multilingual forms
Back
Top