How to make switching language button

wiyono posted 3 years ago

Hallo, i'm using blade template, all file content is in view and i need 2 language on my project, how the easiest way to make the button switcher language? can someone help me?

Thank you

usm4n replied 3 years ago

this may not be the complete solution but you can do something like this:

class HomeController extends BaseController {

	public function postChangeLanguage() 
		$rules = [
		'language' => 'in:en,fr' //list of supported languages of your application.
		$language = Input::get('lang'); //lang is name of form select field.
		$validator = Validator::make(compact($language),$rules);
		{/**/ }

and you can create a form like this:

{{ Form::open(['action' => '[email protected]']) }}
{{ Form::close()}}

and in your App before filter

   $language = Session::get('language','en'); //en will be the default language.
martinhearn replied 3 years ago

This is only set for the current request - you will need to save the setting in a session and assign every page load (for example in global.php)

usm4n replied 3 years ago

I was just editing my reply @martinhearn :)

wiyono replied 3 years ago

Hallo @usm4n, thank you, i will try it...
Hallo @martinhearn, i muss put button select language, thank you

martinhearn replied 3 years ago

:) @usm4n

although perhaps better to retrieve the default language from the config rather than hardcode:

$language = Session::get('language',Config::get('app.locale'));
usm4n replied 3 years ago

@martinhearn yes sure, you are right :)

bishalpaudel replied 3 years ago

Thanks man, its working perfect.

steve111MV replied 1 year ago

it's not clear

ied3vil replied 1 year ago

I know it's late but have you tried ?

Sign in to participate in this thread!

We'd like to thank these amazing companies for supporting us