Toplevel functions

server.setup(modules, render=None, default='html')

Define whats going to be served by this instance.

  • config (module | object) – Usually the module provided as modules directory within the application.
  • renders (module | dict) – Usually the module server.renders, or a dictionary renderName => renderClass.
  • default (str) – Name of the renderer, which will form the root of the application. This will be the renderer, which wont get a prefix, usually html. (=> /user instead of /html/user)

Configures default language to lang.

Parameters:lang (str) – Name of the language module to use by default.
server.setDefaultDomainLanguage(domain, lang)
server.translate(key, **kwargs)

Translate key into language text pendant.

This function is part of ViURs language support facilities for supporting internationalization (i18n).

Translations are provided in the applications translations module in form of a dict, where the keys should be the language strings in the project’s major language (usually english), and the values the strings provided in the particular language implemented. The translation key strings must be given in a lower-case order, altought they may be capitalized or upper-case written. If no key is found within a specific translation, it is directly used as the output string.

The strings may contain placeholders in form {{placeholer}}, which can be assigned via the kwargs argument.

translate() is also provided as _() as global function.

In this simple example, a file translations/ is implemented with the content:

de = {
                "welcome to viur": u"Willkommen in ViUR",
                "hello {{user}}!": u"Hallo, {{user}}!"

To support internationalization, it is simply done this way:

txt = _( "Hello {{user}}!", user="John Doe" ) + " - "  + _( "Welcome to ViUR" )

Language support is also provided in Jinja2-templates like this:

{{ _( "Hello {{user}}!", user="John Doe" ) }} - {{ _( "Welcome to ViUR" ) }}

This will both output “Hello John Doe! - Welcome to ViUR” in an english-configured language environment, and “Hallo John Doe! - Willkommen in ViUR” in a german-configured language environment.

The current session language (or default language) can be overridden with _lang, e.g.

txt = _( "Hello {{user}}!", user="John Doe" ) + " - "  + _( "Welcome to ViUR", lang="en" )

will result in “Hallo John Doe! - Welcome to ViUR” in a german-configured language environment.

  • key (str) – The key value that should be translated; If no key is found in the configured language, key is directly used.
  • kwargs – May contain place-holders replaced as {{placeholer}} within the key or translation. The special-value _lang overrides the current language setting.

Translated text or key, with replaced placeholders, if given.

Return type: