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

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

yohns/lang
==========

Simple and easy language class for php to be able to easily create translations for your text.

0.2.0(6mo ago)0151MITPHPPHP ^8.0

Since Oct 28Pushed 6mo ago1 watchersCompare

[ Source](https://github.com/Yohn/Lang)[ Packagist](https://packagist.org/packages/yohns/lang)[ RSS](/packages/yohns-lang/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (2)Versions (5)Used By (1)

Yohns\\Lang\\Text
=================

[](#yohnslangtext)

Simple and easy PHP translation library with auto-generation support, dot notation, and seamless integration with `yohns/config`.

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

[](#installation)

```
composer require yohns/lang
```

Quick Start
-----------

[](#quick-start)

```
use Yohns\Core\Config;
use Yohns\Lang\Text;

// Initialize Config for your application
new Config(__DIR__ . '/lib/Config');

// Initialize Text with language directory
$langDir = __DIR__ . '/lib/Lang';
$text = new Text($langDir, 'en'); // 'en' for English

// Basic usage
echo Text::L('welcome', 'Welcome to our site');
// Output: "Welcome to our site" (or translation if found)

// With placeholders
echo Text::L('hello_user', 'Hello, [name]!', ['[name]' => 'John']);
// Output: "Hello, John!"

// Dot notation for nested translations
echo Text::L('pages.about', 'About Us');
// Output: "About Us" (or translation if found)
```

Features
--------

[](#features)

- **Auto-generation**: Missing translations are automatically added to the default language file
- **Dot notation**: Organize translations hierarchically (e.g., `pages.about`, `messages.success.saved`)
- **Placeholder support**: Replace `[placeholders]` with dynamic values
- **Fallback system**: Falls back to default language, then to provided default text
- **Config integration**: Uses `yohns/config` for file management and configuration
- **Multiple languages**: Easy switching between languages

Overview
--------

[](#overview)

Class `Text`

This class is responsible for handling language translations. It loads language files from a specified directory using the Config class and provides functionality to retrieve phrases in the specified language. It supports dynamic addition of phrases to the default language file if they do not already exist, and supports dot notation for nested keys.

Methods
-------

[](#methods)

NameDescription[L](#textl)Retrieves the translated phrase for the given phrase key.[\_\_construct](#text__construct)Text constructor.[getAll](#textgetall)Retrieves all loaded texts for the current language.[reload](#textreload)Reloads the language files from the language directory.[set](#textset)Sets a new phrase or updates an existing one in the current language.### Text::L

[](#textl)

**Description**

```
public static L (string $key, string $default, array $replacements)
```

Retrieves the translated phrase for the given phrase key.

Supports dot notation for nested keys (e.g., 'pages.about'). If the phrase does not exist in the loaded language text, it adds the default text to the default language file.

**Parameters**

- `(string) $key`: The key of the phrase to retrieve (supports dot notation).
- `(string) $default`: The default text to use and store if the key is not found.
- `(array) $replacements`: Optional replacements for placeholders in the phrase.

**Return Values**

`string`

> The translated phrase with optional replacements.

---

### Text::\_\_construct

[](#text__construct)

**Description**

```
public __construct (string $dir, string $lingo)
```

Text constructor.

**Parameters**

- `(string) $dir`: The directory where translations are located.
- `(string) $lingo`: The language identifier, default is 'en'.

**Return Values**

`void`

**Throws Exceptions**

`\Exception`

> if the specified language directory is not readable or the specified language file does not exist.

---

### Text::getAll

[](#textgetall)

**Description**

```
public static getAll (void)
```

Retrieves all loaded texts for the current language.

**Parameters**

`This function has no parameters.`

**Return Values**

`mixed`

> An array containing all loaded texts or null if not loaded.

---

### Text::reload

[](#textreload)

**Description**

```
public static reload (void)
```

Reloads the language files from the language directory.

**Parameters**

`This function has no parameters.`

**Return Values**

`void`

---

### Text::set

[](#textset)

**Description**

```
public static set (string $key, mixed $value)
```

Sets a new phrase or updates an existing one in the current language.

This is useful for runtime customization of language strings.

**Parameters**

- `(string) $key`: The key of the text to set.
- `(mixed) $value`: The value to associate with the key.

**Return Values**

`void`

---

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance69

Regular maintenance activity

Popularity6

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity37

Early-stage or recently created project

 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 ~127 days

Total

4

Last Release

183d ago

### Community

Maintainers

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

---

Top Contributors

[![Yohn](https://avatars.githubusercontent.com/u/2002591?v=4)](https://github.com/Yohn "Yohn (9 commits)")

### Embed Badge

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

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

###  Alternatives

[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)[inpsyde/multilingual-press

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

2414.0k1](/packages/inpsyde-multilingual-press)[statikbe/laravel-chained-translator

The Laravel Chained Translator can combine several translators that can override each others translations.

36149.4k6](/packages/statikbe-laravel-chained-translator)

PHPackages © 2026

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