core.modules.translation

Classes

Creator

Create a collection of name/value pairs.

TranslationSkel

This is a container-object holding information about one database entity.

Translation

The Translation module is a system module used by the ViUR framework for its internationalization capabilities.

Module Contents

class core.modules.translation.Creator(*args, **kwds)

Bases: enum.Enum

Create a collection of name/value pairs.

Example enumeration:

>>> class Color(Enum):
...     RED = 1
...     BLUE = 2
...     GREEN = 3

Access them by:

  • attribute access:

    >>> Color.RED
    <Color.RED: 1>
    
  • value lookup:

    >>> Color(1)
    <Color.RED: 1>
    
  • name lookup:

    >>> Color['RED']
    <Color.RED: 1>
    

Enumerations can be iterated over, and know how many members they have:

>>> len(Color)
3
>>> list(Color)
[<Color.RED: 1>, <Color.BLUE: 2>, <Color.GREEN: 3>]

Methods can be added to enumerations, and members can have their own attributes – see the documentation for details.

VIUR = 'viur'
USER = 'user'
class core.modules.translation.TranslationSkel(*args, **kwargs)

Bases: viur.core.skeleton.Skeleton

This is a container-object holding information about one database entity.

It has to be sub-classed with individual information about the kindName of the entities and its specific data attributes, the so called bones. The Skeleton stores its bones in an OrderedDict-Instance, so the definition order of the contained bones remains constant.

Variables:
  • key (server.bones.BaseBone) – This bone stores the current database key of this entity. Assigning to this bones value is dangerous and does not affect the actual key its stored in.

  • creationdate (server.bones.DateBone) – The date and time where this entity has been created.

  • changedate (server.bones.DateBone) – The date and time of the last change to this entity.

kindName = 'viur-translations'

Specifies the entity kind name this Skeleton is associated with. Will be determined automatically when not explicitly set.

database_adapters

Custom database adapters. Allows to hook special functionalities that during skeleton modifications.

name
tr_key
translations
translations_missing
default_text
hint
usage_filename
usage_lineno
usage_variables
creator
public
classmethod read(skel, *args, **kwargs)

Read Skeleton with key from the datastore into the Skeleton. If not key is given, skel[“key”] will be used.

Reads all available data of entity kind kindName and the key key from the Datastore into the Skeleton structure’s bones. Any previous data of the bones will discard.

To store a Skeleton object to the Datastore, see write().

Parameters:
  • key – A viur.core.db.Key, string, or int; from which the data shall be fetched. If not provided, skel[“key”] will be used.

  • create – Allows to specify a dict or initial callable that is executed in case the Skeleton with the given key does not exist, it will be created.

Returns:

None on error, or the given SkeletonInstance on success.

classmethod write(skel, **kwargs)

Write current Skeleton to the datastore.

Stores the current data of this instance into the database. If an key value is set to the object, this entity will ne updated; Otherwise a new entity will be created.

To read a Skeleton object from the data store, see read().

Parameters:
  • key – Allows to specify a key that is set to the skeleton and used for writing.

  • update_relations – If False, this entity won’t be marked dirty; This avoids from being fetched by the background task updating relations.

Returns:

The Skeleton.

class core.modules.translation.Translation(*args, **kwargs)

Bases: viur.core.prototypes.list.List

The Translation module is a system module used by the ViUR framework for its internationalization capabilities.

kindName = 'viur-translations'

Name of the datastore kind that is handled by this module.

This information is used to bind a specific viur.core.skeleton.Skeleton-class to this prototype. By default, it is automatically determined from the module’s class name, so a module named Animal refers to a Skeleton named AnimalSkel and its kindName is animal.

For more information, refer to the function _resolveSkelCls().

adminInfo()

This is a dict holding the information necessary for the Vi/Admin to handle this module.

name: str

Human-readable module name that will be shown in the admin tool.

handler: str (list, tree or singleton):

Allows to override the handler provided by the module. Set this only when really necessary, otherwise it can be left out and is automatically injected by the Module’s prototype.

icon: str

(Optional) Either the Shoelace icon library name or a path relative to the project’s deploy folder (e.g. /static/icons/viur.svg) for the icon used in the admin tool for this module.

columns: List[str]

(Optional) List of columns (bone names) that are displayed by default. Used only by the List handler.

filter: Dict[str, str]

(Optional) Dictionary of additional parameters that will be send along when fetching entities from the server. Can be used to filter the entities being displayed on the client-side.

display: str (“default”, “hidden” or “group”)

(Optional) “hidden” will hide the module in the admin tool’s main bar. (itwill not be accessible directly, however it’s registered with the frontend so it can be used in a relational bone). “group” will show this module in the main bar, but it will not be clickable. Clicking it will just try to expand it (assuming there are additional views defined).

preview: Union[str, Dict[str, str]]

(Optional) A url that will be opened in a new tab and is expected to display the entity selected in the table. Can be “/{{module}}/view/{{key}}”, with {{module}} and {{key}} getting replaced as needed. If more than one preview-url is needed, supply a dictionary where the key is the URL and the value the description shown to the user.

views: List[Dict[str, t.Any]]

(Optional) List of nested adminInfo like dictionaries. Used to define additional views on the module. Useful f.e. for an order module, where you want separate list of “payed orders”, “unpayed orders”, “orders waiting for shipment”, etc. If such views are defined, the top-level entry in the menu bar will expand if clicked, revealing these additional filters.

actions: List[str]

(Optional) List of actions supported by this modules. Actions can be defined by the frontend (like “add”, “edit”, “delete” or “preview”); it can be an action defined by a plugin loaded by the frontend; or it can be a so called “server side action” (see “customActions” below)

customActions: Dict[str, dict]

(Optional) A mapping of names of server-defined actions that can be used in the actions list above to their definition dictionary. See …. for more details.

disabledActions: List[str, dict]

(Optional) A list of disabled actions. The frontend will inject default actions like add or edit even if they’re not listed in actions. Listing them here will prevent that. It’s up to the frontend to decide if that action won’t be visible at all or it’s button just being disabled.

sortIndex: int

(Optional) Defines the order in which the modules will appear in the main bar in ascrending order.

indexedBones: List[str]

(Optional) List of bones, for which an (composite?) index exists in this view. This allows the fronted to signal the user that a given list can be sorted or filtered by this bone. If no additional filters are enforced by the listFilter and filter is not set, this should be all bones which are marked as indexed.

changeInvalidates: List[str]

(Optional) A list of module-names which depend on the entities handled from this module. This allows the frontend to invalidate any caches in these depended modules if the data in this module changes. Example: This module may be a list-module handling the file_rootNode entities for the file module, so a edit/add/deletion action on this module should be reflected in the rootNode-selector in the file-module itself. In this case, this property should be set to ["file"].

moduleGroup: str

(Optional) If set, should be a key of a moduleGroup defined in …. .

editViews: Dict[str, t.Any]

(Optional) If set, will embed another list-widget in the edit forms for a given entity. See …. for more details.

If this is a function, it must take no parameters and return the dictionary as shown above. This can be used to customize the appearance of the Vi/Admin to individual users.

roles

Allows to specify role settings for a module.

Defaults to no role definition, which ignores the module entirely in the role-system. In this case, access rights can still be set individually on the user’s access bone.

A “*” wildcard can either be used as key or as value to allow for “all roles”, or “all rights”.

# Example
roles = {
    "*": "view",                # Any role may only "view"
    "editor": ("add", "edit"),  # Role "editor" may "add" or "edit", but not "delete"
    "admin": "*",               # Role "admin" can do everything
}
addSkel()

Returns a custom TranslationSkel where the name is editable. The name becomes part of the key.

cloneSkel

Retrieve a new instance of a viur.core.skeleton.Skeleton that is used by the application for cloning an existing entry from the list.

The default is a SkeletonInstance returned by baseSkel().

Like in viewSkel(), the skeleton can be post-processed. Bones that are being removed aren’t visible and cannot be set, but it’s also possible to just set a bone to readOnly (revealing it’s value to the user, but preventing any modification.

See also

viewSkel(), editSkel(), baseSkel()

Returns:

Returns a SkeletonInstance for editing an entry.

onAdded(*args, **kwargs)

Hook function that is called after adding an entry.

It should be overridden for a module-specific behavior. The default is writing a log entry.

Parameters:

skel – The Skeleton that has been added.

See also

add(), , onAdd()

onEdited(*args, **kwargs)

Hook function that is called after modifying an entry.

It should be overridden for a module-specific behavior. The default is writing a log entry.

Parameters:

skel – The Skeleton that has been modified.

See also

edit(), onEdit()

onDeleted(*args, **kwargs)

Hook function that is called after deleting an entry.

It should be overridden for a module-specific behavior. The default is writing a log entry.

Parameters:

skel – The Skeleton that has been deleted.

See also

delete(), onDelete()

_reload_translations()
_last_reload = None
dump(*, pattern=None, language=None)

Dumps translations as JSON.

Parameters:
  • pattern (list[str] | None) – Optional, provide fnmatch-style translation key filter patterns of the translations wanted.

  • language (list[str] | None) – Allows to request a specific language. By default, the language of the current request is used.

Returns:

A dictionary with translations as JSON. Structure: {language: {key: value, ...}, ...}

Return type:

dict[str, dict[str, str]]

Example calls:

  • /json/_translation/dump?pattern=viur.* get viur.*-translations for current language

  • /json/_translation/dump?pattern=viur.*&language=en for english translations

  • /json/_translation/dump?pattern=viur.*&language=en&language=de for english and german translations

  • /json/_translation/dump?pattern=viur.*&language=* for all available language

get_public(*, languages=[], **kwargs)
Parameters:

languages (list[str])