def initialize(supervisor): if supervisor.config.get('i18n.enabled'): supervisor.exts.commands.register('xmsgs', collect_messages, '--xmsgs', action='store_true', help='collect gettext messages') supervisor.exts.commands.register('cmsgs', compile_messages, '--cmsgs', action='store_true', help='compile gettext messages') default_locale = supervisor.config.get('i18n.default_locale', 'en') domain = supervisor.config.get('i18n.domain') locale_dir = os.path.join( supervisor.config['root'], supervisor.config.get('localedir', 'locales') ) locales = supervisor.config.get('i18n.locales', ['en']) langs = [(code, name) for code, name in LANGS if code in locales] supervisor.wsgi = I18NPlugin(supervisor.app, langs=langs, default_locale=default_locale, domain=domain, locale_dir=locale_dir)
def i18n_middleware(app): default_locale = exts.config.get('i18n.default_locale', 'en') domain = exts.config.get('i18n.domain') locale_dir = os.path.join(exts.config['root'], exts.config.get('localedir', 'locales')) locales = exts.config.get('i18n.locales', ['en']) langs = [(code, name) for code, name in LANGS if code in locales] return I18NPlugin(app, langs=langs, default_locale=default_locale, domain=domain, locale_dir=locale_dir)
from bottle_utils.i18n import I18NPlugin, i18n_path, i18n_url, lazy_gettext as _ bottle.BaseRequest.MEMFILE_MAX = 1024 * 1024 * 16 SESSION = { 'session.type': 'cookie', 'session.cookie_expires': 60 * 60 * 24 * 365, 'session.encrypt_key': "o(eaji3jgoijeh83", 'session.validate_key': True, } app = bottle.default_app() config = yaml.load(open("config.yaml")) sqlite = bottle.ext.sqlite.Plugin(dbfile='dugnad.db') app.install(sqlite) app = I18NPlugin(app, config['languages'], config['languages'][0][0], "lang") app = SessionMiddleware(app, SESSION) logging.basicConfig(level=logging.INFO) class Form: class Button: def __init__(self, blueprint): self.name = blueprint['name'] self.type = "button" def tohtml(self): s = "<button id='%s' name='%s'>%s</button>" % ( self.name, self.name, _(self.name)) return s
where(Number.time >= oldest_to_be_shown).group_by(Number.number).order_by(Number.time.desc(), Number.number) # filter numbers entered often enough # format numbers for later output display_output = sorted([{ 'num': n.number, 'count': int(n.count) } for n in numbers if int(n.count) >= MIN_COUNT][:DISPLAY_SIZE], key=lambda n: n['num']) since = format_datetime(oldest_to_be_shown, 'short', locale=get_valid_locale(request.locale)) return {'numbers': display_output, 'since': since, 'min_count': MIN_COUNT} @route('/pm-start') @view('static/pm-start.html') def enter(): return {'entered': []} # findet templates im gleichen Verzeichnis TEMPLATE_PATH.append(MOD_PATH) app = default_app() application = I18NPlugin(app, langs=LANGS, default_locale=DEFAULT_LOCALE, domain='messages', locale_dir=os.path.join(MOD_PATH, 'locales'))
bottle.TEMPLATE_PATH=("./views", "./templates") tabulator_root="/tabulator/" tabulator_root_path = ".%s" % tabulator_root css_root="/css/" css_root_path = ".%s" % css_root images_root="/images/" images_root_path = ".%s" % images_root save_root="/uploads/" save_root_path = ".%s" % save_root tapp = bottle.default_app() wsgi_app = I18NPlugin(tapp, langs=LANGS, default_locale=DEFAULT_LOCALE, locale_dir=LOCALES_DIR, domain='base' ) app = SessionMiddleware(wsgi_app, session_opts) logger = logging.getLogger('DMViewer') logger.setLevel(logging.DEBUG) ch = logging.StreamHandler() formatter = logging.Formatter('%(asctime)s %(name)s %(levelname)s: %(message)s') ch.setFormatter(formatter) logger.addHandler(ch) ## helper class PrettyFormsDict(FormsDict):