Twill 2.12.4 localization problem with siteground
Hi,
For one of my clients, I developed a CMS with Twill 2.8.12. Now, they are asking me to enable multilingual functionalities. Perfect.
Locally, everything seems to work fine.
However, on the server on SiteGround, whenever I view a language, it always goes to a 404 error.
$locales = LaravelLocalization::getSupportedLocales();
$prefix = (count($locales) > 1) ? LaravelLocalization::setLocale() : '';
// cache.headers
$locale_middleware = ['localeViewPath', 'cache.headers'];
$middleware = (count($locales) > 1) ? ['localize', 'localeSessionRedirect', 'localizationRedirect', 'localeViewPath', 'cache.headers'] : $locale_middleware;
Route::group([
'prefix' => $prefix,
'middleware' => $middleware,
], function () {
// HOME
Route::get('/', [PageController::class, 'home'])->name('home');
});
I copied the database from the production server, and I can't understand why it works locally but not in production.
Twill.php
'available_user_locales' => [
'en',
'fr',
// 'it',
// 'ru',
],
laravellocalization.php
'supportedLocales' => [
'en' => ['name' => 'English', 'script' => 'Latn', 'native' => 'English', 'regional' => 'en_GB'],
'fr' => ['name' => 'French', 'script' => 'Latn', 'native' => 'français', 'regional' => 'fr_FR'],
]
translatable.php
<?php
return [
'locales' => [
'en',
'fr',
// 'it',
// 'ru',
],
'locale_separator' => '-',
'locale' => null,
'use_fallback' => false,
'use_property_fallback' => true,
'fallback_locale' => 'en',
'translation_suffix' => 'Translation',
'locale_key' => 'locale',
'to_array_always_loads_translations' => true,
];
3 Replies
Have you made sure to clear the caches on the production site?
php artisan config:cache && php artisan route:cache && php artisan cache:clear
yes, i'm doiing deploy with deployer.
I also add
task('deploy:kormiartisan', function () {
info('Artisan => cd {{release_path}} && {{bin/php}} artisan config:cache && {{bin/php}} artisan route:cache && {{bin/php}} artisan cache:clear');
run('cd {{release_path}} && {{bin/php}} artisan config:cache && {{bin/php}} artisan route:cache && {{bin/php}} artisan cache:clear');
});
to force it... But nothing change
@Tom M
im tring to debug...
when i add a second supporteLocales in laravellocalization.php it seems don't enter in routes/web.php (i put some die('o') inside the code).
Whene only I use a suppertedLocales (en) die appears
how is it possible? Only in production machine? In my local machine everything is fine!
This is my .htaccess, But i don't think it's the problem
SetEnv PHPRC ./current/php.ini
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine on RewriteBase / RewriteCond %{HTTPS} off [OR] RewriteCond %{HTTP_HOST} !^www. [NC] RewriteCond %{HTTP_HOST} ^(?:www.)?(.+)$ [NC] RewriteCond %{REQUEST_URI} !^/[0-9]+..+.cpaneldcv$ RewriteCond %{REQUESTURI} !^/.well-known/acme-challenge/[0-9a-zA-Z-]+$ RewriteCond %{REQUEST_URI} !^/.well-known/pki-validation/[A-F0-9]{32}.txt(?:\ Comodo\ DCV)?$ RewriteRule ^ https://www.%1%{REQUEST_URI} [L,NE,R=301] Handle Authorization Header RewriteCond %{HTTP:Authorization} . RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] ###### NON TOCCARE SE SI VUOLE CHE TUTTO FUNZIONI IN PROD / STAGING RewriteCond %{HTTP_HOST} ^www.mysite.com [NC] RewriteCond %{REQUEST_URI} !current/public RewriteRule (.) /current/public/$1 [L] RewriteCond %{HTTP_HOST} ^www.mysite.local [NC] RewriteCond %{REQUEST_URI} !/public RewriteRule ^(.)$ public/$1 [L] ###### NON TOCCARE SE SI VUOLE CHE TUTTO FUNZIONI IN PROD / STAGING Send Requests To Front Controller... RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [L] If i do THis $prefix = 'en'; $middleware = ['localize', 'localeSessionRedirect', 'localizationRedirect', 'localeViewPath', 'cache.headers']; instead of $locales = LaravelLocalization::getSupportedLocales(); $prefix = (count($locales) > 1) ? LaravelLocalization::setLocale() : ''; // cache.headers $locale_middleware = ['localeViewPath', 'cache.headers']; $middleware = (count($locales) > 1) ? ['localize', 'localeSessionRedirect', 'localizationRedirect', 'localeViewPath', 'cache.headers'] : $locale_middleware; In first case dump return "en" correctly and all works fine. In the second case dump doesn't appear and 404 appears Locally first and second case works, but I have the same configuration of server, same packages in vendors (composer), same db. @ifox do you have a solution, please? If i do this $prefix=LaravelLocalization::setLocale('en'); instead of $prefix='en'; 404 appears. it's like LaravelLocalization makes an error... but in logs files i don't find anything
RewriteEngine on RewriteBase / RewriteCond %{HTTPS} off [OR] RewriteCond %{HTTP_HOST} !^www. [NC] RewriteCond %{HTTP_HOST} ^(?:www.)?(.+)$ [NC] RewriteCond %{REQUEST_URI} !^/[0-9]+..+.cpaneldcv$ RewriteCond %{REQUESTURI} !^/.well-known/acme-challenge/[0-9a-zA-Z-]+$ RewriteCond %{REQUEST_URI} !^/.well-known/pki-validation/[A-F0-9]{32}.txt(?:\ Comodo\ DCV)?$ RewriteRule ^ https://www.%1%{REQUEST_URI} [L,NE,R=301] Handle Authorization Header RewriteCond %{HTTP:Authorization} . RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] ###### NON TOCCARE SE SI VUOLE CHE TUTTO FUNZIONI IN PROD / STAGING RewriteCond %{HTTP_HOST} ^www.mysite.com [NC] RewriteCond %{REQUEST_URI} !current/public RewriteRule (.) /current/public/$1 [L] RewriteCond %{HTTP_HOST} ^www.mysite.local [NC] RewriteCond %{REQUEST_URI} !/public RewriteRule ^(.)$ public/$1 [L] ###### NON TOCCARE SE SI VUOLE CHE TUTTO FUNZIONI IN PROD / STAGING Send Requests To Front Controller... RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [L] If i do THis $prefix = 'en'; $middleware = ['localize', 'localeSessionRedirect', 'localizationRedirect', 'localeViewPath', 'cache.headers']; instead of $locales = LaravelLocalization::getSupportedLocales(); $prefix = (count($locales) > 1) ? LaravelLocalization::setLocale() : ''; // cache.headers $locale_middleware = ['localeViewPath', 'cache.headers']; $middleware = (count($locales) > 1) ? ['localize', 'localeSessionRedirect', 'localizationRedirect', 'localeViewPath', 'cache.headers'] : $locale_middleware; In first case dump return "en" correctly and all works fine. In the second case dump doesn't appear and 404 appears Locally first and second case works, but I have the same configuration of server, same packages in vendors (composer), same db. @ifox do you have a solution, please? If i do this $prefix=LaravelLocalization::setLocale('en'); instead of $prefix='en'; 404 appears. it's like LaravelLocalization makes an error... but in logs files i don't find anything
I'm afraid that's not really a Twill issue, but more an issue with the laravel localization package