PHPackages                             mirac/multilanguage - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Localization &amp; i18n](/categories/localization)
4. /
5. mirac/multilanguage

ActiveLibrary[Localization &amp; i18n](/categories/localization)

mirac/multilanguage
===================

PHP Multi Language Library

7311PHP

Since Nov 12Pushed 2y ago1 watchersCompare

[ Source](https://github.com/miracsengonul/multi_language)[ Packagist](https://packagist.org/packages/mirac/multilanguage)[ RSS](/packages/mirac-multilanguage/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependenciesVersions (1)Used By (0)

\#PHP Multi Language Library
============================

[](#php-multi-language-library)

This class is a PHP library that allows you to add multi-language support to your project.

- [Installation](#installation)
- [Simple Usage](#usage)
- [Example](#example)

[](#installation)

Installation
------------

[](#installation)

Run the following code in the directory of your project.

> composer require mirac/multilanguage dev-master

If there is no Composer autoload command on your page, add the following command at the beginning of your page.

```
require_once __DIR__ . '/vendor/autoload.php';
```

Let's continue below this line. Since we will create a 'lang' folder in the project directory, add the following commands.

```
use Mirac\MultiLanguage\Create;
Create::folder();
```

After adding these lines to your page, access it through your browser. You will see a folder named 'lang' created in your directory.

> We will add all language files to this folder later.

After seeing that the folder has been created, let's delete the two lines we added earlier because our job is done.

```
/*
use Mirac\MultiLanguage\Create;
Create::folder();
*/
```

Instead, let's add the following lines.

```
use Mirac\MultiLanguage\Language;
use Mirac\MultiLanguage\Select;

$lang = new Language();
$select  = new Select();
```

That's all for configuration. Now we can add languages.

[](#usage)

Usage
-----

[](#usage)

- [Adding Language Files](#lang-klas%C3%B6r%C3%BC-%C4%B0%C3%A7ine-dil-dosyas%C4%B1-ekleme)
- [Using on the Page](#sayfada-kullanma)
- [Visitor Language Selection](#ziyaret%C3%A7inin-dil-se%C3%A7mesi)

[](#dosya-ekle)

### Adding Language Files to the 'lang' Folder

[](#adding-language-files-to-the-lang-folder)

To translate files, we need to create folders with country codes inside the created 'lang' folder in our directory.

Example:

For Turkish, we create a folder named 'tr'. Then we add our translation files to it.

You can add a folder and translation file for any language you want.

Let's create a language file named 'homepage' for Turkish. Depending on the size of your site, you can duplicate your files. But don't forget to translate the same files!

Let's create our file containing the translations of our homepage in the 'tr' folder as 'homepage.php'.

> lang/tr/homepage.php

```
