PHPackages                             phederal/leaf-lang - 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. phederal/leaf-lang

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

phederal/leaf-lang
==================

A Leaf module to add multi language capabilities to leaf applications

1.0.1(1y ago)012MITPHP

Since Nov 11Pushed 1y ago1 watchersCompare

[ Source](https://github.com/phederal/leaf-lang)[ Packagist](https://packagist.org/packages/phederal/leaf-lang)[ RSS](/packages/phederal-leaf-lang/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (4)Versions (3)Used By (0)

 [![](https://camo.githubusercontent.com/d98ee5e32c2ff016fdfdac6c42654a908f4cc34b229c7b00caacc5a717455ae8/68747470733a2f2f6c6561667068702e6465762f6c6f676f2d636972636c652e706e67)](https://camo.githubusercontent.com/d98ee5e32c2ff016fdfdac6c42654a908f4cc34b229c7b00caacc5a717455ae8/68747470733a2f2f6c6561667068702e6465762f6c6f676f2d636972636c652e706e67)

Leaf Lang
=========

[](#leaf-lang)

[![Latest Stable Version](https://camo.githubusercontent.com/9f22f869a4e430eaa57c972ad6c2ae165d9b097acbe460ddc262e21406e70104/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f706865646572616c2f6c6561662d6c616e67)](https://packagist.org/packages/phederal/leaf-lang)[![Total Downloads](https://camo.githubusercontent.com/2e8cbf6e5bb7fde4db2305114d207ec317f2691b3a077830d1adf28ddaf13ccd/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f706865646572616c2f6c6561662d6c616e67)](https://packagist.org/packages/phederal/leaf-lang)[![License](https://camo.githubusercontent.com/a24e1a3d31c9e2813f1e35665943534a97c586aff8e4e685b89eae194ded8456/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f706865646572616c2f6c6561662d6c616e67)](https://packagist.org/packages/phederal/leaf-lang)

Leaf Lang is a simple but powerful module that adds multi language capabilities to your leaf applications.

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

[](#installation)

You can easily install Leaf Lang using [Composer](https://getcomposer.org/).

```
composer require phederal/leaf-lang
```

Quick Start Guide
-----------------

[](#quick-start-guide)

### Create translation folder and files

[](#create-translation-folder-and-files)

```
// Create a folder named "locales" in your project root
// (you can also create in another place that makes more sense, just be aware to configure the path accordingly)

// Create the following file inside the "locales" folder
en_US.locale.json

// With the following content
{
    "welcome.title": "Hello World"
}
```

### Initialize Lang

[](#initialize-lang)

In your index.php file (if using MVC: public/index.php). Add these lines:

```
lang()->init(
    [
        'TRANSLATION_FILES_LOCATION' => './locales',
    ]
);
```

### Add Language Switch Route

[](#add-language-switch-route)

In your routes file ("\_app.php" for MVC and "index.php" for base Leaf) add this line:

```
lang()->addLanguageSwitchRoute();
```

### Start Translating

[](#start-translating)

Now in your template file you can add the following:

(this example is using **laravel blade** as template engine but you can adjust according to your template engine)

```

    @foreach(lang()->getAvailableLocales() as $locale)
        getCurrentLocale() === $locale ? 'selected' : '' }}>{{ $locale }}
    @endforeach

{{ tl('welcome.title') }}
```

Or in a simple index.php file

```
