PHPackages                             frmb/language - 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. frmb/language

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

frmb/language
=============

A PHP-class to render a specific language on the website depending on clients browser language for a multi-language website

v1.3(11y ago)019MITPHPPHP &gt;=5.4

Since Mar 8Pushed 11y ago1 watchersCompare

[ Source](https://github.com/frmb14/Language)[ Packagist](https://packagist.org/packages/frmb/language)[ RSS](/packages/frmb-language/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (1)Versions (5)Used By (0)

Language
========

[](#language)

[![Build Status](https://camo.githubusercontent.com/8e601fdbd8d2184f15b30a2df478a1ecb9bf2f934d345fcf1375c2f8d944a5ab/68747470733a2f2f7472617669732d63692e6f72672f66726d6231342f4c616e67756167652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/frmb14/Language)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/96f4cccd5e427714150f1bd24defab3192c15a672f32bf7e4221b9b15aafdf45/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f66726d6231342f4c616e67756167652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/frmb14/Language/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/7977ec7a0ac4962e9bb0be7eba654e9713bad7cc1f067c0396e4e8c1e2074118/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f66726d6231342f4c616e67756167652f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/frmb14/Language/?branch=master)

A PHP-class to render a specific language on the website depending on clients browser language for a multi-language website in Anax-MVC Framework:

How to use
----------

[](#how-to-use)

### Installation

[](#installation)

Install by using composer and enter the following code in your composer.json file:

```
"require": {
	"frmb/language": "dev-master"
},
```

You can also clone this repository and install it manually in your Anax-MVC project.

Once the files have been downloaded create a new folder in your Anax app/content directory called *Language*, this is where the XML files will be placed.

If you want to test the example included, copy the files from *vendor/frmb/language/content/Language* to your Language file created above and copy the **LanguageTest.php** file from the webroot directory to yours and you're ready to go!

### Usage

[](#usage)

To load the Language Module you need to create a new Shared variable using this code in your Front Controller

```
$di->setShared('language', function() use ($di){
    $language = new \Anax\Language\Language();
	$language->setDI($di);
    return $language;
});
```

Then you're ready to begin.

#### Basics

[](#basics)

##### Configuration

[](#configuration)

Open up tile class file **Language.php** inside the installation directory (default *vendor/frmb/language/src/Language/*), inside the \_\_construct function there's block of configuration. There you will set what languages that the site will support, en (English) should always be included as it's default for unsupported languages. Then whatever language you insert is up to you for example: **sv** (Swedish), **dk** (Denmark) and **no** (Norwegian), do remember that if you enter a language in the configuration, you MUST create a file matching the language.

To create new Language files use this template and call it **prefix\_board.xml** where **prefix** is the language, for example **en** or **sv** inside the *content/Language* folder and paste this XML

```

		board
		welcome_message
		Welcome to my module!

		board
		byline
		Powered by frmb/Language

```

Having the Verbose option set to true is highly recommended during the development and testing period as you'll be able to see what files are being loaded and not. Verbose can also be toggled by writing `?verbose` in the browser.

##### General

[](#general)

The default file that's loaded when inside a Front Controller is the **prefix\_board.xml** file where **prefix** is the selected language by the browser and automatically detected by Language (or manually by entering `?l=SHORT_LANGUAGE` in the browser), this is where all global words and sentences should be saved, such as credits, welcome message, footer messages and so on.

The class can accessed inside your Front Controller by typing

```
$app->language->words('welcome_message');
```

This will generate the text from **prefix\_board.xml** which is "Welcome to my module!" or any other language that you have set and translated.

To use the it inside a Controller or a Module class you will simply call the Words function by using $this instead of $app for example:

```
class CommentController
{
	public function viewAction(){
		echo $this->language->words('commentcontroller_hello');
	}
}
```

But if we call the Language class inside a Controller or Module then we're no longer inside the "board", right? We're inside the Controller or Module and therefore we need a new XML document to cover its words! As default you need to create a new file in your Language folder called **prefix\_classname.xml**, in the example above the result would be **en\_commentcontroller.xml**. You can simply paste the xml code that's in the Configuration a little bit up, but if you watch closely there's a xml object called "word\_app" where it says "board", yet again, we're not in the board but in a Controller or a Module now, so change it to our class name, CommentController as in the exampel.

That should cover the most basic usage, more in Advanced usage!

### Advanced Usage

[](#advanced-usage)

Lets continue on handling external Controllers like the example CommentController which I mentionened above. Sometimes you do not call a Controller or Module directly inside the Front Controller but still want to use the words for a Controller like our CommentController to write out a title or a sentence before it's been called.
You can pre-load the controller file by passing the parameter "module" inside the `Words` function:

```
$app->router->add('comment', function() use ($app) {
	$app->theme->setTitle($app->language->words( 'commentcontroller_hello', ['module' => 'CommentController']) );

	$app->views->add('comment/form', [
        'title' => , $app->language->words('commentcontroller_title'),
        'information' => $app->language->words('commentcontroller_information'),
    ]);
});
```

Now the CommentControllers xml file would have been loaded and is available for usage.

This can be useful for other things than only pre-loading controllers, we can for example create a dynamic navbar

```
'home'  => [
    'text'  => $this->di->language->words('navbar_home', ['module' => 'navbar']),
    'url'   => $this->di->get('url')->create(''),
    'title' => 'Home route of current frontcontroller'
],
'comments'  => [
    'text'  => $this->di->language->words('navbar_comments),
    'url'   => $this->di->get('url')->create('comments'),
    'title' => 'Route to our Comment Controllers'
],
```

Using the example above would require a new file called **prefix\_navbar.xml** with the word\_app set to navbar.

Forcing a language to be used is also possible, we can for example always make one set as English by using the parameter *lang*.

```
$app->views->add('me/hem', [
	'content' => $content . $app->language->words('welcome_message') . '' . $app->language->words('welcome_message', ['lang' => 'en']),
	'byline' => $byline . $app->language->words('byline'),
]);
```

Changelog
---------

[](#changelog)

**2015-03-14** 1.2 - Added Travis CI and Scrutinizer. Optimized code and added 4 more test cases for PHPUnit.
**2015-03-14** 1.1 - Many updates
**2015-03-08** 1.0 - Initial release

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity61

Established project with proven stability

 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.

###  Release Activity

Cadence

Every ~2 days

Total

4

Last Release

4082d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5f708765b5eb3d6e13936304519f03c523874282c7f45b9b40e67c42f758424a?d=identicon)[frmb14](/maintainers/frmb14)

---

Top Contributors

[![frmb14](https://avatars.githubusercontent.com/u/11362557?v=4)](https://github.com/frmb14 "frmb14 (17 commits)")

---

Tags

languagetextmultieducationautomatic

### Embed Badge

![Health badge](/badges/frmb-language/health.svg)

```
[![Health](https://phpackages.com/badges/frmb-language/health.svg)](https://phpackages.com/packages/frmb-language)
```

###  Alternatives

[vanderlee/syllable

Text syllable splitting and hyphenation using Frank M. Liang's TeX algorithm.

124432.6k8](/packages/vanderlee-syllable)[codezero/laravel-localized-routes

A convenient way to set up, manage and use localized routes in a Laravel app.

543638.1k4](/packages/codezero-laravel-localized-routes)[gettext/languages

gettext languages with plural rules

7530.3M11](/packages/gettext-languages)[akaunting/laravel-language

Language switcher package for Laravel

223285.2k1](/packages/akaunting-laravel-language)[inpsyde/multilingual-press

Simply THE multisite-based free open source plugin for your multilingual websites.

2414.0k1](/packages/inpsyde-multilingual-press)[josiasmontag/laravel-redis-mock

This Laravel package provides a Redis mock for your tests

471.8M16](/packages/josiasmontag-laravel-redis-mock)

PHPackages © 2026

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