Multi Language Settings

Let's add the French language.
  • Create a new file fr.json in the fr folder in the assets/lang folder and copy the en.json file code in this file.
  • Now you need to add the language in the assets/js/app.js file. In the function setLanguage, add the "Switch case" condition as below code and make sure to add the french.jpg file in the assets/images/flags folder.
    case "fr":
        document.getElementById("header-lang-img").src = "assets/images/flags/french.svg";
    break; 
  • You can simply use key attributes in the HTML tag to convert the language text. Example: <div data-key="t-title">This is title.</div>
  • Add the below dropdown in the partials/topbar.php file in the language dropdown.

    <!-- item-->
    <a href="javascript:void(0);" class="dropdown-item notify-item language" data-lang="fr" title="French">
        <img src="assets/images/flags/french.jpg" alt="user-image" class="me-2 rounded" height="18">
        <span class="align-middle">French</span>
    </a> 

Multi-Language Settings - Codeigniter

For official documentation of Codeigniter you can follow https://codeigniter4.github.io/userguide/outgoing/localization.html.
Please follow the below steps to add a new language.

  1. Set default language from the app/Config/App.php.
    $defaultLocale= 'en'; and in supported language $supportedLocales = ['en', 'es', 'de', 'it', 'ru'];
    and set public $baseURL = 'https://yourdomain.com/';
  2. All the files of each language are located in app/Language. You can create a new language folder by referring to the English language.
  3. You need to add a new language in the topbar dropdown in the file app/Views/partials/topbar.php and app/Views/partials/horizontal.php file.
  4. It is managed by the backend in the file app/Controllers/Language.php.
    You can use <?= lang('Files.Search') ?> to translate "Search" keyword in supported languages.

Multi-Language Settings - PHP
  1. Let's add a new language Italy.
    Create an it.php file in the assets/lang-php folder. And refer to the other languages to add or update the keys and values for translation.
  2. You need to add a new language in the topbar dropdown in the file partials/topbar.php file and fin the class "language-switch". You can add a new language flag so it will be able to render in the topbar.
  3. You can use <?php echo $lang["Forms"]; ?> in the view.

Multi-Language Settings - Ajax
  1. Let's add a new language Italy.
    Create an it.json file in the assets/lang folder. And refer to the other languages to add or update the keys and values for translation.
  2. You need to add a new language in the topbar dropdown in the file index.html file and fin the class "language-switch". You can add a new language flag so it will be able to render in the topbar.
  3. You can use <a href="forms.html" key="t-crypto">Forms in the view.

© Skote.