Esempio n. 1
0
def translation_upload():
    default_language = _guess_default_language()
    if default_language:
        form = UploadForm(language = default_language)
    else:
        form = UploadForm()

    if form.validate_on_submit():
        errors = False
        app_url = form.url.data

        try:
            translation_url, original_messages, metadata = extract_local_translations_url(app_url)
        except Exception as e:
            traceback.print_exc()
            form.url.errors = [unicode(e)]
            errors = True

        xml_contents = form.opensocial_xml.data.read()
        if isinstance(xml_contents, str):
            xml_contents = unicode(xml_contents, 'utf8')
        try:
            translated_messages, metadata = extract_messages_from_translation(xml_contents)
        except Exception as e:
            traceback.print_exc()
            form.opensocial_xml.errors = [unicode(e)]
            errors = True
        
        if not errors:
            language = form.language.data
            target = form.target.data
            add_full_translation_to_app(current_golab_user(), app_url, translation_url, metadata, language, target, translated_messages, original_messages, from_developer = False)
            flash("Contents successfully added")

    return render_template('translator/translations_upload.html', form=form)
Esempio n. 2
0
def api_app():
    app_url = request.args.get('app_url')
    app_thumb = None
    app_link = None
    name = None
    desc = None

    for repo_app in db.session.query(RepositoryApp).filter_by(url = app_url).all():
        if repo_app.name is not None:
            name = repo_app.name
        if repo_app.app_thumb is not None:
            app_thumb = repo_app.app_thumb
        if repo_app.description is not None:
            desc = repo_app.description
        if repo_app.app_link is not None:
            app_link = repo_app.app_link

    translation_url, original_messages, metadata = extract_local_translations_url(app_url, force_local_cache = True)
    translations = retrieve_translations_stats(translation_url, original_messages)
    register_app_url(app_url, translation_url, metadata)

    app_data = {
        'url' : app_url,
        'app_thumb': app_thumb,
        'app_link' : app_link,
        'name' : name,
        'desc' : desc,
        'translations' : translations,
    }
    return jsonify(**app_data)
Esempio n. 3
0
def bundle_update(language, target):
    app_url = request.values.get('app_url')
    key = request.values.get("key")
    value = request.values.get("value")

    if key is None or value is None:
        return jsonify(**{"result": "error"})

    user = current_golab_user()
    translation_url, original_messages, metadata = extract_local_translations_url(app_url, force_local_cache = True)
    translated_messages = { key : value }

    add_full_translation_to_app(user, app_url, translation_url, metadata, language, target, translated_messages, original_messages, from_developer = False)

    return jsonify(**{"result": "success"})
Esempio n. 4
0
def api_translate(language, target):
    app_url = request.args.get('app_url')

    errors = []
    if not app_url:
        errors.append("'app_url' argument missing")
    if not language:
        errors.append("'lang' argument missing")
    if not target:
        errors.append("'target' argument missing")
    if errors:
        return '; '.join(errors), 400

    translation_url, original_messages, metadata = extract_local_translations_url(app_url)
    translation = {}

    stored_translations, from_developer, automatic = retrieve_stored(translation_url, language, target)
    suggestions = retrieve_suggestions(original_messages, language, target, stored_translations)
    for key, original_message_pack in original_messages.iteritems():
        value = original_message_pack['text']
        stored = stored_translations.get(key, {})
        current_suggestions = list(suggestions.get(key, []))
        current_target = stored.get('value')

        if from_developer:
            can_edit = not stored.get('from_developer', True)
        else:
            can_edit = True

        translation[key] = {
            'source' : value,
            'target' : current_target,
            'from_default' : stored.get('from_default', False),
            'suggestions' : current_suggestions,
            'can_edit' : can_edit
        }

    app_thumb = None
    name = None
    for repo_app in db.session.query(RepositoryApp).filter_by(url = app_url).all():
        if repo_app.name is not None:
            name = repo_app.name
        if repo_app.app_thumb is not None:
            app_thumb = repo_app.app_thumb
        if name and app_thumb:
            break

    update_user_status(language, target, app_url, current_golab_user())
    users_status = get_user_status(language, target, app_url, current_golab_user())

    response = {
        'url' : app_url,
        'app_thumb' : app_thumb,
        'name' : name,
        'translation' : translation,
        'modificationDate': users_status['modificationDate'],
        'modificationDateByOther': users_status['modificationDateByOther'],
        'automatic': automatic and not from_developer
    }

    if False:
        response = json.dumps(response, indent = 4)
        return "<html><body>%s</body></html>" % response
    return jsonify(**response)
    user = get_golab_default_user()

    for f in files:
        print "Processing...",f,
        translation = loads(open(f).read())
        app_url = translation['spec']
        language, target = translation['bundle'].rsplit('_', 1)
        if language == 'all_ALL':
            print "Skipping all_ALL"
            continue
        elif language.startswith('af'):
            print "Skipping afghan and afrikaans"
            continue

        try:
            translated_messages = json.loads(json.loads(translation['data']))
        except (ValueError, TypeError):
            translated_messages = json.loads(translation['data'])

        if translated_messages is None or len(translated_messages) == 0:
            print "Skipping empty"
            continue

        from_developer = False

        translation_url, original_messages = extract_local_translations_url(app_url, force_local_cache = True)

        add_full_translation_to_app(user, app_url, translation_url, language, target, translated_messages, original_messages, from_developer)
        print "[done]"

    for f in files:
        print "Processing...", f,
        translation = loads(open(f).read())
        app_url = translation['spec']
        language, target = translation['bundle'].rsplit('_', 1)
        if language == 'all_ALL':
            print "Skipping all_ALL"
            continue
        elif language.startswith('af'):
            print "Skipping afghan and afrikaans"
            continue

        try:
            translated_messages = json.loads(json.loads(translation['data']))
        except (ValueError, TypeError):
            translated_messages = json.loads(translation['data'])

        if translated_messages is None or len(translated_messages) == 0:
            print "Skipping empty"
            continue

        from_developer = False

        translation_url, original_messages = extract_local_translations_url(
            app_url, force_local_cache=True)

        add_full_translation_to_app(user, app_url, translation_url, language,
                                    target, translated_messages,
                                    original_messages, from_developer)
        print "[done]"