Introducing ReUI:Open-source UI components and apps built with React, Next.js and Tailwind CSS
Browse ReUI

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
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • 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
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(