title: How to set specific language for all pages in Codeigniter 4
body: <p>I've translated 2 language in '<strong>app/Language</strong>' folder and set language switcher. Currently translation works fine for base url like <code>example.com/en</code> and <code>example.com/sp</code>.</p>
  
  <p>My problem is when visitor visits other page like <code>/post/cats/123</code> then How I set the language for all view page. What is the standard way for language setting in codeigniter 4. </p>
  
  <p>Language folder -</p>
  
  <p><a href="https://i.stack.imgur.com/AnlkO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AnlkO.png" alt="enter image description here"></a></p>
  
  <p>language switcher code.</p>
  
  <pre><code>&lt;div class="dropdown-menu" aria-labelledby="navbarDropdown"&gt;
      &lt;a class="dropdown-item" href="&lt;?= base_url('en') ?&gt;"&gt;English&lt;/a&gt;
      &lt;a class="dropdown-item" href="&lt;?= base_url('sp') ?&gt;"&gt;Spanish&lt;/a&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Route-</p>
  
  <pre><code>$routes-&gt;get('/{locale}', 'Language::index');
  </code></pre>
  
  <p>Language class - </p>
  
  <pre><code>class Language extends BaseController
  {
  
      public function index()
      {
           $locale = $this-&gt;request-&gt;getLocale();
           $this-&gt;request-&gt;setLocale($locale);
           return redirect()-&gt;back();
      }
  }
  </code></pre>