src/i18n/TextCollection/i18nTextCollector.php
public function collectFromEntityProviders($filePath, Module $module = null)
    {
        $entities = array();
        $classes = ClassInfo::classes_for_file($filePath);
        foreach ($classes as $class) {
            // Skip non-implementing classes
            if (!class_exists($class) || !is_a($class, i18nEntityProvider::class, true)) {
                continue;
            }

            // Skip abstract classes
            $reflectionClass = new ReflectionClass($class);
            if ($reflectionClass->isAbstract()) {
                continue;
            }

            /** @var i18nEntityProvider $obj */
            $obj = singleton($class);
            $provided = $obj->provideI18nEntities();
            // Handle deprecated return syntax
            foreach ($provided as $key => $value) {
                // Detect non-associative result for any key
                if (is_array($value) && $value === array_values($value)) {
                    Deprecation::notice('5.0', 'Non-associative translations from providei18nEntities is deprecated');
                    $entity = array_filter([
                        'default' => $value[0],
                        'comment' => isset($value[1]) ? $value[1] : null,
                        'module' => isset($value[2]) ? $value[2] : null,
                    ]);
                    if (count($entity) === 1) {
                        $provided[$key] = $value[0];
                    } elseif ($entity) {
                        $provided[$key] = $entity;
                    } else {
                        unset($provided[$key]);
                    }
                }
            }
            $entities = array_merge($entities, $provided);
        }

        ksort($entities);
        return $entities;
    }
public function collectFromEntityProviders($filePath, Module $module = null)
    {
        $entities = array();
        $classes = ClassInfo::classes_for_file($filePath);
        foreach ($classes as $class) {
            // Skip non-implementing classes
            if (!class_exists($class) || !is_a($class, i18nEntityProvider::class, true)) {
                continue;
            }

            // Skip abstract classes
            $reflectionClass = new ReflectionClass($class);
            if ($reflectionClass->isAbstract()) {
                continue;
            }

            /** @var i18nEntityProvider $obj */
            $obj = singleton($class);
            $provided = $obj->provideI18nEntities();
            // Handle deprecated return syntax
            foreach ($provided as $key => $value) {
                // Detect non-associative result for any key
                if (is_array($value) && $value === array_values($value)) {
                    Deprecation::notice('5.0', 'Non-associative translations from providei18nEntities is deprecated');
                    $entity = array_filter([
                        'default' => $value[0],
                        'comment' => isset($value[1]) ? $value[1] : null,
                        'module' => isset($value[2]) ? $value[2] : null,
                    ]);
                    if (count($entity) === 1) {
                        $provided[$key] = $value[0];
                    } elseif ($entity) {
                        $provided[$key] = $entity;
                    } else {
                        unset($provided[$key]);
                    }
                }
            }
            $entities = array_merge($entities, $provided);
        }

        ksort($entities);
        return $entities;
    }
public function collectFromEntityProviders ( $ filePath , Module $ module = null ) { $ entities = array ( ) ; $ classes = ClassInfo :: classes_for_file ( $ filePath ) ; foreach ( $ classes as $ class ) { // Skip non-implementing classes if ( ! class_exists ( $ class ) || ! is_a ( $ class , i18nEntityProvider :: class , true ) ) { continue ; } // Skip abstract classes $ reflectionClass = new ReflectionClass ( $ class ) ; if ( $ reflectionClass -> isAbstract ( ) ) { continue ; } /** @var i18nEntityProvider $obj */ $ obj = singleton ( $ class ) ; $ provided = $ obj -> provideI18nEntities ( ) ; // Handle deprecated return syntax foreach ( $ provided as $ key => $ value ) { // Detect non-associative result for any key if ( is_array ( $ value ) && $ value === array_values ( $ value ) ) { Deprecation :: notice ( '5.0' , 'Non-associative translations from providei18nEntities is deprecated' ) ; $ entity = array_filter ( [ 'default' => $ value [ 0 ] , 'comment' => isset ( $ value [ 1 ] ) ? $ value [ 1 ] : null , 'module' => isset ( $ value [ 2 ] ) ? $ value [ 2 ] : null , ] ) ; if ( count ( $ entity ) === 1 ) { $ provided [ $ key ] = $ value [ 0 ] ; } elseif ( $ entity ) { $ provided [ $ key ] = $ entity ; } else { unset ( $ provided [ $ key ] ) ; } } } $ entities = array_merge ( $ entities , $ provided ) ; } ksort ( $ entities ) ; return $ entities ; }
Allows classes which implement i18nEntityProvider to provide
additional translation strings.

Not all classes can be instanciated without mandatory arguments,
so entity collection doesn't work for all SilverStripe classes currently

@uses i18nEntityProvider
@param string $filePath
@param Module $module
@return array
Allows classes which implement i18nEntityProvider to provide additional translation strings .