PHPackages                             delboy1978uk/bone-i18n - 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. delboy1978uk/bone-i18n

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

delboy1978uk/bone-i18n
======================

I18n package for Bone Framework

v1.4.5(3mo ago)02.3k3MITPHPPHP ^8.2CI passing

Since Feb 26Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/delboy1978uk/bone-i18n)[ Packagist](https://packagist.org/packages/delboy1978uk/bone-i18n)[ RSS](/packages/delboy1978uk-bone-i18n/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (12)Versions (34)Used By (3)

bone-i18n
=========

[](#bone-i18n)

[![Latest Stable Version](https://camo.githubusercontent.com/9eeb61df1478cd51ae7d3f6e2a64b3a9e9c6aad9c1cb1c6ee0e9a8ea2c4abb43/68747470733a2f2f706f7365722e707567782e6f72672f64656c626f7931393738756b2f626f6e652d6931386e2f762f737461626c65)](https://packagist.org/packages/delboy1978uk/bone-i18n) [![Total Downloads](https://camo.githubusercontent.com/27ea7507b6d99dc9c8663394a1729d7cfcf17d9c3deca4b6d3fb9fd04c058493/68747470733a2f2f706f7365722e707567782e6f72672f64656c626f7931393738756b2f626f6e652f646f776e6c6f616473)](https://packagist.org/packages/delboy1978uk/bone) [![Latest Unstable Version](https://camo.githubusercontent.com/8ccaec6ebd6ff40aef01313ac2361de288ab5eeb30a7f46be22be0d0c646cadc/68747470733a2f2f706f7365722e707567782e6f72672f64656c626f7931393738756b2f626f6e652d6931386e2f762f756e737461626c65)](https://packagist.org/packages/delboy1978uk/bone-i18n) [![License](https://camo.githubusercontent.com/631015e46e629df867b75257e5269b2231007f2737ed0a422296efcff2abfb67/68747470733a2f2f706f7365722e707567782e6f72672f64656c626f7931393738756b2f626f6e652d6931386e2f6c6963656e7365)](https://packagist.org/packages/delboy1978uk/bone-i18n)
[![build status](https://github.com/delboy1978uk/bone-i18n/actions/workflows/master.yml/badge.svg)](https://github.com/delboy1978uk/bone-i18n/actions/workflows/master.yml/badge.svg) [![Code Coverage](https://camo.githubusercontent.com/f25435cd669245366c6216c89c97aa2a7ab612b6ceaad67fca35ac6a70a8ac6f/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f64656c626f7931393738756b2f626f6e652d6931386e2f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/delboy1978uk/bone-i18n/?branch=master) [![Scrutinizer Code Quality](https://camo.githubusercontent.com/a99cf6858ec09d639fb9a4a46cf3a8973d32277ee29cbf049b1d9bd0c0911ae2/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f64656c626f7931393738756b2f626f6e652d6931386e2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/delboy1978uk/bone-i18n/?branch=master)

I18n package for Bone Framework

installation
------------

[](#installation)

bone-i18n is a core dependency of `delboy1978uk/bone`, and so it is installed by default.

setup
-----

[](#setup)

The skeleton app has a directory for translations (usually `data/translations` but you can set this to anything), which will contain locale folders such as `en_US` etc.

Drop in your `.mo` and `.po` files. Open `config/bone-i18n.php` and tweak to suit:

```

```

Or more conveniently

```

```

in your view files. A link such as `/user` would then become `/en_US/user`. Bone Framework uses i18n middleware to fetch the locale and it strips the locale from the URL and sets it as a Request Attribute, so you do not need to define routes with a locale parameter.

#### controllers

[](#controllers)

In a controller action if you need the locale you can say:

```
$locale = $request->getAttribute('locale');
```

To get a translator into your controller, make it implement `Bone\I18n\I18nAwareInterface` and use the `Bone\I18n\Traits\HasTranslatorTrait`. If you package's Package class returns the controller without going through the `Bone\Mvc\Controller\Init` class, change it now to this:

```
return  Init::controller(new YourController(), $c);
```

You can now call `$this->getTranslator()` which will return an instance of the translator.

#### translation view helper

[](#translation-view-helper)

To translate text in your view, call the following:

```
