core.modules.translation

Module Contents

Classes

Creator

Generic enumeration.

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.

class core.modules.translation.Creator

Bases: enum.Enum

Generic enumeration.

Derive from this class to define new enumerations.

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
database_adapters
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
roles
cloneSkel
_last_reload
adminInfo()
addSkel()

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

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()
dump(*, pattern=[], language=[])

Dumps translations as JSON.

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

  • language (list[str]) – Allows to request a specific language.

Return type:

dict[str, str] | 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]) –