Beispiel #1
0
# In applying this license, CERN does not
# waive the privileges and immunities granted to it by virtue of its status
# as an Intergovernmental Organization or submit itself to any jurisdiction.
"""Helper models for Zenodo data model."""

from __future__ import absolute_import, print_function

import json
from datetime import datetime
from os.path import dirname, join

from flask_babelex import gettext
from jsonref import JsonRef
from speaklater import make_lazy_gettext

_ = make_lazy_gettext(lambda: gettext)


class AccessRight(object):
    """Class defining access right status."""

    OPEN = 'open'

    EMBARGOED = 'embargoed'

    RESTRICTED = 'restricted'

    CLOSED = 'closed'

    _all = (
        (OPEN, _('Open Access')),
Beispiel #2
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self._ = make_lazy_gettext(lambda: self.meta.locale.translate)
Beispiel #3
0
import inspect

from flask import Markup, current_app, flash, request
from flask_login import current_user
from flask_wtf import FlaskForm as BaseForm
from speaklater import make_lazy_gettext
from wtforms import BooleanField, Field, HiddenField, PasswordField, \
    StringField, SubmitField, ValidationError, validators

from .confirmable import requires_confirmation
from .utils import _, _datastore, config_value, get_message, \
    localize_callback, url_for_security, validate_redirect_url, \
    verify_and_update_password

lazy_gettext = make_lazy_gettext(lambda: localize_callback)

_default_field_labels = {
    'email': _('Email Address'),
    'password': _('Password'),
    'remember_me': _('Remember Me'),
    'login': _('Login'),
    'register': _('Register'),
    'send_confirmation': _('Resend Confirmation Instructions'),
    'recover_password': _('Recover Password'),
    'reset_password': _('Reset Password'),
    'retype_password': _('Retype Password'),
    'new_password': _('New Password'),
    'change_password': _('Change Password'),
    'send_login_link': _('Send Login Link')
}
"""Helper models for CAP data models."""

from __future__ import absolute_import, print_function

import json
from datetime import datetime
from os.path import dirname, join

from flask import current_app
from flask_babelex import gettext
from invenio_search import Query, current_search_client
from jsonref import JsonRef
from speaklater import make_lazy_gettext

_ = make_lazy_gettext(lambda: gettext)


class ObjectType(object):
    """Class to load object types data."""

    index_id = None
    index_internal_id = None

    @classmethod
    def _load_data(cls):
        """Load object types for JSON data."""
        if cls.index_id is None:
            with open(join(dirname(__file__), "data", "objecttypes.json")) \
                 as fp:
                data = json.load(fp)
Beispiel #5
0
 def _(self):
     return make_lazy_gettext(lambda: self.locale.translate)
Beispiel #6
0
import inspect

from flask import Markup, current_app, flash, request
from flask_login import current_user
from flask_wtf import FlaskForm as BaseForm
from speaklater import make_lazy_gettext
from wtforms import BooleanField, Field, HiddenField, PasswordField, \
    StringField, SubmitField, ValidationError, validators

from .confirmable import requires_confirmation
from .utils import _, _datastore, config_value, get_message, \
    localize_callback, url_for_security, validate_redirect_url, \
    verify_and_update_password

lazy_gettext = make_lazy_gettext(lambda: localize_callback)

_default_field_labels = {
    'email': _('Email Address'),
    'password': _('Password'),
    'remember_me': _('Remember Me'),
    'login': _('Login'),
    'register': _('Register'),
    'send_confirmation': _('Resend Confirmation Instructions'),
    'recover_password': _('Recover Password'),
    'reset_password': _('Reset Password'),
    'retype_password': _('Retype Password'),
    'new_password': _('New Password'),
    'change_password': _('Change Password'),
    'send_login_link': _('Send Login Link')
}
Beispiel #7
0
from speaklater import make_lazy_gettext


def translate(message):
    return message


def gettext_from_po_file(message,
                         domain="messages",
                         languages=None,
                         class_=None,
                         fallback=False):
    """模块 gettext 将使用路径 (在 Unix 系统中): localedir/language/LC_MESSAGES/domain.mo 查找二进制 .mo 文件,
    此处对应地查找 language 的位置是环境变量 LANGUAGE, LC_ALL, LC_MESSAGES 和 LANG 中
    """
    localedir = gettext._localedirs.get(domain, None)
    codeset = gettext._localecodesets.get(domain, None)
    try:
        t = gettext.translation(domain,
                                localedir=localedir,
                                languages=languages,
                                class_=class_,
                                fallback=fallback,
                                codeset=codeset)
    except OSError:
        return message
    return t.gettext(message)


lazy_gettext = make_lazy_gettext(lambda: translate)