assembl.models.langstrings module

Classes for multilingual strings, using automatic or manual translation

class assembl.models.langstrings.LangString(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base

A multilingual string, composed of many LangStringEntry

add_entry(entry, allow_replacement=True)[source]

Add a LangStringEntry to the langstring. Previous versions with the same language will be tombstoned, and translations based on such a version will be suppressed.

classmethod create(value, locale_code='und')[source]

Create an instance. Not used.

classmethod create_localized_langstring(trans_string, desired_locales=None, known_translations=None)[source]

Construct a langstring from a localized string. Call with a TranslationString.

remove_translations_of(entry)[source]

Remove all translations based on this code.

send_to_changes(connection, operation=<CrudOperation.DELETE: -1>, discussion_id=None, view_def='changes')[source]

Ask for this object to be sent on the changes websocket.

See assembl.tasks.changes_router.

user_can(user_id, operation, permissions)[source]

Whether the user, with the given permissions, can perform the given Crud operation on this instance.

class assembl.models.langstrings.LangStringEntry(session=None, *args, **kwargs)[source]

Bases: assembl.lib.history_mixin.TombstonableMixin, sqlalchemy.ext.declarative.api.Base

A string bound to a given locale. Many of those form a LangString

error_code

Type of error from the translation server

error_count

Errors from the translation server

locale_confirmed

Locale inferred from discussion agrees with identification_data

populate_from_context(context)[source]

If object created in this context, populate some relations from that context.

This is the magic fallback, ideally define the relationships you want populated explicitly in subclasses of this.

send_to_changes(connection, operation=<CrudOperation.DELETE: -1>, discussion_id=None, view_def='changes')[source]

Ask for this object to be sent on the changes websocket.

See assembl.tasks.changes_router.

user_can(user_id, operation, permissions)[source]

Whether the user, with the given permissions, can perform the given Crud operation on this instance.

class assembl.models.langstrings.LocaleLabel(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base

Allows to obtain the name of locales (in any target locale, incl. itself)

SPECIAL_LOCALES = ['und', 'zxx', 'mul']

Note: The name of locales follow Posix locale conventions: lang(_Script)(_COUNTRY), (eg zh_Hant_HK, but script can be elided (eg fr_CA) if only one script for language, as per http://www.iana.org/assignments/language-subtag-registry/language-subtag-registry