Version: current

# Interface i18nEntityProvider

Dynamically provide translatable entites for the `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.

### Direct known implementers

`CMSMenu`, `DataObject`, `SiteTree`

### Indirect known implementers

`AdditionalMenuWidget`, `AdditionalMenuWidget_Item`, `BaseObjectCategory`, `Image_Cached`, `Import1CLog`, `Import1CLog_File`, `Import1CLog_Item`, `Import1CLog_Task`, `ImportCatalog1C_PriceType`, `ImportCatalog1C_ProductProp`, `LoginAttempt`, `LogItem`, `MapObject`, `BookingAdminPage`, `MapObjectGroup`, `MapPage`, `Material3D_File`, `MediawebPage`, `MediawebPage_File`, `MediawebPage_Image`, `MediawebPage_Photo`, `Member`, `MemberPassword`, `Monument`, `BookingOrder`, `MonumentCatalog`, `MonumentForm`, `MonumentGalleryItem`, `MonumentPhotoGallery`, `MP3`, `NewsArchive`, `NewsEntry`, `NewsHolder`, `NewsHomepageWidget`, `Newsletter`, `BookingOrder_StatusLog`, `Newsletter_Recipient`, `Newsletter_SentRecipient`, `NewsletterEmailBlacklist`, `NewsletterType`, `NewsSidebarWidget`, `Notification`, `Order`, `Order_StatusLog`, `OrderDataObject`, `OrderItem`, `BookingPage`, `OrderService`, `OrderServiceOrder`, `Page`, `PageComment`, `PageMenuWidget`, `Payment`, `PaymentMethod`, `PaymentType`, `PayPalPayment`, `Permission`, `BookingPaymentMethod`, `PermissionRole`, `PermissionRoleCode`, `Person`, `PhotoAlbumHomepageWidget`, `PhotoAlbumItem`, `PhotoAlbumPage`, `PhotoGalleryHomepageWidget`, `PhotoGalleryHomepageWidget_Item`, `PhotoGalleryPage`, `PhotoGalleryWidget`, `BookingService`, `Polishing`, `Poll`, `PollAnswer`, `PollSidebarWidget`, `PortraitType`, `PriceListWidget`, `Product`, `ProductImportLog`, `ProductImportLog_Item`, `ProductParam`, `ButtonsBlockHomepageWidget`, `ProductParamValue`, `ProductSearchPage`, `ProductVariation`, `ProfilePage`, `PublHolder`, `Publication`, `PublicationWidget`, `QueuedEmail`, `RatePeriod`, `RatingDataObject`, `ButtonsBlockHomepageWidget_Item`, `RealtyImportLog`, `RealtyImportLog_Item`, `RedirectEntry`, `RedirectorPage`, `RegionRestriction`, `RegistrationPage`, `RelatedPageLink`, `Room`, `RoomCatalog`, `RoomOrder`, `CallBackWidget`, `RoomOrderPerson`, `RoomRate`, `RoomService`, `RoomServiceOrder`, `SberbankPayment`, `SearchWidget`, `SeparateHomepageWidget`, `SeparateSidebarWidget`, `ServiceOrder`, `ShippingMethod`, `Address`, `CarouselHomepageWidget`, `SidebarWidget`, `SidebarWidgetArea`, `SimpleOrderData`, `SimpleOrderForm`, `SimpleOrderPage`, `SiteConfig`, `SliderHomepageWidget`, `SliderHomepageWidget_Item`, `Socle`, `SocleSection`, `CarouselHomepageWidget_Item`, `SocleSize`, `SpecialCatalog`, `SpecialCatalogHomepageWidget`, `SpecialCatalogSidebarWidget`, `StartCatalog`, `SubmittedFileField`, `SubmittedForm`, `SubmittedFormField`, `SubscribeForm`, `SubscribeWidget`, `CartPage`, `SubsectionMenuWidget`, `Subsite`, `Subsite_Template`, `SubsiteDomain`, `SubsitesSelectorPage`, `SubsitesVirtualPage`, `TableShippingMethod`, `TableShippingRate`, `TextAnonsWidget`, `TextAnonsWidget_Item`, `CartWidget`, `TextBlockHomepageWidget`, `TextBlockSidebarWidget`, `Texture3D_File`, `UnitellerPayment`, `UnsubscribeRecord`, `UserDefinedForm`, `UserDefinedForm_EmailRecipient`, `VAT`, `VideoBankPage`, `VideoCategory`, `Catalog`, `VideoEntry`, `VideoFile`, `VirtualPage`, `VirtualProduct`, `VKNotificationQueue`, `WeatherSidebarWidget`, `WebylonWidget`, `WebylonWidget_Item`, `WebylonWidgetArea`, `WeightTableShippingMethod`, `CatalogFilter`, `WeightTableShippingRate`, `Widget`, `WidgetArea`, `YaMoneyPayment`, `YandexMapsHomepageWidget`, `YandexMapsWidget`, `CatalogFilterSidebarWidget`, `CatalogRubricsHomepageWidget`, `CheckoutPage`, `ChequePayment`, `AdvancedSliderHomepageWidget`, `ConsultantWidget`, `ContactsBlockWidget`, `ContactsPage`, `CostTableShippingMethod`, `CostTableShippingRate`, `CurrencyWidget`, `CustomMenuHolder`, `CustomMenuItem`, `CustomPayment`, `DataObjectFileTracking`, `AdvancedSliderHomepageWidget_Item`, `DocPage`, `DocumentDirection`, `DocumentHaving`, `DocumentItem`, `DocumentPage_File`, `DocumentsPage`, `DocumentType`, `EditableCheckbox`, `EditableCheckboxGroupField`, `EditableCountryDropdownField`, `Announcement`, `EditableDateField`, `EditableDateTimeField`, `EditableDropdown`, `EditableEmailField`, `EditableFileField`, `EditableFormField`, `EditableFormHeading`, `EditableHiddenField`, `EditableLiteralField`, `EditableMemberListField`, `AnnouncementHolder`, `EditableMultipleOptionField`, `EditableNumericField`, `EditableOption`, `EditablePhoneField`, `EditableRadioField`, `EditableSiteAgreementField`, `EditableSpamProtectionField`, `EditableTextField`, `EditableTimeField`, `Email_BounceRecord`, `AuthFormWidget`, `Epitaph`, `ErrorPage`, `Event`, `EventCalendarWidget`, `EventHolder`, `FaqHolder`, `FAQHomepageWidget`, `FaqQuestion`, `FaqSection`, `FAQSidebarWidget`, `BannerWidget`, `FavoritePage`, `FavoriteProductsSidebarWidget`, `FeedbackHomepageWidget`, `File`, `FixedShippingMethod`, `FlowerGarden`, `FlowerGarden_Size`, `FLV`, `Folder`, `Group`, `BannerWidget_Item`, `Guestbook`, `GuestbookEntry`, `GuestbookWidget`, `HomePage`, `HomepageWidget`, `HomepageWidgetArea`, `HouseCatalogSearchWidget`, `HTMLBlockHomepageWidget`, `HTMLBlockSidebarWidget`, `Image`

Package: sapphire\i18n
Uses: ``i18nTextCollector::collectFromEntityProviders()``
Used by: ``i18nTextCollector``
Used by: ``i18nTextCollector::collectFromEntityProviders()``
Located at sapphire/core/i18nEntityProvider.php

## Methods summary

`public array` | # `provideI18nEntities( )` 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; } Example usage:
    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;
    }
    }
Example usage in DataObject->provideI18nEntities(). 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:
    class MyTestClass implements i18nEntityProvider {
    function provideI18nEntities() {
            $entities = array();
                    $entities["MyOtherModuleClass.MYENTITY"] = array(
                            $value,
                            PR_MEDIUM,
                            'My context description',
                            'myothermodule'
                    );
            }
            return $entities;
    }
#### Returns `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.

### Magic methods summary

[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the Silverstripe Forums to ask development related questions. -