protected function ensureBackwardsCompatibility($messages) { if (preg_match('/^\\{"[a-z]{2}":/', $messages)) { return $messages; } else { return '{"' . Lang::locale() . '":' . $messages . '}'; } }
function __($phrase, array $replacePhrase = []) { $thisLang = Lang::locale(); $arrayTranslate = Trans::fillCacheTrans(); if (isset($arrayTranslate[$phrase][$thisLang])) { $phrase = $arrayTranslate[$phrase][$thisLang]; } else { $phrase = Trans::generateTranslation($phrase, $thisLang); } if (count($replacePhrase)) { $phrase = str_replace(array_keys($replacePhrase), array_values($replacePhrase), $phrase); } return $phrase; }
public function index() { $model = $this->settings->model; $this->data['sortby'] = Input::get('sortby'); $this->data['order'] = Input::get('order'); if (property_exists($model, 'translable')) { $model = $model::where('lang', \Lang::locale()); } if ($this->data['sortby'] && $this->data['order']) { $this->data['entries'] = $model::orderBy($this->data['sortby'], $this->data['order'])->paginate($this->settings->rowsPerPage); } else { $this->data['entries'] = $model::paginate($this->settings->rowsPerPage); } if (!empty($this->settings->list_view) && view()->exists($this->settings->list_view)) { return view($this->settings->list_view, $this->data); } else { return view($this->list_view, $this->data); } }
/** * The actual HTML creation of the field. * * @return string */ function make() { // Set options (parameters) foreach (self::$availableOptions as $opt) { if ($this->field->{$opt}) { $this->addData($opt, $this->field->{$opt}); } } $format = $this->field->format; if (!$format) { $format = ""; $format .= $this->field->has_date !== false ? trans('sharp::format.date_inputFormat') : ""; $format .= $this->field->has_time ? (strlen($format) ? " " : "") . trans('sharp::format.time_inputFormat') : ""; $this->addData("format", $format); } $this->addData("lang", \Lang::locale()); // Valuate field (date formatting according to declared format) $fieldValue = null; if ($this->fieldValue) { $d = strtotime($this->fieldValue); if ($d) { $fieldValue = date($format, $d); } } if (!$this->instance && $this->isListItem) { // No instance and part of a list item : this field is meant to be in the template item. // In this case, we don't set the "sharp-date" class which will trigger the JS code for // the date component creation $this->addClass("sharp-date-template"); } else { // Regular case $this->addClass("sharp-date"); } // Auto-populate the real sent field $str = Form::hidden($this->fieldName, $this->fieldValue, ["class" => "sharp-date-timestamp", "autocomplete" => "off"]); // And populate with formatted date the visible input field $str .= Form::text("__date__" . $this->fieldName, $fieldValue, $this->attributes); return $str; }
/** * Used with AJAX in the list view (datatables) to show extra information about that row that didn't fit in the table. * It defaults to showing all connected translations and their CRUD buttons. * * It's enabled by: * - setting the $crud['details_row'] variable to true; * - adding the details route for the entity; ex: Route::get('page/{id}/details', 'PageCrudController@showDetailsRow'); */ public function showDetailsRow($id) { // get the info for that entry $model = $this->crud['model']; $this->data['entry'] = $model::find($id); $this->data['entry']->addFakes($this->getFakeColumnsAsArray()); $this->data['original_entry'] = $this->data['entry']; $this->data['crud'] = $this->crud; if (property_exists($model, 'translatable')) { $this->data['translations'] = $this->data['entry']->translations(); // create a list of languages the item is not translated in $this->data['languages'] = \Dick\TranslationManager\Models\Language::all(); $this->data['languages_already_translated_in'] = $this->data['entry']->translationLanguages(); $this->data['languages_to_translate_in'] = $this->data['languages']->diff($this->data['languages_already_translated_in']); $this->data['languages_to_translate_in'] = $this->data['languages_to_translate_in']->reject(function ($item) { return $item->abbr == \Lang::locale(); }); } // load the view from /resources/views/vendor/dick/crud/ if it exists, otherwise load the one in the package return $this->firstViewThatExists('vendor.dick.crud.details_row', 'crud::details_row', $this->data); }
<?php $lang = Lang::locale(); $url = explode('/', Request::url()); $url = implode('/', array_slice($url, 4)); ?> <!doctype html> <html> <head> <base href="{{ url('/') }}"> <meta charset="utf-8"> <meta name="description" content=""> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>@yield('title') | Landoretti</title> <link rel="icon" href="img/favicon.ico"> <link rel="stylesheet" href="/css/normalize.css"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"> <link rel="stylesheet" href="/css/style.css"> </head> <body> <header> <img src="/img/Logo.gif" alt="Landoretti logo" class="logo"> @include('layout.adminbar') @include('layout.navbar') </header> <main> @yield('content') </main> <footer> @include('layout.footer') </footer>
private function lang($text, $params = [], $options = null) { switch ($options) { case 'lower': return Lang::lower($text, $params); case 'capital': return Lang::capital($text, $params); case 'locale': return Lang::locale($text, $params); } return Lang::lang($text, $params); }
/** * Overwriting the Eloquent save() method, to set a default translation language, if necessary. */ public function save(array $options = []) { if (isset($this->translatable)) { // set a default language (the one the user is currently using) if (!isset($this->translation_lang) || $this->translation_lang == '') { $this->translation_lang = \Lang::locale(); } // TODO: if some untranslatable attributes are empty, but its parent's are filled, copy them } parent::save(); }
/** * Retourne les résultats d'une recherche * * @param string $query : l'expression à rechercher * * @return CrawledContent $resultsContainigQuery */ public static function getSearchResult($query) { $calledClass = get_called_class(); return self::search($query, $values)->select('crawled_contents.id', 'url', 'title', 'content', 'language', 'deleted_at', DB::raw('COUNT(log_outgoing_links.id) AS count'), DB::raw(self::caseWhen(DB::raw('language'), array(Lang::locale() => static::SAME_LANGUAGE), 0) . ' + ' . self::caseWhen(self::substr(DB::raw('language'), 1, 2), array(substr(Lang::locale(), 0, 2) => static::SAME_PRIMARY_LANGUAGE), 0) . ' + COUNT(DISTINCT key_words.id) * ' . static::KEY_WORD_SCORE . ' + ' . self::findAndCount(DB::raw('content'), $query) . ' * ' . static::COMPLETE_QUERY_SCORE . ' + ' . self::findAndCount(DB::raw('content'), $values) . ' * ' . static::ONE_WORD_SCORE . ' AS score '))->leftJoin('log_outgoing_links', 'log_outgoing_links.crawled_content_id', '=', 'crawled_contents.id')->leftJoin('crawled_content_key_word', 'crawled_content_key_word.crawled_content_id', '=', 'crawled_contents.id')->leftJoin('key_words', function ($join) use($calledClass, $values) { $join->on('crawled_content_key_word.key_word_id', '=', 'key_words.id')->on('key_words.word', 'in', DB::raw('(' . implode(', ', array_maps(array('normalize', 'strtolower', array($calledClass, 'quote')), $values)) . ')')); })->groupBy('crawled_contents.id')->orderBy('score', 'desc'); }
public static function smartDate($timestamp) { $timeDiff = time() - $timestamp; // same day if ($timeDiff > -60 * 60 * 24) { // in more than -3h if ($timeDiff < -60 * 60 * 3) { return Lang::locale('in') . ' ' . ceil(-$timeDiff / 3600) . 'h'; } // in more than -1h if ($timeDiff < -60 * 60) { $min = ceil(-$timeDiff % 3600 / 60); if ($min == 0) { $min = ''; } else { if ($min == 60) { $min = ''; $timeDiff -= 60 * 60; } else { $min = str_pad($min, 2, '0', STR_PAD_LEFT); } } return Lang::locale('in') . ' ' . floor(-$timeDiff / 3600) . 'h' . $min; } // in more than -1 min if ($timeDiff < -60) { $min = ceil(-$timeDiff / 60); if ($min == 60) { return Lang::locale('in') . ' 1h'; } return Lang::locale('in') . ' ' . $min . ' min'; } // in more than now if ($timeDiff < 0) { $sec = ceil(-$timeDiff); if ($sec == 60) { return Lang::locale('in') . ' 1 min'; } return Lang::locale('in') . ' ' . $sec . 's'; } // now if ($timeDiff == 0) { return Lang::locale('now'); } // less than 1 min ago if ($timeDiff < 60) { return Lang::locale('ago', [$timeDiff . 's']); } // less than 1h ago if ($timeDiff < 60 * 60) { $min = floor($timeDiff / 60); if ($min == 0) { $min = ''; } return Lang::locale('ago', [$min . ' min']); } // less than 3h ago if ($timeDiff < 60 * 60 * 3) { $min = floor($timeDiff % 3600 / 60); if ($min == 0) { $min = ''; } else { if ($min == 60) { $min = ''; $timeDiff += 60 * 60; } else { $min = ' ' . str_pad($min, 2, '0', STR_PAD_LEFT); } } return Lang::locale('ago', [floor($timeDiff / 3600) . 'h' . $min]); } // less than 1 day ago if ($timeDiff < 60 * 60 * 24) { return Lang::locale('ago', [floor($timeDiff / 3600) . 'h']); } } // same month if (date('Y-m') == date('Y-m', $timestamp)) { return utf8_encode(strftime('%d %b', $timestamp)) . self::getTime($timestamp); } // same year if (date('Y') == date('Y', $timestamp)) { return utf8_encode(strftime('%d %b', $timestamp)); } return utf8_encode(strftime('%d %b %Y', $timestamp)); }