# ai-builder/2.7.8/includes/class-translation-settings.php

AI Builder – Generate pages, blocks, images &amp; translate with AI, version 2.7.8. 131 lines.

- Page: https://pluginprobe.com/plugins/ai-builder/2.7.8/code/includes/class-translation-settings.php
- Raw: https://pluginprobe.com/plugins/ai-builder/2.7.8/raw/includes/class-translation-settings.php
- Modified: 2025-11-28T09:58:58+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/ai-builder/2.7.8/code/includes/class-translation-settings.php#L10-L20`.

```php
<?php

if (!defined('ABSPATH')) {
    exit;
}

class AIBUI_Translation_Settings
{
    const OPTION_KEY = 'aibui_translation_settings';

    public static function init()
    {
        add_action('admin_post_aibui_save_translation_settings', array(__CLASS__, 'handle_save'));
    }

    public static function get_default_settings()
    {
        return array(
            'enable_switcher' => false,
            'default_lang' => 'en',
            'available_langs' => array('en'),
            'switcher_bg' => '#5686c9',
            'switcher_text' => '#ffffff',
            'switcher_min_height' => 30,
            'switcher_min_width' => 90,
            'switcher_alpha' => 0.9,
        );
    }

    public static function get_settings()
    {
        $stored = get_option(self::OPTION_KEY, array());
        if (!is_array($stored)) {
            $stored = array();
        }

        return wp_parse_args($stored, self::get_default_settings());
    }

    public static function handle_save()
    {
        if (!current_user_can('manage_options')) {
            wp_die(__('You do not have permission to perform this action.', 'ai-builder'));
        }

        check_admin_referer('aibui_save_translation_settings');

        $defaults = self::get_default_settings();
        $supported = array_keys(AIBUI_Translation_Handler::get_supported_languages());

        $enable_switcher = isset($_POST['enable_switcher']);

        $default_lang = isset($_POST['default_lang']) ? sanitize_text_field(wp_unslash($_POST['default_lang'])) : $defaults['default_lang'];
        if (!in_array($default_lang, $supported, true)) {
            $default_lang = $defaults['default_lang'];
        }

        $available_langs = array();
        if (!empty($_POST['available_langs'])) {
            $raw_langs = (array) $_POST['available_langs'];
            foreach ($raw_langs as $lang) {
                $lang = sanitize_text_field(wp_unslash($lang));
                if (in_array($lang, $supported, true)) {
                    $available_langs[] = $lang;
                }
            }
            $available_langs = array_unique($available_langs);
        }

        if (empty($available_langs)) {
            $available_langs = array($default_lang);
        }

        if (!in_array($default_lang, $available_langs, true)) {
            array_unshift($available_langs, $default_lang);
        }

        $switcher_bg = isset($_POST['switcher_bg']) ? sanitize_hex_color(wp_unslash($_POST['switcher_bg'])) : $defaults['switcher_bg'];
        if (empty($switcher_bg)) {
            $switcher_bg = $defaults['switcher_bg'];
        }

        $switcher_text = isset($_POST['switcher_text']) ? sanitize_hex_color(wp_unslash($_POST['switcher_text'])) : $defaults['switcher_text'];
        if (empty($switcher_text)) {
            $switcher_text = $defaults['switcher_text'];
        }

        $switcher_min_height = isset($_POST['switcher_min_height']) ? absint($_POST['switcher_min_height']) : $defaults['switcher_min_height'];
        if ($switcher_min_height <= 0) {
            $switcher_min_height = $defaults['switcher_min_height'];
        }

        $switcher_min_width = isset($_POST['switcher_min_width']) ? absint($_POST['switcher_min_width']) : $defaults['switcher_min_width'];
        if ($switcher_min_width <= 0) {
            $switcher_min_width = $defaults['switcher_min_width'];
        }

        $switcher_alpha = isset($_POST['switcher_alpha']) ? floatval($_POST['switcher_alpha']) : $defaults['switcher_alpha'];
        if ($switcher_alpha < 0) {
            $switcher_alpha = 0;
        } elseif ($switcher_alpha > 1) {
            $switcher_alpha = 1;
        }

        $settings = array(
            'enable_switcher' => $enable_switcher,
            'default_lang' => $default_lang,
            'available_langs' => $available_langs,
            'switcher_bg' => $switcher_bg,
            'switcher_text' => $switcher_text,
            'switcher_min_height' => $switcher_min_height,
            'switcher_min_width' => $switcher_min_width,
            'switcher_alpha' => $switcher_alpha,
        );

        update_option(self::OPTION_KEY, $settings);

        $redirect = add_query_arg(
            array(
                'page' => 'aibui-translation-settings',
                'translation_saved' => 1,
            ),
            admin_url('admin.php')
        );

        wp_safe_redirect($redirect);
        exit;
    }
}


```
