silverstripe-framework/core/i18nEntityProvider.php
Ingo Schommer 4ecb895b0a ENHANCEMENT Added i18nEntityProvider interface (see comments in #1625) incl. unit tests
MINOR documentation for i18nTextCollector

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@65022 467b73ca-7a2a-4603-9d3b-597d59a354a9
2008-11-01 13:26:08 +00:00

52 lines
1.6 KiB
PHP

<?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.
*
* @package sapphire
* @subpackage i18n
*/
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,
* PR_MEDIUM,
* '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()}.
*
* @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();
}
?>