<commit_before>function translations_Init() {
    var settings = new Settings();
    changeLanguage(settings.language);

    $('#settings .language select').change(function() {
        var code = $(this).val();
        var settings = new Settings();
        settings.language = code;
        settings.save();
        changeLanguage(code);
    });

    $('#translator-panel .close').click(function() {
        $('#translatorMode').removeAttr('checked').change();
    });
    $('#translatorMode').change(function() {
        var mode = $(this).is(':checked');
        var settings = new Settings();

        settings.translatorMode = mode;
        settings.save();

        if (mode) {
            $('#translator-panel').show();
            $('html').addClass('translator');
            $('#results-container').hide();
            loadTranslatorPanel();
        } else {
            $('#translator-panel').hide();
            $('html').removeClass('translator');
            $('#results-container').show();
        }
        
        $(window).resize();
    });

    if (settings.translatorMode) {
        $('#translatorMode').attr('checked', 'checked').change();
    }
}

var translations,
    TRANSLATABLE_ATTRIBUTES = [
        'title',
        'alt',
        'placeholder'
    ];

function updateMarkup(translations) {
    $('.translatable').each(function(i, elem) {
        elem = $(elem);

        var translationKeys = elem.data('translationKeys') || {},
            key;

        if (translationKeys.hasOwnProperty('text')) {
            key = translationKeys.text;
        } else {
            key = elem.text();
            translationKeys.text = key;
        }

        if (translations.hasOwnProperty(key)) {
            elem.text(translations[key]);
        }

        $.each(TRANSLATABLE_ATTRIBUTES, function(j, attr) {
            if (elem.attr(attr) !== undefined) {
                if (translationKeys.hasOwnProperty(attr)) {
                    key = translationKeys[attr];
                } else {
                    key = elem.attr(attr);
                    translationKeys[attr] = key;
                }
                if (translations.hasOwnProperty(key)) {
                    elem.attr(attr, translations[key]);
                }
            }
        });

        elem.data('translationKeys', translationKeys);
    });

    loadTranslatorPanel();
}

function changeLanguage(code) {
    $('#settings .language option[value=' + code + ']').attr('selected', 'selected');

    if (autoDetectedLanguageByServer === code) {
        updateMarkup(autoDetectedTranslations);
    } else {
        $.getJSON('/translations/' + code, function(data, textStatus) {
            updateMarkup(data);
        });
    }
}

/**
 * Locates an translatable element in the DOM by its translation source text.
 */
function findTranslatable(key) {
    var ret;

    $('.translatable').each(function(i, elem) {
        elem = $(elem);
        var translationKeys = elem.data('translationKeys') || {};

        if (translationKeys.hasOwnProperty('text') && translationKeys.text === key) {
            ret = elem;
            return false;
        }

        $.each(TRANSLATABLE_ATTRIBUTES, function(j, attr) {
            if (elem.attr(attr) !== undefined) {
                if (translationKeys.hasOwnProperty(attr) && translationKeys[attr] === key) {
                    ret = elem;
                    return false;
                }
            }
        });
    });

    return ret;
}

function loadTranslatorPanel() {
    var key,
        tr,
        input;

    $('#translator-panel tbody').html('');

    inputBlurHandler = function() {
        $('.selected-translation').removeClass('selected-translation');
    };
    inputFocusHandler = function() {
        var tr = $(this).parent().parent();
        var key = tr.find('td.source').text();
        var elem = findTranslatable(key);
        if (elem) {
            elem.addClass('selected-translation');
        }
    };

    for (key in translations) {
        if (translations.hasOwnProperty(key)) {
            tr = $('<tr/>');
            $('<td class="source"/>').text(key).appendTo(tr);
            input = $('<input type="text" />').val(translations[key]);
            input.focus(inputFocusHandler);
            input.blur(inputBlurHandler);
            $('<td/>').append(input).appendTo(tr);
            tr.appendTo('#translator-panel tbody');
        }
    }
}
<commit_msg>Fix bug where translations variable was not set<commit_after>function translations_Init() {
    var settings = new Settings();
    changeLanguage(settings.language);

    $('#settings .language select').change(function() {
        var code = $(this).val();
        var settings = new Settings();
        settings.language = code;
        settings.save();
        changeLanguage(code);
    });

    $('#translator-panel .close').click(function() {
        $('#translatorMode').removeAttr('checked').change();
    });
    $('#translatorMode').change(function() {
        var mode = $(this).is(':checked');
        var settings = new Settings();

        settings.translatorMode = mode;
        settings.save();

        if (mode) {
            $('#translator-panel').show();
            $('html').addClass('translator');
            $('#results-container').hide();
            loadTranslatorPanel();
        } else {
            $('#translator-panel').hide();
            $('html').removeClass('translator');
            $('#results-container').show();
        }
        
        $(window).resize();
    });

    if (settings.translatorMode) {
        $('#translatorMode').attr('checked', 'checked').change();
    }
}

var translations,
    TRANSLATABLE_ATTRIBUTES = [
        'title',
        'alt',
        'placeholder'
    ];

function updateMarkup(data) {
    translations = data;

    $('.translatable').each(function(i, elem) {
        elem = $(elem);

        var translationKeys = elem.data('translationKeys') || {},
            key;

        if (translationKeys.hasOwnProperty('text')) {
            key = translationKeys.text;
        } else {
            key = elem.text();
            translationKeys.text = key;
        }

        if (translations.hasOwnProperty(key)) {
            elem.text(translations[key]);
        }

        $.each(TRANSLATABLE_ATTRIBUTES, function(j, attr) {
            if (elem.attr(attr) !== undefined) {
                if (translationKeys.hasOwnProperty(attr)) {
                    key = translationKeys[attr];
                } else {
                    key = elem.attr(attr);
                    translationKeys[attr] = key;
                }
                if (translations.hasOwnProperty(key)) {
                    elem.attr(attr, translations[key]);
                }
            }
        });

        elem.data('translationKeys', translationKeys);
    });

    loadTranslatorPanel();
}

function changeLanguage(code) {
    $('#settings .language option[value=' + code + ']').attr('selected', 'selected');

    if (autoDetectedLanguageByServer === code) {
        updateMarkup(autoDetectedTranslations);
    } else {
        $.getJSON('/translations/' + code, function(data, textStatus) {
            updateMarkup(data);
        });
    }
}

/**
 * Locates an translatable element in the DOM by its translation source text.
 */
function findTranslatable(key) {
    var ret;

    $('.translatable').each(function(i, elem) {
        elem = $(elem);
        var translationKeys = elem.data('translationKeys') || {};

        if (translationKeys.hasOwnProperty('text') && translationKeys.text === key) {
            ret = elem;
            return false;
        }

        $.each(TRANSLATABLE_ATTRIBUTES, function(j, attr) {
            if (elem.attr(attr) !== undefined) {
                if (translationKeys.hasOwnProperty(attr) && translationKeys[attr] === key) {
                    ret = elem;
                    return false;
                }
            }
        });
    });

    return ret;
}

function loadTranslatorPanel() {
    var key,
        tr,
        input;

    $('#translator-panel tbody').html('');

    inputBlurHandler = function() {
        $('.selected-translation').removeClass('selected-translation');
    };
    inputFocusHandler = function() {
        var tr = $(this).parent().parent();
        var key = tr.find('td.source').text();
        var elem = findTranslatable(key);
        if (elem) {
            elem.addClass('selected-translation');
        }
    };

    for (key in translations) {
        if (translations.hasOwnProperty(key)) {
            tr = $('<tr/>');
            $('<td class="source"/>').text(key).appendTo(tr);
            input = $('<input type="text" />').val(translations[key]);
            input.focus(inputFocusHandler);
            input.blur(inputBlurHandler);
            $('<td/>').append(input).appendTo(tr);
            tr.appendTo('#translator-panel tbody');
        }
    }
}

{'fraction_non_alphanumeric': 0.15239948119325553, 'fraction_numerical': 0.0, 'mean_word_length': 1.7770108043217288, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '7114409', 'n_tokens_mistral': 2481, 'n_tokens_neox': 2392, 'n_words': 427}