2008-11-01 14:26:08 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Dynamically provide translatable entites for the {@link i18n} logic.
|
|
|
|
* This is particularly handy for natural language strings in static variables
|
|
|
|
* of a class definition, as the _t() method can only be used in a runtime/instance
|
|
|
|
* context. The provideI18nEntities() method enables you to define your own entities
|
|
|
|
* with your custom naming, mostly involving either the variable name or the array
|
|
|
|
* key. With this in place, you can use a getter method to trigger translation
|
|
|
|
* of your values.
|
|
|
|
* For any statics containing natural language, never use the static directly -
|
|
|
|
* always wrap it in a getter.
|
|
|
|
*
|
2012-04-12 08:02:46 +02:00
|
|
|
* @package framework
|
2008-11-01 14:26:08 +01:00
|
|
|
* @subpackage i18n
|
2008-11-02 00:16:45 +01:00
|
|
|
* @uses i18nTextCollector->collectFromEntityProviders()
|
2008-11-01 14:26:08 +01:00
|
|
|
*/
|
|
|
|
interface i18nEntityProvider {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Example usage:
|
|
|
|
* <code>
|
|
|
|
* class MyTestClass implements i18nEntityProvider {
|
|
|
|
* function provideI18nEntities() {
|
|
|
|
* $entities = array();
|
|
|
|
* foreach($this->stat('my_static_array) as $key => $value) {
|
|
|
|
* $entities["MyTestClass.my_static_array_{$key}"] = array(
|
|
|
|
* $value,
|
2012-04-14 00:16:22 +02:00
|
|
|
*
|
2008-11-01 14:26:08 +01:00
|
|
|
* 'My context description'
|
|
|
|
* );
|
|
|
|
* }
|
|
|
|
* return $entities;
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* static function my_static_array() {
|
|
|
|
* $t_my_static_array = array();
|
|
|
|
* foreach(self::$my_static_array as $k => $v) {
|
|
|
|
* $t_my_static_array[$k] = _t("MyTestClass.my_static_array_{$key}", $v);
|
|
|
|
* }
|
|
|
|
* return $t_my_static_array;
|
|
|
|
* }
|
|
|
|
* }
|
|
|
|
* </code>
|
|
|
|
*
|
|
|
|
* Example usage in {@link DataObject->provideI18nEntities()}.
|
|
|
|
*
|
2009-02-02 00:49:53 +01:00
|
|
|
* You can ask textcollector to add the provided entity to a different module
|
|
|
|
* than the class is contained in by adding a 4th argument to the array:
|
|
|
|
* <code>
|
|
|
|
* class MyTestClass implements i18nEntityProvider {
|
|
|
|
* function provideI18nEntities() {
|
|
|
|
* $entities = array();
|
|
|
|
* $entities["MyOtherModuleClass.MYENTITY"] = array(
|
|
|
|
* $value,
|
2012-04-14 00:16:22 +02:00
|
|
|
*
|
2009-02-02 00:49:53 +01:00
|
|
|
* 'My context description',
|
|
|
|
* 'myothermodule'
|
|
|
|
* );
|
|
|
|
* }
|
|
|
|
* return $entities;
|
|
|
|
* }
|
|
|
|
* </code>
|
|
|
|
*
|
2008-11-01 14:26:08 +01:00
|
|
|
* @return array All entites in an associative array, with
|
|
|
|
* entity name as the key, and a numerical array of pseudo-arguments
|
|
|
|
* for _t() as a value.
|
|
|
|
*/
|
|
|
|
function provideI18nEntities();
|
|
|
|
}
|