当前位置: 首页>>代码示例>>Python>>正文


Python flask_babel.gettext方法代码示例

本文整理汇总了Python中flask_babel.gettext方法的典型用法代码示例。如果您正苦于以下问题:Python flask_babel.gettext方法的具体用法?Python flask_babel.gettext怎么用?Python flask_babel.gettext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在flask_babel的用法示例。


在下文中一共展示了flask_babel.gettext方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: validate

# 需要导入模块: import flask_babel [as 别名]
# 或者: from flask_babel import gettext [as 别名]
def validate(self) -> bool:
        rv = Form.validate(self)
        if not rv:
            return False
        user = db.session.query(User).filter(User.username == self.username.data).first()
        # email and password found and match
        if user is None:
            self.username.errors.append(gettext('Username was not found.'))
            return False

        if user.check_password(self.password.data) is False:
            self.password.errors.append(gettext('Wrong password.'))
            return False

        self.user = user
        return True 
开发者ID:Salamek,项目名称:gitlab-tools,代码行数:18,代码来源:sign.py

示例2: series_list

# 需要导入模块: import flask_babel [as 别名]
# 或者: from flask_babel import gettext [as 别名]
def series_list():
    if current_user.check_visibility(constants.SIDEBAR_SERIES):
        if current_user.series_view == 'list':
            entries = calibre_db.session.query(db.Series, func.count('books_series_link.book').label('count')) \
                .join(db.books_series_link).join(db.Books).filter(calibre_db.common_filters()) \
                .group_by(text('books_series_link.series')).order_by(db.Series.sort).all()
            charlist = calibre_db.session.query(func.upper(func.substr(db.Series.sort, 1, 1)).label('char')) \
                .join(db.books_series_link).join(db.Books).filter(calibre_db.common_filters()) \
                .group_by(func.upper(func.substr(db.Series.sort, 1, 1))).all()
            return render_title_template('list.html', entries=entries, folder='web.books_list', charlist=charlist,
                                         title=_(u"Series"), page="serieslist", data="series")
        else:
            entries = calibre_db.session.query(db.Books, func.count('books_series_link').label('count')) \
                .join(db.books_series_link).join(db.Series).filter(calibre_db.common_filters()) \
                .group_by(text('books_series_link.series')).order_by(db.Series.sort).all()
            charlist = calibre_db.session.query(func.upper(func.substr(db.Series.sort, 1, 1)).label('char')) \
                .join(db.books_series_link).join(db.Books).filter(calibre_db.common_filters()) \
                .group_by(func.upper(func.substr(db.Series.sort, 1, 1))).all()

            return render_title_template('grid.html', entries=entries, folder='web.books_list', charlist=charlist,
                                         title=_(u"Series"), page="serieslist", data="series", bodyClass="grid-view")
    else:
        abort(404) 
开发者ID:janeczku,项目名称:calibre-web,代码行数:25,代码来源:web.py

示例3: language_overview

# 需要导入模块: import flask_babel [as 别名]
# 或者: from flask_babel import gettext [as 别名]
def language_overview():
    if current_user.check_visibility(constants.SIDEBAR_LANGUAGE):
        charlist = list()
        if current_user.filter_language() == u"all":
            languages = calibre_db.speaking_language()
            # ToDo: generate first character list for languages
        else:
            try:
                cur_l = LC.parse(current_user.filter_language())
            except UnknownLocaleError:
                cur_l = None
            languages = calibre_db.session.query(db.Languages).filter(
                db.Languages.lang_code == current_user.filter_language()).all()
            if cur_l:
                languages[0].name = cur_l.get_language_name(get_locale())
            else:
                languages[0].name = _(isoLanguages.get(part3=languages[0].lang_code).name)
        lang_counter = calibre_db.session.query(db.books_languages_link,
                                        func.count('books_languages_link.book').label('bookcount')).group_by(
            text('books_languages_link.lang_code')).all()
        return render_title_template('languages.html', languages=languages, lang_counter=lang_counter,
                                     charlist=charlist, title=_(u"Languages"), page="langlist",
                                     data="language")
    else:
        abort(404) 
开发者ID:janeczku,项目名称:calibre-web,代码行数:27,代码来源:web.py

示例4: search

# 需要导入模块: import flask_babel [as 别名]
# 或者: from flask_babel import gettext [as 别名]
def search():
    term = request.args.get("query")
    if term:
        entries = calibre_db.get_search_results(term)
        ids = list()
        for element in entries:
            ids.append(element.id)
        searched_ids[current_user.id] = ids
        return render_title_template('search.html',
                                     searchterm=term,
                                     adv_searchterm=term,
                                     entries=entries,
                                     title=_(u"Search"),
                                     page="search")
    else:
        return render_title_template('search.html',
                                     searchterm="",
                                     title=_(u"Search"),
                                     page="search") 
开发者ID:janeczku,项目名称:calibre-web,代码行数:21,代码来源:web.py

示例5: render_archived_books

# 需要导入模块: import flask_babel [as 别名]
# 或者: from flask_babel import gettext [as 别名]
def render_archived_books(page, order):
    order = order or []
    archived_books = (
        ub.session.query(ub.ArchivedBook)
        .filter(ub.ArchivedBook.user_id == int(current_user.id))
        .filter(ub.ArchivedBook.is_archived == True)
        .all()
    )
    archived_book_ids = [archived_book.book_id for archived_book in archived_books]

    archived_filter = db.Books.id.in_(archived_book_ids)

    entries, random, pagination = calibre_db.fill_indexpage_with_archived_books(page,
                                                                                db.Books,
                                                                                archived_filter,
                                                                                order,
                                                                                allow_show_archived=True)

    name = _(u'Archived Books') + ' (' + str(len(archived_book_ids)) + ')'
    pagename = "archived"
    return render_title_template('index.html', random=random, entries=entries, pagination=pagination,
                                 title=name, page=pagename)

# ################################### Download/Send ################################################################## 
开发者ID:janeczku,项目名称:calibre-web,代码行数:26,代码来源:web.py

示例6: send_to_kindle

# 需要导入模块: import flask_babel [as 别名]
# 或者: from flask_babel import gettext [as 别名]
def send_to_kindle(book_id, book_format, convert):
    if not config.get_mail_server_configured():
        flash(_(u"Please configure the SMTP mail settings first..."), category="error")
    elif current_user.kindle_mail:
        result = send_mail(book_id, book_format, convert, current_user.kindle_mail, config.config_calibre_dir,
                           current_user.nickname)
        if result is None:
            flash(_(u"Book successfully queued for sending to %(kindlemail)s", kindlemail=current_user.kindle_mail),
                  category="success")
            ub.update_download(book_id, int(current_user.id))
        else:
            flash(_(u"Oops! There was an error sending this book: %(res)s", res=result), category="error")
    else:
        flash(_(u"Please update your profile with a valid Send to Kindle E-mail Address."), category="error")
    if "HTTP_REFERER" in request.environ:
        return redirect(request.environ["HTTP_REFERER"])
    else:
        return redirect(url_for('web.index'))


# ################################### Login Logout ################################################################## 
开发者ID:janeczku,项目名称:calibre-web,代码行数:23,代码来源:web.py

示例7: watch_gdrive

# 需要导入模块: import flask_babel [as 别名]
# 或者: from flask_babel import gettext [as 别名]
def watch_gdrive():
    if not config.config_google_drive_watch_changes_response:
        with open(gdriveutils.CLIENT_SECRETS, 'r') as settings:
            filedata = json.load(settings)
        if filedata['web']['redirect_uris'][0].endswith('/'):
            filedata['web']['redirect_uris'][0] = filedata['web']['redirect_uris'][0][:-((len('/gdrive/callback')+1))]
        else:
            filedata['web']['redirect_uris'][0] = filedata['web']['redirect_uris'][0][:-(len('/gdrive/callback'))]
        address = '%s/gdrive/watch/callback' % filedata['web']['redirect_uris'][0]
        notification_id = str(uuid4())
        try:
            result = gdriveutils.watchChange(gdriveutils.Gdrive.Instance().drive, notification_id,
                               'web_hook', address, gdrive_watch_callback_token, current_milli_time() + 604800*1000)
            config.config_google_drive_watch_changes_response = json.dumps(result)
            # after save(), config_google_drive_watch_changes_response will be a json object, not string
            config.save()
        except HttpError as e:
            reason=json.loads(e.content)['error']['errors'][0]
            if reason['reason'] == u'push.webhookUrlUnauthorized':
                flash(_(u'Callback domain is not verified, please follow steps to verify domain in google developer console'), category="error")
            else:
                flash(reason['message'], category="error")

    return redirect(url_for('admin.configuration')) 
开发者ID:janeczku,项目名称:calibre-web,代码行数:26,代码来源:gdrive.py

示例8: run

# 需要导入模块: import flask_babel [as 别名]
# 或者: from flask_babel import gettext [as 别名]
def run(self):
        while True:
            i = self.queue.get()
            if i == 'dummy':
                self.queue.task_done()
                break
            if i['task'] == 'add_format':
                cur_book = self.session.query(Books).filter(Books.id == i['id']).first()
                cur_book.data.append(i['format'])
                try:
                    # db.session.merge(cur_book)
                    self.session.commit()
                except OperationalError as e:
                    self.session.rollback()
                    self.log.error("Database error: %s", e)
                    # self._handleError(_(u"Database error: %(error)s.", error=e))
                    # return
            self.queue.task_done() 
开发者ID:janeczku,项目名称:calibre-web,代码行数:20,代码来源:db.py

示例9: speaking_language

# 需要导入模块: import flask_babel [as 别名]
# 或者: from flask_babel import gettext [as 别名]
def speaking_language(self, languages=None):
        from . import get_locale

        if not languages:
            languages = self.session.query(Languages) \
                .join(books_languages_link) \
                .join(Books) \
                .filter(self.common_filters()) \
                .group_by(text('books_languages_link.lang_code')).all()
        for lang in languages:
            try:
                cur_l = LC.parse(lang.lang_code)
                lang.name = cur_l.get_language_name(get_locale())
            except UnknownLocaleError:
                lang.name = _(isoLanguages.get(part3=lang.lang_code).name)
        return languages 
开发者ID:janeczku,项目名称:calibre-web,代码行数:18,代码来源:db.py

示例10: send_mail

# 需要导入模块: import flask_babel [as 别名]
# 或者: from flask_babel import gettext [as 别名]
def send_mail(book_id, book_format, convert, kindle_mail, calibrepath, user_id):
    """Send email with attachments"""
    book = calibre_db.get_book(book_id)

    if convert == 1:
        # returns None if success, otherwise errormessage
        return convert_book_format(book_id, calibrepath, u'epub', book_format.lower(), user_id, kindle_mail)
    if convert == 2:
        # returns None if success, otherwise errormessage
        return convert_book_format(book_id, calibrepath, u'azw3', book_format.lower(), user_id, kindle_mail)

    for entry in iter(book.data):
        if entry.format.upper() == book_format.upper():
            converted_file_name = entry.name + '.' + book_format.lower()
            worker.add_email(_(u"Send to Kindle"), book.path, converted_file_name,
                             config.get_mail_settings(), kindle_mail, user_id,
                             _(u"E-mail: %(book)s", book=book.title), _(u'This e-mail has been sent via Calibre-Web.'))
            return
    return _(u"The requested file could not be read. Maybe wrong permissions?") 
开发者ID:janeczku,项目名称:calibre-web,代码行数:21,代码来源:helper.py

示例11: from_profile

# 需要导入模块: import flask_babel [as 别名]
# 或者: from flask_babel import gettext [as 别名]
def from_profile(cls, user, profile):
        if not user or user.is_anonymous:
            if not app.config.get("SECURITY_REGISTERABLE"):
                msg = "User not found. Registration disabled."
                logging.warning(msg)
                raise Exception(_(msg))
            email = profile.data.get("email")
            if not email:
                msg = "Please provide an email address."
                logging.warning(msg)
                raise Exception(_(msg))
            conflict = User.query.filter(User.email == email).first()
            if conflict:
                msg = "Email {} is already used. Login and then connect " + \
                      "external profile."
                msg = _(msg).format(email)
                logging.warning(msg)
                raise Exception(msg)

            now = datetime.now()
            user = User(
                email=email,
                name="{} {}".format(profile.data.get("first_name"),
                                    profile.data.get("last_name")),
                confirmed_at=now,
                active=True)

            db.session.add(user)
            db.session.flush()

        assert user.id, "User does not have an id"
        connection = cls(user_id=user.id, **profile.data)
        db.session.add(connection)
        db.session.commit()
        return connection 
开发者ID:beavyHQ,项目名称:beavy,代码行数:37,代码来源:social_connection.py

示例12: subtitle

# 需要导入模块: import flask_babel [as 别名]
# 或者: from flask_babel import gettext [as 别名]
def subtitle(self) -> str:
        return gettext('Stats') 
开发者ID:PennyDreadfulMTG,项目名称:Penny-Dreadful-Tools,代码行数:4,代码来源:charts.py

示例13: subtitle

# 需要导入模块: import flask_babel [as 别名]
# 或者: from flask_babel import gettext [as 别名]
def subtitle(self) -> str:
        return gettext('About') 
开发者ID:PennyDreadfulMTG,项目名称:Penny-Dreadful-Tools,代码行数:4,代码来源:about.py

示例14: render

# 需要导入模块: import flask_babel [as 别名]
# 或者: from flask_babel import gettext [as 别名]
def render(self, engine: pystache.renderengine.RenderEngine, context: ContextStack) -> str:
        s = gettext(self.key)  # The key is populated in messages.pot via generate_translations.py - pylint: disable=translation-of-non-string
        def lookup(match: Match) -> str:
            return engine.fetch_string(context, match.group(1))
        s = re.sub(r'\{([a-z_]+)\}', lookup, s)
        return markdown(engine.escape(s), extensions=[NoParaTagsExtension()])

# pylint: disable=no-self-use 
开发者ID:PennyDreadfulMTG,项目名称:Penny-Dreadful-Tools,代码行数:10,代码来源:template.py

示例15: TT_REPORT

# 需要导入模块: import flask_babel [as 别名]
# 或者: from flask_babel import gettext [as 别名]
def TT_REPORT(self) -> str:
        return gettext('Report') 
开发者ID:PennyDreadfulMTG,项目名称:Penny-Dreadful-Tools,代码行数:4,代码来源:report.py


注:本文中的flask_babel.gettext方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。