PHPackages                             rebelox/languages - 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. rebelox/languages

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

rebelox/languages
=================

Languages allows you to easily make a multi-language website.

1.0.0(10y ago)116[1 issues](https://github.com/RebeloX/languages/issues)MITPHPPHP &gt;=5.3.0

Since Jun 30Pushed 10y ago1 watchersCompare

[ Source](https://github.com/RebeloX/languages)[ Packagist](https://packagist.org/packages/rebelox/languages)[ Docs](https://github.com/RebeloX/language)[ RSS](/packages/rebelox-languages/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)DependenciesVersions (2)Used By (0)

Languages [![GitHub release](https://camo.githubusercontent.com/108faefdcd71c8c478de462744cc89102b62f45598cc94794868c90c8946c0bf/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f726562656c6f782f6c616e6775616765732e737667)](https://github.com/RebeloX/languages/releases/tag/1.0.0)
==================================================================================================================================================================================================================================================================================================================

[](#languages-)

Languages allows you to easily make a multi-language website.

How is it works
---------------

[](#how-is-it-works)

When a users opens the website, the API will gets the user's country using the `geoip_country_code_by_name` function from the **[GeoIP API](http://dev.maxmind.com/geoip/)**. Then the API searches the configuration files and gets the right language and then by using the user's language the API gets the right message. If the user has a language cookie, the API will ignore the first step and will get the right message using the user's language saved on the cookie.

Installing
----------

[](#installing)

Install using composer

```
{
    "require": {
        "rebelox/languages": "^1.0"
    }
}
```

You can also [visit the releases](https://github.com/RebeloX/languages/releases) and **download** from there.

Configuration
-------------

[](#configuration)

First of all you need to **configurate the api**, the configuration is easy, you just need to **create two files**, one will be the **languages file**, and the other will be the **messages file**.

#### Languages File

[](#languages-file)

The languages file should be like this

```
{
  "default": "default_language",
  "lang1": "countries",
  "lang2": "countries"
}
```

**Where:**

- **default** is the default language you want to your website use by default.
- **lang1 and lang2** are the languages you want to define.
- **countries** is the the list of countries that use that language.

Here's an exemple:

```
{
	"default": "pt",
	"pt" : "BR,PT,AO",
	"en" : "UK,US,AU"
}
```

You may want to check [this list](http://dev.maxmind.com/geoip/legacy/codes/iso3166/) to see all ISO-3166 country codes.

======

#### Messages File

[](#messages-file)

The messages' file structures:

```
{
	"message_name":{
		"lang1":"Message in the lang1",
		"lang2":"Message in the lang2"
	}
}
```

**Where**

- **message\_name** is the name you want to give to your message, it's also known has the identifier.
- **lang1 and lang2** are the languages you defined on the languages file.
- **Message (..) lang1 and lang2** are the messages in the respective languages.

Here's an exemple:

```
{
	"hello":{
		"pt":"Olá mundo",
		"en":"Hello World"
	}
}
```

Basic Usage
-----------

[](#basic-usage)

```
