How to use the lektor.i18n.get_i18n_block function in Lektor

To help you get started, we’ve selected a few Lektor examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github lektor / lektor / lektor / datamodel.py View on Github external
def datamodel_data_from_ini(id, inifile):
    def _parse_order(value):
        value = (value or '').strip()
        if not value:
            return None
        return [x for x in [x.strip() for x in value.strip().split(',')] if x]

    return dict(
        filename=inifile.filename,
        id=id,
        parent=inifile.get('model.inherits'),
        name_i18n=get_i18n_block(inifile, 'model.name'),
        label_i18n=get_i18n_block(inifile, 'model.label'),
        primary_field=inifile.get('model.primary_field'),
        hidden=inifile.get_bool('model.hidden', default=None),
        protected=inifile.get_bool('model.protected', default=None),
        child_config=dict(
            enabled=inifile.get_bool('children.enabled', default=None),
            slug_format=inifile.get('children.slug_format'),
            model=inifile.get('children.model'),
            order_by=_parse_order(inifile.get('children.order_by')),
            replaced_with=inifile.get('children.replaced_with'),
            hidden=inifile.get_bool('children.hidden', default=None),
        ),
        attachment_config=dict(
            enabled=inifile.get_bool('attachments.enabled', default=None),
            model=inifile.get('attachments.model'),
            order_by=_parse_order(inifile.get('attachments.order_by')),
github lektor / lektor-archive / lektor / datamodel.py View on Github external
def datamodel_data_from_ini(id, inifile):
    def _parse_order(value):
        value = (value or '').strip()
        if not value:
            return None
        return [x for x in [x.strip() for x in value.strip().split(',')] if x]

    return dict(
        filename=inifile.filename,
        id=id,
        parent=inifile.get('model.inherits'),
        name_i18n=get_i18n_block(inifile, 'model.name'),
        label_i18n=get_i18n_block(inifile, 'model.label'),
        primary_field=inifile.get('model.primary_field'),
        hidden=inifile.get_bool('model.hidden', default=None),
        protected=inifile.get_bool('model.protected', default=None),
        child_config=dict(
            enabled=inifile.get_bool('children.enabled', default=None),
            slug_format=inifile.get('children.slug_format'),
            model=inifile.get('children.model'),
            order_by=_parse_order(inifile.get('children.order_by')),
            replaced_with=inifile.get('children.replaced_with'),
        ),
        attachment_config=dict(
            enabled=inifile.get_bool('attachments.enabled', default=None),
            model=inifile.get('attachments.model'),
            order_by=_parse_order(inifile.get('attachments.order_by')),
        ),
github lektor / lektor / lektor / types / multi.py View on Github external
def _parse_choices(options):
    s = options.get('choices')
    if not s:
        return None

    choices = []
    items = s.split(',')
    user_labels = get_i18n_block(options, 'choice_labels')
    implied_labels = []

    for item in items:
        if '=' in item:
            choice, value = item.split('=', 1)
            choice = choice.strip()
            if choice.isdigit():
                choice = int(choice)
            implied_labels.append(value.strip())
            choices.append(choice)
        else:
            choices.append(item.strip())
            implied_labels.append(item.strip())

    if user_labels:
        rv = list(zip(choices, _reflow_and_split_labels(user_labels)))
github lektor / lektor / lektor / environment.py View on Github external
source_path='env.imagemagick_executable')
    set_simple(target='LESSC_EXECUTABLE',
               source_path='env.lessc_executable')

    for section_name in ('ATTACHMENT_TYPES', 'PROJECT', 'PACKAGES', 'THEME_SETTINGS'):
        section_config = inifile.section_as_dict(section_name.lower())
        config[section_name].update(section_config)

    for sect in inifile.sections():
        if sect.startswith('servers.'):
            server_id = sect.split('.')[1]
            config['SERVERS'][server_id] = inifile.section_as_dict(sect)
        elif sect.startswith('alternatives.'):
            alt = sect.split('.')[1]
            config['ALTERNATIVES'][alt] = {
                'name': get_i18n_block(inifile, 'alternatives.%s.name' % alt),
                'url_prefix': inifile.get('alternatives.%s.url_prefix' % alt),
                'url_suffix': inifile.get('alternatives.%s.url_suffix' % alt),
                'primary': inifile.get_bool('alternatives.%s.primary' % alt),
                'locale': inifile.get('alternatives.%s.locale' % alt, 'en_US'),
            }

    for alt, alt_data in iteritems(config['ALTERNATIVES']):
        if alt_data['primary']:
            config['PRIMARY_ALTERNATIVE'] = alt
            break
    else:
        if config['ALTERNATIVES']:
            raise RuntimeError('Alternatives defined but no primary set.')
github lektor / lektor-archive / lektor / types / multi.py View on Github external
def _parse_choices(options):
    s = options.get('choices')
    if not s:
        return None

    choices = []
    items = s.split(',')
    user_labels = get_i18n_block(options, 'choice_labels')
    implied_labels = []

    for item in items:
        if '=' in item:
            choice, value = item.split('=', 1)
            choice = choice.strip()
            if choice.isdigit():
                choice = int(choice)
            implied_labels.append(value.strip())
            choices.append(choice)
        else:
            choices.append(item.strip())
            implied_labels.append(item.strip())

    if user_labels:
        rv = list(zip(choices, _reflow_and_split_labels(user_labels)))
github ulope / pyformat.info / vendor / lektor / lektor / datamodel.py View on Github external
def flowblock_data_from_ini(id, inifile):
    return dict(
        filename=inifile.filename,
        id=id,
        name_i18n=get_i18n_block(inifile, 'block.name'),
        fields=fielddata_from_ini(inifile),
        order=inifile.get_int('block.order'),
        button_label=inifile.get('block.button_label'),
    )
github lektor / lektor / lektor / datamodel.py View on Github external
def flowblock_data_from_ini(id, inifile):
    return dict(
        filename=inifile.filename,
        id=id,
        name_i18n=get_i18n_block(inifile, 'block.name'),
        fields=fielddata_from_ini(inifile),
        order=inifile.get_int('block.order'),
        button_label=inifile.get('block.button_label'),
    )
github ulope / pyformat.info / vendor / lektor / lektor / types / fake.py View on Github external
def to_json(self, pad, record=None, alt=PRIMARY_ALT):
        rv = FakeType.to_json(self, pad, record, alt)
        rv['heading_i18n'] = get_i18n_block(self.options, 'heading')
        return rv
github lektor / lektor-archive / lektor / datamodel.py View on Github external
def flowblock_data_from_ini(id, inifile):
    return dict(
        filename=inifile.filename,
        id=id,
        name_i18n=get_i18n_block(inifile, 'block.name'),
        fields=fielddata_from_ini(inifile),
        order=inifile.get_int('block.order'),
        button_label=inifile.get('block.button_label'),
    )
github lektor / lektor / lektor / types / fake.py View on Github external
def to_json(self, pad, record=None, alt=PRIMARY_ALT):
        rv = FakeType.to_json(self, pad, record, alt)
        rv['heading_i18n'] = get_i18n_block(self.options, 'heading')
        return rv