The New Way to Build! Introducing ReUI — the developer platform for agentic UI with shadcn/ui
Learn More

LARAVEL Add Russian to language switching with flag


Add Russian to language switching
make this language main
need only 2 language RU/EN


Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(

Replies (1)


Hi,

To add Russian (RU) as a language option to language switching in a Laravel application with flags, and set it as the main language alongside English (EN), you can follow these steps:

First, create language files for Russian (ru) and English (en) if they don't already exist in the resources/lang directory. You should have folders like en and ru containing language files such as messages.php. Ensure the language files have the required translations.

Open the config/app.php file and find the locale setting. Set it to 'ru' to make Russian the default language:


"locale" => "ru",


Create routes to handle language switching. You can add these routes to your web.php file:


Route::get("lang/{locale}", "LocalizationController@index");

Create a new controller if you haven't already and add the index method to handle language switching. The controller might look like this:


class LocalizationController extends Controller
{
public function index($locale)
{
if (in_array($locale, ["en", "ru"])) {
App::setLocale($locale);
session()->put("locale", $locale);
}
return redirect()->back();
}
}


In your Blade views, create a language switcher dropdown or buttons. Here's an example using a dropdown:

https://gist.github.com/faizalmy/691f8c96acef86c26f7294e87b99225c

Make sure to adjust the routes (route('localization.index', ['locale' => 'en']) and route('localization.index', ['locale' => 'ru'])) to match your route names.


Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(