Comments: on this page. Click to read or post your own.

Class Translatable

Description

The {Translatable} decorator allows your DataObjects to have versions in different languages, defining which fields are can be translated.

Common language names (e.g. 'en') are used in {Translatable} for database-entities. On the other hand, the file-based i18n-translations always have a "locale" (e.g. 'en_US').

You can enable {Translatabe} for any DataObject-subclass: <example> static $extensions = array( "Translatable('MyTranslatableVarchar', 'OtherTranslatableText')" ); </example>

Caution: Does not apply any character-set conversion, it is assumed that all content is stored and represented in UTF-8 (Unicode). Please make sure your database and HTML-templates adjust to this.

Caution: Further decorations of DataObject might conflict with this implementation, e.g. when overriding the get_one()-calls (which are already extended by {Translatable}).

Located in /sapphire/core/model/Translatable.php (line 28)

Object
   |
   --Extension
      |
      --DataObjectDecorator
         |
         --Translatable
Variable Summary
static boolean $bypass
static unknown_type $creatingFromID
static string $default_lang
static boolean $enabled
static boolean $language_decided
static string $reading_lang
static mixed $tableList
Method Summary
static string choose_site_lang ([$langsAvailable $langsAvailable = null])
static void creating_from (int $id)
static string current_lang ()
static string default_lang ()
static void disable ()
static void enable ()
static mixed get_by_lang (string $class, string $lang, [string $filter = ''], [string $sort = ''], [string $join = ""], [string $limit = ""], [string $containerClass = "DataObjectSet"], [string $having = ""])
static array get_langs_by_id (string $class, int $id)
static DataObject get_one (string $callerClass, [string $filter = ""], [boolean $cache = false], [string $orderby = ""])
static DataObject get_one_by_lang (string $class, string $lang, [string $filter = ''], [boolean $cache = false], [string $orderby = ""])
static DataObject get_original (string $class, string $originalLangID)
static boolean is_default_lang ()
static boolean is_enabled ()
static void set_default_lang ($lang $lang)
static void set_reading_lang (string $lang)
static boolean table_exists (mixed $table)
static void write (DataObject $object, string $lang)
Translatable __construct ( $translatableFields)
array allFieldsInTable (string $table)
void augmentDatabase ()
void augmentSQL (SQLQuery &$query)
void augmentWrite ( &$manipulation, SQLQuery $manipulation)
string baseTable ([ $stage = null])
void duplicateOrReplaceFields ( &$fields)
string extendWithSuffix (string $table)
array fieldsInExtraTables (string $table)
boolean isInAugmentedTable (string $clause, string $table)
boolean isVersionedTable (string $table)
void updateCMSFields ( &$fields)
Variables
static boolean $bypass = false (line 64)

Indicates whether the 'Lang' transformation when modifying queries should be bypassed If it's true

  • access: protected
static unknown_type $creatingFromID (line 78)

Dataobject's original ID when we're creating a new language version of an object

  • access: protected
static string $default_lang = 'en' (line 41)

The 'default' language.

  • access: protected
static boolean $enabled = false (line 35)

Indicates if the multilingual feature is enabled

  • access: protected
static boolean $language_decided = false (line 56)

Indicates if the start language has been determined using choose_site_lang

  • access: protected
static string $reading_lang = null (line 50)

The language in which we are reading dataobjects.

Usually stored in session, specific to the "site mode": either 'site' or 'cms'.

static mixed $tableList = null (line 71)

A cached list of existing tables

  • access: protected
array $original_values = null (line 90)

A map of the field values of the original (untranslated) DataObject record

  • access: protected
array $translatableFields (line 84)

An array of fields that can be translated.

  • access: protected

Inherited Variables

Inherited from DataObjectDecorator

DataObjectDecorator::$decoratable_statics

Inherited from Extension

Extension::$allowed_actions
Extension::$owner

Inherited from Object

Object::$builtInMethods
Object::$class
Object::$classConstructed
Object::$extensions
Object::$extension_instances
Object::$extraMethods
Object::$extraStatics
Object::$statics
Object::$static_cached
Methods
static method choose_site_lang (line 116)

Choose the language the site is currently on.

If $_GET['lang'] or $_COOKIE['lang'] is set, then it will use that language, and store it in the session. Otherwise it checks the session for a possible stored language, either from namespace to the site_mode ('site' or 'cms'), or for a 'global' language setting. The final option is the member preference.

static string choose_site_lang ([$langsAvailable $langsAvailable = null])
  • $langsAvailable $langsAvailable: array A numerical array of languages which are valid choices (optional)
static method creating_from (line 328)

When creating, set the original ID value

static void creating_from (int $id)
  • int $id
static method current_lang (line 171)

Get the current reading language.

static string current_lang ()
static method default_lang (line 146)

Get the current reading language.

static string default_lang ()
static method disable (line 310)

Disable the multilingual feature

static void disable ()
static method enable (line 302)

Enables the multilingual feature

static void enable ()
static method get_by_lang (line 251)

Get all the instances of the given class translated to the given language

  • return: The objects matching the conditions.
static mixed get_by_lang (string $class, string $lang, [string $filter = ''], [string $sort = ''], [string $join = ""], [string $limit = ""], [string $containerClass = "DataObjectSet"], [string $having = ""])
  • string $class: The name of the class
  • string $lang: The name of the language
  • string $filter: A filter to be inserted into the WHERE clause.
  • string $sort: A sort expression to be inserted into the ORDER BY clause.
  • string $join: A single join clause. This can be used for filtering, only 1 instance of each DataObject will be returned.
  • string $limit: A limit expression to be inserted into the LIMIT clause.
  • string $containerClass: The container class to return the results in.
  • string $having: A filter to be inserted into the HAVING clause.
static method get_langs_by_id (line 278)

Get a list of languages in which a given element has been translated

  • return: List of languages
static array get_langs_by_id (string $class, int $id)
  • string $class: Name of the class of the element
  • int $id: ID of the element
static method get_one (line 214)

Get a singleton instance of a class in the most convenient language (@see choose_site_lang())

static DataObject get_one (string $callerClass, [string $filter = ""], [boolean $cache = false], [string $orderby = ""])
  • string $callerClass: The name of the class
  • string $filter: A filter to be inserted into the WHERE clause.
  • boolean $cache: Use caching (default: false)
  • string $orderby: A sort expression to be inserted into the ORDER BY clause.
static method get_one_by_lang (line 197)

Get a singleton instance of a class in the given language.

static DataObject get_one_by_lang (string $class, string $lang, [string $filter = ''], [boolean $cache = false], [string $orderby = ""])
  • string $class: The name of the class.
  • string $lang: The name of the language.
  • string $filter: A filter to be inserted into the WHERE clause.
  • boolean $cache: Use caching (default: false)
  • string $orderby: A sort expression to be inserted into the ORDER BY clause.
static method get_original (line 265)

Get a record in his original language version.

static DataObject get_original (string $class, string $originalLangID)
  • string $class: The name of the class.
  • string $originalLangID: The original record id.
static method is_default_lang (line 163)

Check whether the default and current reading language are the same.

  • return: Return true if both default and reading language are the same.
static boolean is_default_lang ()
static method is_enabled (line 319)

Check whether multilingual support has been enabled

  • return: True if enabled
static boolean is_enabled ()
static method set_default_lang (line 155)

Set default language.

static void set_default_lang ($lang $lang)
  • $lang $lang: String
static method set_reading_lang (line 182)

Set the reading language, either namespaced to 'site' (website content) or 'cms' (management backend).

static void set_reading_lang (string $lang)
  • string $lang: New reading language.
static method table_exists (line 99)

Checks if a table given table exists in the db

  • return: Returns true if $table exists.
static boolean table_exists (mixed $table)
  • mixed $table: Table name
static method write (line 291)

Writes an object in a certain language. Use this instead of $object->write() if you want to write an instance in a determinated language independently of the currently set working language

static void write (DataObject $object, string $lang)
  • DataObject $object: Object to be written
  • string $lang: The name of the language
Constructor __construct (line 340)

Construct a new Translatable object.

  • var: The different fields of the object that can be translated.
Translatable __construct ( $translatableFields)
  • $translatableFields

Redefinition of:
Object::__construct()
allFieldsInTable (line 712)

Get a list of fields in the {$table}_lang table

array allFieldsInTable (string $table)
  • string $table: Table name
augmentDatabase (line 462)
void augmentDatabase ()

Redefinition of:
DataObjectDecorator::augmentDatabase()
Update the database schema as required by this extension.
augmentSQL (line 350)
void augmentSQL (SQLQuery &$query)

Redefinition of:
DataObjectDecorator::augmentSQL()
Edit the given query object to support queries for this extension
augmentWrite (line 510)

Augment a write-record request.

void augmentWrite ( &$manipulation, SQLQuery $manipulation)
  • SQLQuery $manipulation: Query to augment.
  • &$manipulation

Redefinition of:
DataObjectDecorator::augmentWrite()
Augment a write-record request.
baseTable (line 743)

Return the base table - the class that directly extends DataObject.

string baseTable ([ $stage = null])
  • $stage
duplicateOrReplaceFields (line 637)
  • access: protected
void duplicateOrReplaceFields ( &$fields)
  • &$fields
extendWithSuffix (line 755)

Extends $table with a suffix if required

  • return: Extended table name
string extendWithSuffix (string $table)
  • string $table: Name of the table
fieldsInExtraTables (line 679)

Get a list of fields from the tables created by this extension

  • return: Map where the keys are db, indexes and the values are the table fields
array fieldsInExtraTables (string $table)
  • string $table: Name of the table
hasOwnTranslatableFields (line 441)

Determine if the DataObject has any own translatable field (not inherited).

boolean hasOwnTranslatableFields ()
isInAugmentedTable (line 426)

Check whether a WHERE clause should be applied to the augmented table

  • return: True if the clause can be applied to the augmented table
boolean isInAugmentedTable (string $clause, string $table)
  • string $clause: Where clause that need to know if can be applied to the augmented (suffixed) table
  • string $table: Name of the non-augmented table
isVersionedTable (line 457)

Determine if a table needs Versioned support This is called at db/build time

boolean isVersionedTable (string $table)
  • string $table: Table name
updateCMSFields (line 573)

Change the member dialog in the CMS

This method updates the forms in the cms to allow the translations for the defined translatable fields.

void updateCMSFields ( &$fields)

Redefinition of:
DataObjectDecorator::updateCMSFields()
This function is used to provide modifications to the form in the CMS by the decorator. By default, no changes are made.

Inherited Methods

Inherited From DataObjectDecorator

DataObjectDecorator::augmentDatabase()
DataObjectDecorator::augmentSQL()
DataObjectDecorator::augmentWrite()
DataObjectDecorator::extraDBFields()
DataObjectDecorator::loadExtraDBFields()
DataObjectDecorator::updateCMSFields()
DataObjectDecorator::updateFormFields()
DataObjectDecorator::updateSummaryFields()
DataObjectDecorator::updateSummaryFieldsExcludeExtra()

Inherited From Extension

Extension::setOwner()

Inherited From Object

Object::__construct()
Object::addMethodsFrom()
Object::addStaticVars()
Object::addWrapperMethod()
Object::add_extension()
Object::allMethodNames()
Object::buildMethodList()
Object::cacheToFile()
Object::cacheToFileWithArgs()
Object::create()
Object::createMethod()
Object::defineMethods()
Object::exists()
Object::extend()
Object::extInstance()
Object::getCustomClass()
Object::hasExtension()
Object::hasMethod()
Object::invokeWithExtensions()
Object::is_a()
Object::loadCache()
Object::parentClass()
Object::sanitiseCachename()
Object::saveCache()
Object::set_stat()
Object::set_uninherited()
Object::stat()
Object::strong_create()
Object::uninherited()
Object::useCustomClass()
Object::__call()
Object::__toString()
blog comments powered by Disqus

Documentation generated on Sun, 19 Oct 2008 06:47:10 +1300 by phpDocumentor 1.3.2