<commit_before>from flask import Blueprint, render_template, flash, redirect, session, url_for, request, g
from appcomposer.appstorage.api import create_app
from appcomposer.db import db_session
from sqlalchemy.orm import scoped_session, sessionmaker
from forms import UrlForm, LangselectForm


info = {
    'blueprint': 'translate',
    'url': '/composers/translate',

    'new_endpoint': 'translate.translate_selectlang',
    'edit_endpoint': 'translate.translate_selectlang',
    'delete_endpoint': 'translate.translate_selectlang',

    'name': 'Translate Composer',
    'description': 'Translate an existing app.'
}


translate_blueprint = Blueprint(info['blueprint'], __name__)



import backend
print "Importing backend"


@translate_blueprint.route('/', methods=['GET', 'POST'])
def translate_index():
    form = UrlForm(request.form)
    
    # If it is a POST request (steps 2 & step 3), then request.form['appvar'] will not be None
    # Otherwise we will simply load the index
    if form.validate_on_submit():
        appurl = form.get_appurl()
        flash("App loaded successfully.")
       #return redirect(request.args.get("next") or url_for("translate.translate_index"))
        return redirect(url_for("adapt.adapt_index"))
        
    # It was a GET request (just viewing).
    return render_template('composers/translate/index.html', form=form)



#----------------------------------------
# other pages 
#----------------------------------------

@translate_blueprint.route("/selectlang", methods=["GET", "POST"])
def translate_selectlang():
    """ Source language & target language selection."""

    if request.method == "POST":
        # URL to the XML spec of the gadget.
        appurl = request.form["appurl"]

        # Get all the existing bundles.
        bm = backend.BundleManager()
        bm.load_spec(appurl)

        # Build JSON data
        js = bm.to_json()

        # Create a new App from the specified XML
        app = create_app(appurl, "translate", js)

        return render_template("composers/translate/selectlang.html")

    return render_template("composers/translate/selectlang.html")

@translate_blueprint.route("/edit")
def translate_edit():
    """Text editor for the selected language."""<commit_msg>[translate] Minor fixes and changes<commit_after>import os
import random
from flask import Blueprint, render_template, flash, redirect, session, url_for, request, g
from appcomposer.appstorage.api import create_app
from appcomposer.db import db_session
from sqlalchemy.orm import scoped_session, sessionmaker
from forms import UrlForm, LangselectForm


info = {
    'blueprint': 'translate',
    'url': '/composers/translate',

    'new_endpoint': 'translate.translate_selectlang',
    'edit_endpoint': 'translate.translate_selectlang',
    'delete_endpoint': 'dummy.delete',

    'name': 'Translate Composer',
    'description': 'Translate an existing app.'
}


translate_blueprint = Blueprint(info['blueprint'], __name__)



import backend
print "Importing backend"


@translate_blueprint.route('/', methods=['GET', 'POST'])
def translate_index():
    form = UrlForm(request.form)
    
    # If it is a POST request (steps 2 & step 3), then request.form['appvar'] will not be None
    # Otherwise we will simply load the index
    if form.validate_on_submit():
        appurl = form.get_appurl()
        flash("App loaded successfully.")
       #return redirect(request.args.get("next") or url_for("translate.translate_index"))
        return redirect(url_for("adapt.adapt_index"))
        
    # It was a GET request (just viewing).
    return render_template('composers/translate/index.html', form=form)



#----------------------------------------
# other pages 
#----------------------------------------

@translate_blueprint.route("/selectlang", methods=["GET", "POST"])
def translate_selectlang():
    """ Source language & target language selection."""

    if request.method == "POST":
        # URL to the XML spec of the gadget.
        appurl = request.form["appurl"]

        # Get all the existing bundles.
        bm = backend.BundleManager()
        bm.load_spec(appurl)

        # Build JSON data
        js = bm.to_json()

        # Generate a name for the app.
        # TODO: Eventually, this name should probably be given explicitly by the user.
        appname = os.path.basename(appurl) + "_%d" % random.randint(0, 9999)

        # Create a new App from the specified XML
        app = create_app(appname, "translate", js)

        return render_template("composers/translate/selectlang.html")

    return render_template("composers/translate/selectlang.html")

@translate_blueprint.route("/edit")
def translate_edit():
    """Text editor for the selected language."""
{'fraction_non_alphanumeric': 0.14523258261418648, 'fraction_numerical': 0.0018943380340980846, 'mean_word_length': 3.179419525065963, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, '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': '6709020', 'n_tokens_mistral': 1348, 'n_tokens_neox': 1295, 'n_words': 374}