PHPackages                             rayamedia/yima-locali - 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. rayamedia/yima-locali

ActiveYima-core-module[Localization &amp; i18n](/categories/localization)

rayamedia/yima-locali
=====================

Detection of locale through different strategies, include features for multilingual DB`s(translatable fields) plus CLDR data for full system localization of data, and many predefined useful locale helpers.

112PHP

Since Jan 4Pushed 11y ago1 watchersCompare

[ Source](https://github.com/YiMAproject/yimaLocali)[ Packagist](https://packagist.org/packages/rayamedia/yima-locali)[ RSS](/packages/rayamedia-yima-locali/feed)WikiDiscussions master Synced 2w ago

READMEChangelogDependenciesVersions (1)Used By (0)

yimaLocali
==========

[](#yimalocali)

*this module is part of Yima Application Framework*

\[zf2 module\] Detection of locale through different strategies.

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

[](#configuration)

This is most default configuration of module with description of each key as comment.

```
return array (
	'yimaLocali' => array(
        # Locale Detector Strategies, Implemented DetectorInterface
		'detector' => array(
            #  Used By Default AggregateStrategyFactory (yimaLocali.Detector.Strategy)
            'aggregate' => array(
                'strategies' => array(
                    //'Registered\Service\Or\ClassName' => -10,
                    # or
                    /*
                    array(
                        'object'   => new StrategyObject(),
                        'priority' => -10
                    ),
                    */

                    // default ordered strategies
                    'yimaLocali\Detector\UriPathStrategy' => 90,
                    'yimaLocali\Detector\CookieStrategy'  => 80,
                    array(
                        'object'   => new \yimaLocali\Detector\RestrictLocaleStrategy(),
                        'priority' => -1000
                    ),
                ),
            ),
        ),

        # content of this key will pass to LocaleSupport(class) on Bootstrap
        'available_locales' => array(
            'default'    => 'en_US',
            'locales'  => array(
                'en_US',
                'fa_IR',
            ),
            'aliases'    => array(
                'en'    => 'en_US',
                'fa'    => 'fa_IR',
                'farsi' => 'fa',
            ),
        ),

		# if you need detected locale before continue of running application
		'throw_exceptions' => false,
	),
```

How To Get Detected Locale?
---------------------------

[](#how-to-get-detected-locale)

#### From Service Manager

[](#from-service-manager)

```
class LocaleNeededService implement
    ServiceLocatorAwareInterface
{
    public function getLocale()
    {
        // get serviceManager
        $sm = $this->getServiceLocator();

        // we can get current locale from service manager
        return $sm->get('locale.detected');
    }

    // ...
}
```

#### From Locale Intl Extension

[](#from-locale-intl-extension)

if we have Intl extension installed on server after detection of locale from strategies it will set to "Locale" class as defaultLocale

```
Locale::getDefault();
```

#### From View Helper

[](#from-view-helper)

```
echo $this->locale()->getLocale(); // exp. "en_US"

echo $this->locale(); // exp. "en_US"

echo $this->locale()->getLanguage(); // en
echo $this->locale()->getRegion();   // US
```

#### From Controller Plugin

[](#from-controller-plugin)

```
use Zend\Mvc\Controller\AbstractActionController;

class IndexController extends AbstractActionController
{
    public function indexAction()
    {
        echo $this->locale()->getLocale(); // exp. "en_US"

        echo $this->locale(); // exp. "en_US"

        echo $this->locale()->getLanguage(); // en
        echo $this->locale()->getRegion();   // US
    }
}
```

Locale Detected From Aggregate Default Strategy, What About Else ?
------------------------------------------------------------------

[](#locale-detected-from-aggregate-default-strategy-what-about-else-)

If you want using your own complete different strategy for Locale Detection do the same as below.

#### Make your detection strategy class

[](#make-your-detection-strategy-class)

```
use yimaLocali\Detector\DetectorInterface;

class MyLocaleStrategy implements
    DetectorInterface
{
    /**
     * Get locale from configs default setting
     *
     * @return string
     */
    public function getLocale()
	{
	    // get Locale from default locale module config
	    return LocaleSupport::getDefaultLocale();
	}
}
```

#### Make it exclusive default detection service

[](#make-it-exclusive-default-detection-service)

you must register a service with name "yimaLocali.Detector.Strategy" it will replaced with default AggregateDetector

Register The Strategy To Default Aggregate
------------------------------------------

[](#register-the-strategy-to-default-aggregate)

see [configuration](#config) settings

Plugins for locale(Controller/View)Helper
-----------------------------------------

[](#plugins-for-localecontrollerviewhelper)

we can use pluginManager of locale helper and define some plugin or use default plugins.

#### Make new plugin and use it!

[](#make-new-plugin-and-use-it)

you can take benefit of configuration service for plugins and define your plugin with `yima_locali_plugins` merged config key.

```
return array(
'yima_locali_plugins' => array(
        'factories'  => array(
            'test' => function ($sm) {
                return 'This is locale plugin with test name';
            }
        ),
        // 'invokables' => array(),
        // etc..
    ),
);
```

and you can catch this from within View or Controller:

```
$this->locale()->test();
// or
$this->locale()->plugin('test', $parameters);
```

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

[](#installation)

Composer installation:

require `rayamedia/yima-locali` in your `composer.json`

Or clone to modules folder

Enable module in application config

Support
-------

[](#support)

To report bugs or request features, please visit the [Issue Tracker](https://github.com/RayaMedia/yimaLocali/issues).

*Please feel free to contribute with new issues, requests and code fixes or new features.*

###  Health Score

20

—

LowBetter than 12% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/1f784f9dfb58e36b6a876f3057e5664bb904af71d30bb2023583118138dffe9a?d=identicon)[Payam](/maintainers/Payam)

---

Top Contributors

[![E1101](https://avatars.githubusercontent.com/u/427575?v=4)](https://github.com/E1101 "E1101 (36 commits)")

### Embed Badge

![Health badge](/badges/rayamedia-yima-locali/health.svg)

```
[![Health](https://phpackages.com/badges/rayamedia-yima-locali/health.svg)](https://phpackages.com/packages/rayamedia-yima-locali)
```

###  Alternatives

[smarty-gettext/smarty-gettext

Gettext plugin enabling internationalization in Smarty Package files

752.5M8](/packages/smarty-gettext-smarty-gettext)[renatomarinho/laravel-multi-language

Laravel Multi Language

235.1k](/packages/renatomarinho-laravel-multi-language)

PHPackages © 2026

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