src/Date.php
public static function translateTimeString($time, $from = null, $to = null, $mode = -1)
    {
        // Don't run translations for english.
        if (static::getLocale() == 'en') {
            return $time;
        }

        // All the language file items we can translate.
        $keys = [
            'january',
            'february',
            'march',
            'april',
            'may',
            'june',
            'july',
            'august',
            'september',
            'october',
            'november',
            'december',
            'monday',
            'tuesday',
            'wednesday',
            'thursday',
            'friday',
            'saturday',
            'sunday',
        ];

        // Get all the language lines of the current locale.
        $all = static::getTranslator()->getCatalogue()->all();
        $terms = array_intersect_key($all['messages'], array_flip((array) $keys));

        // Split terms with a | sign.
        foreach ($terms as $i => $term) {
            if (strpos($term, '|') === false) {
                continue;
            }

            // Split term options.
            $options = explode('|', $term);

            // Remove :count and {count} placeholders.
            $options = array_map(function ($option) {
                $option = trim(str_replace(':count', '', $option));
                $option = preg_replace('/({\d+(,(\d+|Inf))?}|\[\d+(,(\d+|Inf))?\])/', '', $option);

                return $option;
            }, $options);

            $terms[$i] = $options;
        }

        // Replace the localized words with English words.
        $translated = $time;
        foreach ($terms as $english => $localized) {
            $translated = str_ireplace($localized, $english, $translated);
        }

        return $translated;
    }
public static function translateTimeString($time, $from = null, $to = null, $mode = -1)
    {
        // Don't run translations for english.
        if (static::getLocale() == 'en') {
            return $time;
        }

        // All the language file items we can translate.
        $keys = [
            'january',
            'february',
            'march',
            'april',
            'may',
            'june',
            'july',
            'august',
            'september',
            'october',
            'november',
            'december',
            'monday',
            'tuesday',
            'wednesday',
            'thursday',
            'friday',
            'saturday',
            'sunday',
        ];

        // Get all the language lines of the current locale.
        $all = static::getTranslator()->getCatalogue()->all();
        $terms = array_intersect_key($all['messages'], array_flip((array) $keys));

        // Split terms with a | sign.
        foreach ($terms as $i => $term) {
            if (strpos($term, '|') === false) {
                continue;
            }

            // Split term options.
            $options = explode('|', $term);

            // Remove :count and {count} placeholders.
            $options = array_map(function ($option) {
                $option = trim(str_replace(':count', '', $option));
                $option = preg_replace('/({\d+(,(\d+|Inf))?}|\[\d+(,(\d+|Inf))?\])/', '', $option);

                return $option;
            }, $options);

            $terms[$i] = $options;
        }

        // Replace the localized words with English words.
        $translated = $time;
        foreach ($terms as $english => $localized) {
            $translated = str_ireplace($localized, $english, $translated);
        }

        return $translated;
    }
public static function translateTimeString ( $ time , $ from = null , $ to = null , $ mode = - 1 ) { // Don't run translations for english. if ( static :: getLocale ( ) == 'en' ) { return $ time ; } // All the language file items we can translate. $ keys = [ 'january' , 'february' , 'march' , 'april' , 'may' , 'june' , 'july' , 'august' , 'september' , 'october' , 'november' , 'december' , 'monday' , 'tuesday' , 'wednesday' , 'thursday' , 'friday' , 'saturday' , 'sunday' , ] ; // Get all the language lines of the current locale. $ all = static :: getTranslator ( ) -> getCatalogue ( ) -> all ( ) ; $ terms = array_intersect_key ( $ all [ 'messages' ] , array_flip ( ( array ) $ keys ) ) ; // Split terms with a | sign. foreach ( $ terms as $ i => $ term ) { if ( strpos ( $ term , '|' ) === false ) { continue ; } // Split term options. $ options = explode ( '|' , $ term ) ; // Remove :count and {count} placeholders. $ options = array_map ( function ( $ option ) { $ option = trim ( str_replace ( ':count' , '' , $ option ) ) ; $ option = preg_replace ( '/({\d+(,(\d+|Inf))?}|\[\d+(,(\d+|Inf))?\])/' , '' , $ option ) ; return $ option ; } , $ options ) ; $ terms [ $ i ] = $ options ; } // Replace the localized words with English words. $ translated = $ time ; foreach ( $ terms as $ english => $ localized ) { $ translated = str_ireplace ( $ localized , $ english , $ translated ) ; } return $ translated ; }
Translate a locale based time string to its english equivalent.

@param  string $time
@return string
Translate a locale based time string to its english equivalent .