'name' => 'status',
'type' => 'SelectFromArray',
'default' => '0',
- 'label' => __('Status'),
- 'options' => ['0' => __('Offline'), '1' => __('Published')],
+ 'label' => 'Status',
+ 'options' => ['0' => 'Hors ligne', '1' => 'Publié'],
'translatable' => true,
'column' => true,
'tab' => 'Informations principales',
use Cubist\Backpack\app\Magic\Requests\CubistMagicUpdateRequest;
use Cubist\Backpack\app\Magic\Util;
use Cubist\Util\Json;
-use Cviebrock\EloquentSluggable\Sluggable;
-use Cviebrock\EloquentSluggable\SluggableScopeHelpers;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Schema\Table;
use Illuminate\Database\Eloquent\Model;
*
* @return array
*/
- public function sluggable()
+ public function sluggable():array
{
return [
'slug' => [
'name' => 'meta_title',
'label' => trans('backpack::pagemanager.meta_title'),
'type' => 'Text',
- 'hint' => trans('If empty, page title is used.') . ' ' . __('Recommended length: 60 chars'),
+ 'hint' => 'Si vide, le titre court est utilisé' . ' ' . 'Longueur recommandée : 60 caractères',
'tab' => $tab,
'fake' => true,
'store_in' => 'seo',
'name' => 'meta_description',
'label' => trans('backpack::pagemanager.meta_description'),
'type' => 'Textarea',
- 'hint' => __('Recommended length: 160 chars'),
+ 'hint' => 'Longueur recommandée : 160 caractères',
'tab' => $tab,
'fake' => true,
'store_in' => 'seo',
$this->addFieldAtEnd([
'name' => 'robots',
- 'label' => __('Allow page index by search engines'),
+ 'label' => 'Permettre l\'indexation par les moteurs de recherche',
'type' => 'Checkbox',
'default' => true,
'tab' => $tab,
class CubistMagicTranslatableModel extends CubistMagicAbstractModel
{
+ use Sluggable;
+ use SluggableScopeHelpers;
+
use HasTranslations {
update as protected updateTranslations;
create as protected createTranslations;
$this->addField(['name' => 'meta_title',
'label' => 'Titre long par défaut',
'type' => 'Text',
- 'hint' => trans('If empty, page title is used.') . ' ' . __('Recommended length: 60 chars'),
+ 'hint' => 'Taille recommandée : 60 caractères',
'tab' => 'SEO // Meta',
]);
'name' => 'meta_description',
'label' => 'Meta description par défaut',
'type' => 'Textarea',
- 'hint' => __('Recommended length: 160 chars'),
+ 'hint' => 'Taille recomandée : 160 caractères',
'tab' => 'SEO // Meta',
]);
namespace Cubist\Backpack\app\Middleware;
+use Closure;
use Cubist\Backpack\app\Magic\Models\Locale;
use Illuminate\Http\Request;
+use Illuminate\Support\Facades\App;
class LocaleSelector
{
public function handle(Request $request, Closure $next)
{
- $response = $next($request);
- // No need to change locale depending on the domaine on admin
- if (strpos($request->getPathInfo(), '/admin/') === 0) {
- return $response;
- }
-
- $domain = $request->getHttpHost();
$class = Locale::getLocaleClass();
- $locales = $class::where('active', 1)->get(0);
+ $locales = $class::where(['enabled' => 1])->orderBy('default', 'DESC')->get();
foreach ($locales as $locale) {
- dd($locale);
+ if ($locale->default) {
+ $defaultLocale = $locale->locale;
+ break;
+ }
+ }
+
+
+ $selectedLocale = $this->_getLocaleByDomain($request, $locales);
+ if (null === $selectedLocale) {
+ $selectedLocale = $defaultLocale;
}
- return $response;
+ $this->setLocale($selectedLocale, $defaultLocale);
+
+ return $next($request);
+ }
+
+ public function setLocale($locale, $default)
+ {
+
+ App::setLocale($locale);
+ app('translator')->setLocale($locale);
+ app('translator')->setFallback($default);
+ }
+
+ /**
+ * @param Request $request
+ * @param Locale[] $locales
+ * @return mixed|null
+ */
+ protected function _getLocaleByDomain(Request $request, $locales)
+ {
+ $httpdomain = $request->getHttpHost();
+ $default = null;
+ $map = [];
+ foreach ($locales as $locale) {
+ if (null === $default && $locale->default) {
+ $default = $locale->locale;
+ }
+ $domains = $locale->domains;
+ if (is_string($locale->domains)) {
+ $domains = json_decode($locale->domains, true);
+ }
+ foreach ($domains as $domain) {
+ $map[trim($domain['domain'])] = $locale->locale;
+ }
+ }
+ return $map[$httpdomain] ?? null;
}
}