# -*- coding: utf-8 -*- """ MoinMoin - show plugin with fall-back for non-native languages @copyright: 2007 by Daniel de Kok @license: GNU GPL """ from MoinMoin.Page import Page nonEnglishLangs = ['es', 'fr', 'nl'] unknownPageMessages = { 'nl': 'Er bestaat geen vertaling van deze pagina, daarom wordt de ' + \ 'Engelstalige pagina getoond!', } def execute(pagename, request): page = Page(request, pagename) # If the requested page exists, all is fine, and we can return if page.exists(): page.send_page(request) return # Does the page name have the form /Foo/Bar? pageParts = pagename.split('/') if len(pageParts) > 0 and pageParts[0] in nonEnglishLangs: # Seems that a non-English page was requested that does # not exist, look if the English page exists. If so, show it. lang = pageParts[0] # pageParts[0] = 'en' del pageParts[0] # Bogus page request? if pageParts[0] in nonEnglishLangs: page.send_page(request) return tryPage = Page(request, '/'.join(pageParts)) if tryPage.exists(): if unknownPageMessages.has_key(lang): msg = unknownPageMessages[lang] else: msg = 'Currently, there is no translation available for this page, ' + \ 'the English page is shown instead!' tryPage.send_page(request, msg = msg) return # The page does not exist, and an English page is also absent. page.send_page(request)