PHPackages                             krisanalfa/bono-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. krisanalfa/bono-lang

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

krisanalfa/bono-lang
====================

Bono Localization Package

0.1.1(11y ago)0341MITPHP

Since Jun 4Pushed 11y agoCompare

[ Source](https://github.com/krisanalfa/bono-lang)[ Packagist](https://packagist.org/packages/krisanalfa/bono-lang)[ RSS](/packages/krisanalfa-bono-lang/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependenciesVersions (5)Used By (0)

Bono Localization Package
=========================

[](#bono-localization-package)

Want some translation in your Bono-Based Application? Use this component. Code like a boss.

Installation
============

[](#installation)

Add this package to `composer.json` require file:

```
"require": {
    "krisanalfa/bono-lang": "dev-master",
},

```

Activate Localization Package
=============================

[](#activate-localization-package)

Put the Provider to your `bono.providers` configuration:

```
'bono.providers' => array(
    '\\Bono\\Lang\\Provider\\LangProvider',
),

```

Configuration
=============

[](#configuration)

Basic configuration is:

```
'bono.providers' => array(
    '\\Bono\\Lang\\Provider\\LangProvider' => array(
        'driver' => '\\Bono\\Lang\\Driver\\FileDriver',
        'lang'   => 'en',
        'debug'  => true
    ),
),

```

- `driver` is a class that responsible to get all list of registered Language and get words for each language available in list
- `lang` is active language you want to use to translate, you can use a `closure` to set the default language, see example below
- `debug` when you set this config to `false`, and you get nothing from translation, the result is empty string, but if it sets to `true`, you get some debug keyword

Using closure to determine which language is set to be default one

```
array(
    'driver' => '\\Bono\\Lang\\Driver\\FileDriver',
    'lang' => function() {
        return $_SESSION['user']['config']['lang'];
    },
    'debug' => true
),

```

Basic FileDriver Dictionary Knowledge
=====================================

[](#basic-filedriver-dictionary-knowledge)

You can change the location of your dictionary, by add `lang.path` in configuration files:

```
'bono.providers' => array(
    '\\Bono\\Lang\\Provider\\LangProvider' => array(
        'driver'    => '\\Bono\\Lang\\Driver\\FileDriver',
        'lang'      => 'en',
        'debug'     => true,
        'lang.path' => 'lang'
    ),
),

```

So in your **root project**, you should create a `lang` folder , and put your dictionary inside that folder.

```
{{ ROOT }}
├── composer.json
└── lang
    ├── en
    │   └── list.php
    │   └── anotherList.php
    └── id
        └── list.php
        └── extraList.php

```

When you want Spanish language exists in your repository, make an `es` folder in `lang` folder. The structure of your dictionary should be like this:

```
{{ ROOT }}
├── composer.json
└── lang
    ├── en
    │   └── list.php
    │   └── anotherList.php
    ├── id
    │   └── list.php
    │   └── extraList.php
    └── es
        └── list.php
        └── spanishList.php

```

```
return array(
    'full_name'  => 'Full Name',
    'birth_date' => 'Birth Date',
    'message'    => 'Hello',
    'flash'      => array(
        'fail'    => 'Sorry, app is currently fucked up', // nested content
        'success' => 'Hurray, that is that I am talking about', // yet another nested content
    ),
);

```

\#Example dictionary Let's say this is our dictionary

```
return array(
    'full_name'  => 'Full Name',
    'birth_date' => 'Birth Date',
    'message'    => 'Hello',
    'flash'      => array(
        'fail'    => 'Sorry, app is currently fucked up', // nested content
        'success' => 'Hurray, that is that I am talking about', // yet another nested content
    ),
);

```

\#Usage (Based on example dictionary)

You can access translation from application container context, such as:

```
$app        = \Bono\App::getInstance();
$translator = $app->translator;
$word       = $translator->translate('message');
echo $word; // output => 'Hello'

```

---

Or via alias function:

```
$word = t('message'); // 't' is an alias for 'translate' method in $translator
echo $word; // output => 'Hello'

```

---

You can append some parameter to your language. But, first, you have to confirm that your line, accept the parameter by change it to

```
// List of English dictionary
array(
    // ... snip
    'message' => 'Hello, :name',
    // ... snip
);

```

So you can append parameter to your dictionary by:

```
$app        = \Bono\App::getInstance();
$translator = $app->translator;
$word       = $translator->translate('message', array('name' => 'Alfa'));
echo $word; // output => 'Hello, Alfa'

```

---

The third argument in `translate` method is option to give translator a default translation if there's no translation in dictionary:

```
$app        = \Bono\App::getInstance();
$translator = $app->translator;
$word       = $translator->translate('n00p', array(), 'Default one');
echo $word; // output => 'Default one.'

```

---

When you want to access your nested dictionary:

```
$app        = \Bono\App::getInstance();
$translator = $app->translator;
$flash      = $translator->translate('flash.fail');
echo $flash; // output => 'Sorry, app is currently fucked up'

```

---

This package also support for choice if there's multiple message in a key, something like this:

```
// List of English dictionary
array(
    // ... snip
    'options' => 'Sagara|Xinix|Solusitama',
    // ... snip
);

```

If you want to take `Sagara` in `options` key, you can access them by:

```
$app        = \Bono\App::getInstance();
$translator = $app->translator;
$word       = $translator->choice('options', 1);
echo $word; // output => 'Sagara'

```

---

You can also put any placeholder in `choice`, something like this:

```
// List of English dictionary
array(
    // ... snip
    'options' => 'Sagara|Xinix :string|Solusitama',
    // ... snip
);

```

```
$app        = \Bono\App::getInstance();
$translator = $app->translator;
$word       = $translator->choice('options', 2, array('string' => 'Technology'));
echo $word; // output => 'Xinix Technology'

```

---

The `count` variable is automatically appended in `choice` method:

```
// List of English dictionary
array(
    // ... snip
    'options' => 'Sagara|Xinix :string|Solusitama :count',
    // ... snip
);

```

```
$app        = \Bono\App::getInstance();
$translator = $app->translator;
$word       = $translator->choice('options', 3);
echo $word; // output => 'Solusitama 3'

```

Some other method you can access
================================

[](#some-other-method-you-can-access)

```
$app        = \Bono\App::getInstance();
$translator = $app->translator;

// Get current active driver
$translator->getDriver();

// Get current active language
$translator->getLanguage();

// Set Spanish to our current active language
$translator->setLanguage('es');

// Determine if we have Spanish language in our repository
$translator->hasLanguage('es');

```

LICENSE
=======

[](#license)

```
MIT LICENSE

Copyright (c) 2014 Krisan Alfa Timur (PT. Sagara Xinix Solusitama)

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 77.8% 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.

###  Release Activity

Cadence

Every ~50 days

Total

4

Last Release

4207d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5585ab7e83e92b16ebfde64d7d90ff330721bcb1fbfa193fb0ffe149a4b3a7d1?d=identicon)[krisanalfa](/maintainers/krisanalfa)

---

Top Contributors

[![krisanalfa](https://avatars.githubusercontent.com/u/3734729?v=4)](https://github.com/krisanalfa "krisanalfa (7 commits)")[![reekoheek](https://avatars.githubusercontent.com/u/299394?v=4)](https://github.com/reekoheek "reekoheek (2 commits)")

### Embed Badge

![Health badge](/badges/krisanalfa-bono-lang/health.svg)

```
[![Health](https://phpackages.com/badges/krisanalfa-bono-lang/health.svg)](https://phpackages.com/packages/krisanalfa-bono-lang)
```

###  Alternatives

[symfony/translation

Provides tools to internationalize your application

6.6k836.5M2.1k](/packages/symfony-translation)[nesbot/carbon

An API extension for DateTime that supports 281 different languages.

169661.4M4.8k](/packages/nesbot-carbon)[joedixon/laravel-translation

A tool for managing all of your Laravel translations

717911.4k11](/packages/joedixon-laravel-translation)[illuminate/translation

The Illuminate Translation package.

6936.4M495](/packages/illuminate-translation)[lajax/yii2-translate-manager

Translation management extension for Yii 2

227578.8k13](/packages/lajax-yii2-translate-manager)[larswiegers/laravel-translations-checker

Make sure your laravel translations are checked and are included in all languages.

256423.2k2](/packages/larswiegers-laravel-translations-checker)

PHPackages © 2026

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