<commit_before>import React from 'react';
import {connectToStores} from 'fluxible-addons-react';
import FocusTrap from 'focus-trap-react';
import { FormattedMessage, defineMessages } from 'react-intl';
import { Button, Modal, Divider, TextArea, Dropdown, Segment} from 'semantic-ui-react';
import TranslationStore from '../../../../stores/TranslationStore';
import ISO6391 from 'iso-639-1';
import {navigateAction} from 'fluxible-router';

class DeckTranslationsModal extends React.Component {

    constructor(props) {
        super(props);

        this.state = {
            openModal: false,
            activeTrap: false,
            action: '',
            languageCode: ''
        };

        this.handleOpen = this.handleOpen.bind(this);
        this.handleClose = this.handleClose.bind(this);
        this.unmountTrap = this.unmountTrap.bind(this);
    }

    handleOpen(){
        $('#app').attr('aria-hidden','true');
        this.setState({
            modalOpen:true,
            activeTrap:true
        });
    }

    handleClose(){
        $('#app').attr('aria-hidden','false');
        this.setState({
            modalOpen:false,
            activeTrap: false,
            action: '',
            languageCode: ''
        });
    }

    unmountTrap(){
        if(this.state.activeTrap){
            this.setState({ activeTrap: false });
            $('#app').attr('aria-hidden','false');
        }
    }

    handleTranslationSelection(e, data) {
        this.setState({ action: 'languageselect', languageCode: data.value });
    }

    handleLanguageSelection(e, data) {
        this.setState({ action: 'translate', languageCode: data.value });
    }

    handleActionClick(e) {
        if (this.state.action === 'languageselect') {
            this.handleClose();

            let path = location.pathname;
            let pathElements = path.split('/');
            let element = pathElements[2];
            let index = element.indexOf('_');
            if (index === -1) {
                pathElements[2] = element + '_' + this.state.languageCode;
            }
            else {
                pathElements[2] = element.substring(0, index) + '_' + this.state.languageCode;
            }
            path = pathElements.join('/');
            this.context.executeAction(navigateAction, {
                url: path
            });
        }
    }

    render() {
        const messages = defineMessages({
            header: {
                id: 'DeckTranslationsModal.header',
                defaultMessage: 'Translation selection',
            },
            currentLanguage: {
                id: 'DeckTranslationsModal.currentLanguage',
                defaultMessage: 'This deck has the following language:',
            },
            currentTranslation: {
                id: 'DeckTranslationsModal.currentTranslation',
                defaultMessage: 'This is a translation of the deck in the following language:',
            },
            switch: {
                id: 'DeckTranslationsModal.switch',
                defaultMessage: 'Select a translation to switch to it:',
            },
            chooseTranslation: {
                id: 'DeckTranslationsModal.chooseTranslation',
                defaultMessage: 'Choose a translation...',
            },
            chooseLanguage: {
                id: 'DeckTranslationsModal.chooseLanguage',
                defaultMessage: 'Choose the target language...',
            },
            startTranslation: {
                id: 'DeckTranslationsModal.startTranslation',
                defaultMessage: 'Or you can start a translation - just select the target language:',
            },
            cancel: {
                id: 'DeckTranslationsModal.cancel',
                defaultMessage: 'Cancel',
            },
            translate: {
                id: 'DeckTranslationsModal.translate',
                defaultMessage: 'Create translation',
            },
            language: {
                id: 'DeckTranslationsModal.language',
                defaultMessage: 'Switch to language',
            },
        });

        let message = this.props.TranslationStore.translations.find((t) => t === this.props.TranslationStore.treeLanguage) ? messages.currentTranslation : messages.currentLanguage;

        let translationOptions = [];
        if (this.props.TranslationStore.translations && this.props.TranslationStore.translations.length > 0) {
            translationOptions = this.props.TranslationStore.translations.reduce((arr, current)  => {
                arr.push({key: current, value: current, text: ISO6391.getNativeName(current)});
                return arr;
            }, []);
        }

        let languagesOptions = [];
        if (this.props.TranslationStore.supportedLangs && this.props.TranslationStore.supportedLangs.length > 0) {
            languagesOptions = this.props.TranslationStore.supportedLangs.reduce((arr, current)  => {
                if (!this.props.TranslationStore.translations.find((t) => t === current))
                    arr.push({key: current, value: current, text: ISO6391.getNativeName(current)});
                return arr;
            }, []);
        }

        let btnMessage = ' ';
        if (this.state.action === 'languageselect')
            btnMessage = this.context.intl.formatMessage(messages.language)
        else if (this.state.action === 'translate')
            btnMessage = this.context.intl.formatMessage(messages.translate)<commit_msg>[SWIK-1287_translation_ui_decks_and_slides] Added two missing semicolons<commit_after>import React from 'react';
import {connectToStores} from 'fluxible-addons-react';
import FocusTrap from 'focus-trap-react';
import { FormattedMessage, defineMessages } from 'react-intl';
import { Button, Modal, Divider, TextArea, Dropdown, Segment} from 'semantic-ui-react';
import TranslationStore from '../../../../stores/TranslationStore';
import ISO6391 from 'iso-639-1';
import {navigateAction} from 'fluxible-router';

class DeckTranslationsModal extends React.Component {

    constructor(props) {
        super(props);

        this.state = {
            openModal: false,
            activeTrap: false,
            action: '',
            languageCode: ''
        };

        this.handleOpen = this.handleOpen.bind(this);
        this.handleClose = this.handleClose.bind(this);
        this.unmountTrap = this.unmountTrap.bind(this);
    }

    handleOpen(){
        $('#app').attr('aria-hidden','true');
        this.setState({
            modalOpen:true,
            activeTrap:true
        });
    }

    handleClose(){
        $('#app').attr('aria-hidden','false');
        this.setState({
            modalOpen:false,
            activeTrap: false,
            action: '',
            languageCode: ''
        });
    }

    unmountTrap(){
        if(this.state.activeTrap){
            this.setState({ activeTrap: false });
            $('#app').attr('aria-hidden','false');
        }
    }

    handleTranslationSelection(e, data) {
        this.setState({ action: 'languageselect', languageCode: data.value });
    }

    handleLanguageSelection(e, data) {
        this.setState({ action: 'translate', languageCode: data.value });
    }

    handleActionClick(e) {
        if (this.state.action === 'languageselect') {
            this.handleClose();

            let path = location.pathname;
            let pathElements = path.split('/');
            let element = pathElements[2];
            let index = element.indexOf('_');
            if (index === -1) {
                pathElements[2] = element + '_' + this.state.languageCode;
            }
            else {
                pathElements[2] = element.substring(0, index) + '_' + this.state.languageCode;
            }
            path = pathElements.join('/');
            this.context.executeAction(navigateAction, {
                url: path
            });
        }
    }

    render() {
        const messages = defineMessages({
            header: {
                id: 'DeckTranslationsModal.header',
                defaultMessage: 'Translation selection',
            },
            currentLanguage: {
                id: 'DeckTranslationsModal.currentLanguage',
                defaultMessage: 'This deck has the following language:',
            },
            currentTranslation: {
                id: 'DeckTranslationsModal.currentTranslation',
                defaultMessage: 'This is a translation of the deck in the following language:',
            },
            switch: {
                id: 'DeckTranslationsModal.switch',
                defaultMessage: 'Select a translation to switch to it:',
            },
            chooseTranslation: {
                id: 'DeckTranslationsModal.chooseTranslation',
                defaultMessage: 'Choose a translation...',
            },
            chooseLanguage: {
                id: 'DeckTranslationsModal.chooseLanguage',
                defaultMessage: 'Choose the target language...',
            },
            startTranslation: {
                id: 'DeckTranslationsModal.startTranslation',
                defaultMessage: 'Or you can start a translation - just select the target language:',
            },
            cancel: {
                id: 'DeckTranslationsModal.cancel',
                defaultMessage: 'Cancel',
            },
            translate: {
                id: 'DeckTranslationsModal.translate',
                defaultMessage: 'Create translation',
            },
            language: {
                id: 'DeckTranslationsModal.language',
                defaultMessage: 'Switch to language',
            },
        });

        let message = this.props.TranslationStore.translations.find((t) => t === this.props.TranslationStore.treeLanguage) ? messages.currentTranslation : messages.currentLanguage;

        let translationOptions = [];
        if (this.props.TranslationStore.translations && this.props.TranslationStore.translations.length > 0) {
            translationOptions = this.props.TranslationStore.translations.reduce((arr, current)  => {
                arr.push({key: current, value: current, text: ISO6391.getNativeName(current)});
                return arr;
            }, []);
        }

        let languagesOptions = [];
        if (this.props.TranslationStore.supportedLangs && this.props.TranslationStore.supportedLangs.length > 0) {
            languagesOptions = this.props.TranslationStore.supportedLangs.reduce((arr, current)  => {
                if (!this.props.TranslationStore.translations.find((t) => t === current))
                    arr.push({key: current, value: current, text: ISO6391.getNativeName(current)});
                return arr;
            }, []);
        }

        let btnMessage = ' ';
        if (this.state.action === 'languageselect')
            btnMessage = this.context.intl.formatMessage(messages.language);
        else if (this.state.action === 'translate')
            btnMessage = this.context.intl.formatMessage(messages.translate);
{'fraction_non_alphanumeric': 0.11994938081894603, 'fraction_numerical': 0.004519569736961041, 'mean_word_length': 1.9192612137203167, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5011956', 'n_tokens_mistral': 2877, 'n_tokens_neox': 2768, 'n_words': 553}