PHPackages                             ryanj93/php-locale-kit - 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. [Database &amp; ORM](/categories/database)
4. /
5. ryanj93/php-locale-kit

ActiveLibrary[Database &amp; ORM](/categories/database)

ryanj93/php-locale-kit
======================

A simple library that allows to manage language packages and translate texts with PHP.

1.1.3(8y ago)110GPL-3.0-or-laterPHPPHP &gt;=7.0

Since May 8Pushed 8y ago1 watchersCompare

[ Source](https://github.com/RyanJ93/php-locale-kit)[ Packagist](https://packagist.org/packages/ryanj93/php-locale-kit)[ Docs](https://github.com/RyanJ93/php-locale-kit#readme)[ RSS](/packages/ryanj93-php-locale-kit/feed)WikiDiscussions master Synced 2d ago

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

PHP Locale Kit
==============

[](#php-locale-kit)

PHP Locale Kit is a simple library that allows to manage language packages based on SQLite3 database. It provide also utilities that allow to translate texts as well as detect their language supporting Google and Yandex as service provider. The package is shipped with a CLI utility that allows to create and translate language packages, for more information and documentation check the file called "cli.md".

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

[](#installation)

Before installing the package, make sure that the `sqlite3` extension is installed, usually this extension is shipped with your PHP installation. To install this package through Composer just run this command:

```
composer require ryanj93/php-locale-kit
```

Usage: Package
--------------

[](#usage-package)

The class "Package" allows to fetch the labels from the language package, before using it you need, of course, to set up the path to the package and the locale to use, the locale must be supported by the package, you can set a locale and allows to the library to switch to a fallback locale based on the language of the given locale code, for example, if you set "en-US" as locale but the package doesn't support it, the library will look for any locale matching with "en", unless the strict mode is enable, here you are an example:

```
$package = new Package();
//path, locale, strict mode
//$locale is a string containing the locale code selected, if different by the given code, it means that a fallback locale has been picked.
$locale = $package->setPackage('path/to/the/package.db', 'en-US', false);
```

You can get a list of all the supported locales by using the following method:

```
//Get all locales.
$locales = $package->getSupportedLocales();
//Check for a specific locale support.
//locale, strict mode
$value = $package->isLocaleSupported('en-US', false);
```

Now you are able to get the labels, you can use the following method passing an array containing the labels' IDs, the IDs can be represented as numbers or strings, according with the package, the labels will be returned as associative array having as key the label ID and as value its text, if a label were not found, it will be omitted, here's the example:

```
$labels = $package->getLabels(array(1, 2, 3));
```

Of course you can fetch all the labels from the package using the following method:

```
$labels = $package->getAllLabels();
```

Usage: Translator
-----------------

[](#usage-translator)

The class "Translator" allows to translate and detect the language of texts, as of now, it support only Google and Yandex as service provider, in order to use it, you need to get an API key from the provider that you are going to use, by default, Yandex is used because it offers a free plan that allows to translate up to 10000000 chars per month, you can get a free API key from Yandex [here](https://translate.yandex.com/developers), here you are the setup example:

```
$translator = new Translator();
//token, text format
$translator->setupYandex('YOUR API TOKEN HERE', Translator::HTML);
```

Now you can translate one or more texts using this method:

```
//text, target language, original language
$texts = $translator->translateText(array('Ciao mondo!'), 'en', 'it');
```

Note that you can omit the original language, in this case it will be automatically detected by the provider. The translated texts will be returned as associative array having as key the original text and as value the translated one. In a similar way you can detect the language of one or more texts, here you are an example:

```
//text, target language, original language
$detections = $translator->detectLanguage(array('Ciao mondo!'));
```

It will return an associative array having as key the original text and as value the code of the language detected. If you need to get a list of all the languages supported by the service provider you can use the following method:

```
$languages = $translator->getSupportedLanguages('en');
```

Both the classes support data caching, you can set up cache using these methods:

```
//Setup cached for the package.
$package->setCache(true)->setCacheHandler($cache);
//Setup cached for the translator.
$translator->setCache(true)->setCacheHandler($cache);
```

Data caching is provided by the library "php-tiny-cacher", as you can see in the examples, the variable "$cache" is an instance of the class "PHPTinyCacher" that allows to store data using different options such as Redis, Memcached and file. You can find more information about it on its [repository on GitHub](https://github.com/RyanJ93/php-tiny-cacher).

If you like this project and think that is useful don't be scared and feel free to contribute reporting bugs, issues or suggestions or if you feel generous, you can send a donation [here](https://www.enricosola.com/about#donations).

Are you looking for the Node.js version? Give a look [here](https://github.com/RyanJ93/locale-kit).

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

2927d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/18029b3320ad57be78062e5be0584dd20deb3fe5f6fbdfb2d723fafc5a3b8742?d=identicon)[ryanj93](/maintainers/ryanj93)

---

Tags

localizationphpphp7translationlocalizationtranslationsqlitesqlite3

### Embed Badge

![Health badge](/badges/ryanj93-php-locale-kit/health.svg)

```
[![Health](https://phpackages.com/badges/ryanj93-php-locale-kit/health.svg)](https://phpackages.com/packages/ryanj93-php-locale-kit)
```

###  Alternatives

[ezsql/ezsql

Advance database access library. Make interacting with a database ridiculously easy. An universal interchangeable CRUD system.

86946.7k](/packages/ezsql-ezsql)[jv2222/ezsql

Advance database access library. Make interacting with a database ridiculously easy. An universal interchangeable CRUD system.

87311.3k2](/packages/jv2222-ezsql)[hpolthof/laravel-translations-db

A database translations implementation for Laravel 5.

545.8k](/packages/hpolthof-laravel-translations-db)[richan-fongdasen/laravel-i18n

Simple route and eloquent localization / translation in Laravel

1296.6k](/packages/richan-fongdasen-laravel-i18n)[nevadskiy/laravel-translatable

Add translations to your Eloquent models

2120.4k1](/packages/nevadskiy-laravel-translatable)[moxio/sqlite-extended-api

Exposes SQLite APIs that are otherwise not available in PHP

188.1k](/packages/moxio-sqlite-extended-api)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
