• Resolved zihniates

    (@zihniates)


    Hi there. Thank you for great plugin, so useful. But I need help for use Polylang plugin with your plugin.

    I have 2 languages on my website Turkish & English. I set the language from the wpDT > Settings > Interface language to the Turkish. It is worked properly. I created another datatable from another Excel file. When I change the language from the Polylang plugin’s icon on website, my page is still Turkish.
    Do you have any solution? I searched already but nothing found.
    Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter zihniates

    (@zihniates)

    I solved this with adding a function and a custom language file.

    I add the code below to the class.wpdatatables.php file line 474. Then add a language file SAMPLE.inc.php to the source/lang/ folder.

        public function setInterfaceLanguage($lang)
        {
            $l = $this->getLang();
            if($l == 'en') {
                $lang = 'SAMPLE.inc.php';
            }
            if (empty($lang)) {
                throw new WDTException('Incorrect language parameter!');
            }
            if (!file_exists(WDT_ROOT_PATH . 'source/lang/' . $lang)) {
                throw new WDTException('Language file not found');
            }
            $this->_interfaceLanguage = WDT_ROOT_PATH . 'source/lang/' . $lang;
        }
    Plugin Author wpDataTables

    (@wpdatatables)

    Hi zihniates,

    I am glad that you find some workaround, but this will be overwritten in next update, so you will need to do it again.

    Instead of that we will provide you a solution with a new hook that you can use, and it will be included in next update, so you don’t have to worry about updating code.

    Here is what you need to do:

    1) Replace your custom code with this

    $lang = apply_filters('wpdatatables_filter_interface_lang', $lang, WDTSettingsController::getArrInterfaceLanguages(), $this->getWpId());

    2) in file wp-content/plugins/wpdatatables/source/class.wdtsettingscontroller.php around line 125 you will find function getInterfaceLanguages
    and after it add new function like this

    /**
         * Returns languages as assoc array
         */
        public static function getArrInterfaceLanguages()
        {
            $newArrLang = [];
            $languages= self::getInterfaceLanguages();
    
            foreach ($languages as $language) {
                $newArrLang[$language['name']] = $language['file'];
            }
    
            return $newArrLang;
        }

    3) Then in your functions.php file of the theme or your child theme add this

    function changeLang($lang, $availableLanguages, $tableID){
    
        // $lang (string) is file name from source/lang directory in plugin
    
        // $availableLanguages (array) is assoc array of available languages from source/lang directory in plugin
        // for example if you need German language you will use like
        // $availableLanguages['German'] to get file name for that language from source/lang directory in plugin
    
        // $tableID (string) is table ID
    
        //We use the native WordPress function get_locale().
        //Or the Polylang function pll_current_language(). But you must first test that it exists.
        // See: https://polylang.pro/doc/function-reference/
        $currentLanguage = get_locale();
        // In our case we are using English (United States) so the language slug is
        // en_US, so in your case can be something else depends on of the WordPress 
        // language settings 
        if ($currentLanguage == 'en_US')
            $lang = $availableLanguages['English'];
    
        return $lang;
    }
    
    add_filter('wpdatatables_filter_interface_lang','changeLang', 10, 3);

    4) On the end you will rename SAMPLE.inc.php file to english.inc.php

    Best regards.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘How To Use Polylang?’ is closed to new replies.