src/Extension/FluentBadgeExtension.php
public function getBadge(DataObject $record)
    {
        /** @var Locale $currentLocale */
        $currentLocale = Locale::getCurrentLocale();

        $badgeClasses = ['badge', 'fluent-badge'];
        if ($currentLocale->getIsDefault()) {
            // Current locale should always show a "default" or green state badge
            $badgeClasses[] = 'fluent-badge--default';
            $tooltip = _t(__CLASS__ . '.BadgeDefault', 'Default locale');
        } elseif ($record->existsInLocale($currentLocale->Locale)) {
            // If the object has been localised in the current locale, show a "localised" state
            $badgeClasses[] = 'fluent-badge--localised';
            $tooltip = _t(__CLASS__ . '.BadgeInvisible', 'Localised in {locale}', [
                'locale' => $currentLocale->getTitle(),
            ]);
        } else {
            // Otherwise the state is that it hasn't yet been localised in the current locale, so is "invisible"
            $badgeClasses[] = 'fluent-badge--invisible';
            $tooltip = _t(__CLASS__ . '.BadgeLocalised', '{type} is not visible in this locale', [
                'type' => $record->i18n_singular_name(),
            ]);
        }

        return DBField::create_field(
            'HTMLFragment',
            sprintf(
                '<span class="%s" title="%s">%s</span>',
                implode(' ', $badgeClasses),
                $tooltip,
                $record->getSourceLocale()->getBadgeLabel()
            )
        );
    }
public function getBadge(DataObject $record)
    {
        /** @var Locale $currentLocale */
        $currentLocale = Locale::getCurrentLocale();

        $badgeClasses = ['badge', 'fluent-badge'];
        if ($currentLocale->getIsDefault()) {
            // Current locale should always show a "default" or green state badge
            $badgeClasses[] = 'fluent-badge--default';
            $tooltip = _t(__CLASS__ . '.BadgeDefault', 'Default locale');
        } elseif ($record->existsInLocale($currentLocale->Locale)) {
            // If the object has been localised in the current locale, show a "localised" state
            $badgeClasses[] = 'fluent-badge--localised';
            $tooltip = _t(__CLASS__ . '.BadgeInvisible', 'Localised in {locale}', [
                'locale' => $currentLocale->getTitle(),
            ]);
        } else {
            // Otherwise the state is that it hasn't yet been localised in the current locale, so is "invisible"
            $badgeClasses[] = 'fluent-badge--invisible';
            $tooltip = _t(__CLASS__ . '.BadgeLocalised', '{type} is not visible in this locale', [
                'type' => $record->i18n_singular_name(),
            ]);
        }

        return DBField::create_field(
            'HTMLFragment',
            sprintf(
                '<span class="%s" title="%s">%s</span>',
                implode(' ', $badgeClasses),
                $tooltip,
                $record->getSourceLocale()->getBadgeLabel()
            )
        );
    }
public function getBadge ( DataObject $ record ) { /** @var Locale $currentLocale */ $ currentLocale = Locale :: getCurrentLocale ( ) ; $ badgeClasses = [ 'badge' , 'fluent-badge' ] ; if ( $ currentLocale -> getIsDefault ( ) ) { // Current locale should always show a "default" or green state badge $ badgeClasses [ ] = 'fluent-badge--default' ; $ tooltip = _t ( __CLASS__ . '.BadgeDefault' , 'Default locale' ) ; } elseif ( $ record -> existsInLocale ( $ currentLocale -> Locale ) ) { // If the object has been localised in the current locale, show a "localised" state $ badgeClasses [ ] = 'fluent-badge--localised' ; $ tooltip = _t ( __CLASS__ . '.BadgeInvisible' , 'Localised in {locale}' , [ 'locale' => $ currentLocale -> getTitle ( ) , ] ) ; } else { // Otherwise the state is that it hasn't yet been localised in the current locale, so is "invisible" $ badgeClasses [ ] = 'fluent-badge--invisible' ; $ tooltip = _t ( __CLASS__ . '.BadgeLocalised' , '{type} is not visible in this locale' , [ 'type' => $ record -> i18n_singular_name ( ) , ] ) ; } return DBField :: create_field ( 'HTMLFragment' , sprintf ( '<span class="%s" title="%s">%s</span>' , implode ( ' ' , $ badgeClasses ) , $ tooltip , $ record -> getSourceLocale ( ) -> getBadgeLabel ( ) ) ) ; }
Given a record with Fluent enabled, return a badge that represents the state of it in the current locale

@param DataObject&FluentVersionedExtension $record
@return DBField
Given a record with Fluent enabled return a badge that represents the state of it in the current locale