def init_menu_lang(): """Create the header language menu.""" item = current_menu.submenu('main.menu') item.register( endpoint=None, text='{icon} <span class="{visible}">{menu}'.format( icon='<i class="fa fa-bars"></i>', visible='visible-md-inline visible-lg-inline', menu=_('Menu') ), order=0 ) order = 10 def return_language(lang): return dict(lang_code=lang) def hide_language(lang): return current_i18n.language != lang for language_item in current_i18n.get_locales(): item = current_menu.submenu( 'main.menu.lang_{language}'.format( language=language_item.language)) ui_language = 'ui_language_{lang}'.format(lang=language_item.language) item.register( endpoint='invenio_i18n.set_lang', endpoint_arguments_constructor=partial( return_language, language_item.language), text='{icon} {language}'.format( icon='<i class="fa fa-language"></i>', language=_(ui_language) ), visible_when=partial(hide_language, language_item.language), order=order ) order += 1 item = current_menu.submenu('main.menu.help') item.register( endpoint='rero_ils.help', text='{icon} {help}'.format( icon='<i class="fa fa-info"></i>', help=_('Help') ), order=100 )
def init_menu_lang(): """Create the header language menu.""" item = current_menu.submenu('main.menu') ui_language = 'ui_language_{lang}'.format(lang=current_i18n.language) # Bug: when you reload the page with register(**kwargs), it failed # We so check that 'id' already exists. If yes, do not create again # the item. rero_register( item, endpoint=None, text='{icon} <span class="{visible}">{menu}'.format( icon='<i class="fa fa-language"></i>', visible='visible-md-inline visible-lg-inline', menu=_(ui_language) ), order=0, id='language-menu' ) order = 10 def return_language(lang): return dict(lang_code=lang) def hide_language(lang): return current_i18n.language != lang for language_item in current_i18n.get_locales(): item = current_menu.submenu( 'main.menu.lang_{language}'.format( language=language_item.language)) ui_language = 'ui_language_{lang}'.format(lang=language_item.language) rero_register( item, endpoint='invenio_i18n.set_lang', endpoint_arguments_constructor=partial( return_language, language_item.language), text='{icon} {language}'.format( icon='<i class="fa fa-language"></i>', language=_(ui_language) ), visible_when=partial(hide_language, language_item.language), order=order, id='language-menu-{language}'.format( language=language_item.language)) order += 1
def init_menu(): """Create the header menus.""" item = current_menu.submenu('main.menu') item.register( endpoint=None, text='{icon} <span class="{visible}">{menu}'.format( icon='<i class="fa fa-bars"></i>', visible='visible-md-inline visible-lg-inline', menu=_('Menu') ), order=0 ) order = 10 def return_language(lang): return dict(lang_code=lang) def hide_language(lang): return current_i18n.language != lang for language_item in current_i18n.get_locales(): item = current_menu.submenu( 'main.menu.lang_{language}'.format( language=language_item.language)) ui_language = 'ui_language_{lang}'.format(lang=language_item.language) item.register( endpoint='invenio_i18n.set_lang', endpoint_arguments_constructor=partial( return_language, language_item.language), text='{icon} {language}'.format( icon='<i class="fa fa-language"></i>', language=_(ui_language) ), visible_when=partial(hide_language, language_item.language), order=order ) order += 1 item = current_menu.submenu('main.menu.help') item.register( endpoint='rero_ils.help', text='{icon} {help}'.format( icon='<i class="fa fa-info"></i>', help=_('Help') ), order=100 ) item = current_menu.submenu('main.profile') account = _('My Account') if current_user.is_authenticated: patron = Patron.get_patron_by_email(current_user.email) if patron: account = patron.initial item.register( endpoint=None, text='{icon} <span class="{visible}">{account}</span>'.format( icon='<i class="fa fa-user"></i>', visible='visible-md-inline visible-lg-inline', account=account ), order=1 ) item = current_menu.submenu('main.profile.login') item.register( endpoint='security.login', endpoint_arguments_constructor=lambda: dict( next=request.full_path ), visible_when=lambda: not current_user.is_authenticated, text='{icon} {login}'.format( icon='<i class="fa fa-sign-in"></i>', login=_('Login') ), order=1 ) item = current_menu.submenu('main.profile.logout') item.register( endpoint='security.logout', endpoint_arguments_constructor=lambda: dict( next='/{viewcode}'.format(viewcode=request.view_args.get( 'viewcode', current_app.config.get( 'RERO_ILS_SEARCH_GLOBAL_VIEW_CODE')) ) ), visible_when=lambda: current_user.is_authenticated, text='{icon} {logout}'.format( icon='<i class="fa fa-sign-out"></i>', logout=_('Logout') ), order=1 ) item = current_menu.submenu('main.profile.signup') item.register( endpoint='security.register', visible_when=lambda: not current_user.is_authenticated, text='{icon} {signup}'.format( icon='<i class="fa fa-user-plus"></i>', signup=_('Sign Up') ), order=2 )