PHPackages                             folded/translation - 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. folded/translation

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

folded/translation
==================

Translate terms for your web app.

v0.1.0(5y ago)05MITPHPPHP &gt;=7.4.0

Since Oct 16Pushed 5y ago2 watchersCompare

[ Source](https://github.com/folded-php/translation)[ Packagist](https://packagist.org/packages/folded/translation)[ RSS](/packages/folded-translation/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (6)Versions (2)Used By (0)

folded/history
==============

[](#foldedhistory)

Translate terms for your web app.

[![Packagist License](https://camo.githubusercontent.com/58ea40faea0726daf0170b44f01142b9bf96f7af209b4ecc7129566bb161b44a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f666f6c6465642f7472616e736c6174696f6e)](https://github.com/folded-php/translation/blob/master/LICENSE) [![Packagist PHP Version Support](https://camo.githubusercontent.com/9f3b81b2180327596d6f9990bcae7c83a36bcc3ab67706c7ba8a1eb2ae67c7ac/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f666f6c6465642f7472616e736c6174696f6e)](https://github.com/folded-php/translation/blob/master/composer.json#L14) [![Packagist Version](https://camo.githubusercontent.com/b1aff47b75bb72dbdb103c364b3da48290c82d2761f60f115a3496a6adfd5e35/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f666f6c6465642f7472616e736c6174696f6e)](https://packagist.org/packages/folded/translation) [![Build Status](https://camo.githubusercontent.com/188faecacea2b4342ec62af270220716a0d4335e373febd075e5c84020e8c28e/68747470733a2f2f7472617669732d63692e636f6d2f666f6c6465642d7068702f7472616e736c6174696f6e2e7376673f6272616e63683d6d61696e)](https://travis-ci.com/folded-php/translation) [![Maintainability](https://camo.githubusercontent.com/b699d463e0b104bc3f188fceb3fc8cbe5b6b7bc4fdcc9c1c136ac0c219b71c46/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f33303130633838613761653536643063373136352f6d61696e7461696e6162696c697479)](https://codeclimate.com/github/folded-php/translation/maintainability) [![TODOs](https://camo.githubusercontent.com/48b61b6de83958d7d163bb8ec668ae156d04656522b1991f4a1b5a26d7cb7841/68747470733a2f2f696d672e736869656c64732e696f2f656e64706f696e743f75726c3d68747470733a2f2f6170692e7469636b6769742e636f6d2f62616467653f7265706f3d6769746875622e636f6d2f666f6c6465642d7068702f7472616e736c6174696f6e)](https://www.tickgit.com/browse?repo=github.com/folded-php/translation)

Summary
-------

[](#summary)

- [About](#about)
- [Features](#features)
- [Requirements](#requirements)
- [Installation](#installation)
- [Examples](#examples)
- [Version support](#version-support)

About
-----

[](#about)

I created this package to have a standalone, easy way to use translation in my web app. This library is based on Laravel's translation engine.

Folded is a constellation of packages to help you setting up a web app easily, using ready to plug in packages.

- [folded/action](https://github.com/folded-php/action): A way to organize your controllers for your web app.
- [folded/config](https://github.com/folded-php/config): Configuration utilities for your PHP web app.
- [folded/crypt](https://github.com/folded-php/crypt): Encrypt and decrypt strings for your web app.
- [folded/exception](https://github.com/folded-php/exception): Various kind of exception to throw for your web app.
- [folded/file](https://github.com/folded-php/file): Manipulate files with functions for your web app.
- [folded/history](https://github.com/folded-php/history): Manipulate the browser history for your web app.
- [folded/http](https://github.com/folded-php/http): HTTP utilities for your web app.
- [folded/orm](https://github.com/folded-php/orm): An ORM for you web app.
- [folded/routing](https://github.com/folded-php/routing): Routing functions for your PHP web app.
- [folded/request](https://github.com/folded-php/request): Request utilities, including a request validator, for your PHP web app.
- [folded/session](https://github.com/folded-php/session): Session functions for your web app.
- [folded/view](https://github.com/folded-php/view): View utilities for your PHP web app.

Features
--------

[](#features)

- Can translate terms in the desired language
- Can set a default language to fallback on
- Can use json and key based translations in the same time
- Can use pluralized translations

Requirements
------------

[](#requirements)

- PHP version &gt;= 7.4.0
- Composer installed

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

[](#installation)

- [1. Install the package](#1-install-the-package)
- [2. Prepare the folders](#2-prepare-the-folders)
- [3. Add the bootstrap code](#3-add-the-bootstrap-code)

### 1. Install the package

[](#1-install-the-package)

In your root folder, run this command:

```
composer required folded/translation
```

### 2. Prepare the folders

[](#2-prepare-the-folders)

To work, you need to have a folder that contains your translation. This is the recommended organization:

```
.
└── lang/
    ├── en
    └── fr

```

Inside the lang folders, you can use any organization that fits your needs, from key based translations to json based translation.

When using key based translation, you will likely put any files containing the key and translated terms in their according folder depending the language. Here is an example.

```
.
└── lang/
    ├── en/
    │   └── messages.php
    └── fr/
        └── messages.php

```

For example, the `messages.php` file can contain this for the en folder:

```
return [
  "home" => [
    "title" => "Welcome in the home page",
  ],
];
```

And this for the fr folder:

```
return [
  "home" => [
    "title" => "Bienvenue sur la page d'accueil",
  ],
];
```

Howether, if you want, you can use json based translation. A good use case with JSON based translation files is when you need to use the translated term as the key. JSON based translations files must leave in the immediate folder `lang`, unless the previous key based method. Here is an example:

```
.
└── lang/
    ├── en/
    │   └── messages.php
    ├── fr/
    │   └── messages.php
    ├── en.json
    └── fr.json

```

And here is the content of `en.json` for example:

```
{
  "Contact us for a custom tailored quotation": "Contact us for a custom tailored quotation"
}
```

And here is the content of `fr.json`:

```
{
  "Contact us for a custom tailored quotation": "Contactez nous pour un devis sur-mesure"
}
```

### 3. Add the bootstrap code

[](#3-add-the-bootstrap-code)

As early as possible, configure the library:

```
use function Folded\setDefaultTranslationLang;
use function Folded\setTranslationFolderPath;

setDefaultTranslationLang("en");
setTranslationFolderPath("path/to/folder");
```

Examples
--------

[](#examples)

Keep in mind that, at any moment, you can refer to the [official Laravel translation documentation](https://laravel.com/docs/7.x/localization) if you have some doubt.

- [1. Get a translated term ](#1-get-a-translated-term-by-its-key)
- [2. Use placeholders in translated term](#2-use-placeholders-in-translated-term)
- [3. Get a translated pluralized term](#3-get-a-pluralized-translated-term)
- [4. Change the lang before getting a translated term](#4-change-the-lang-before-getting-a-translated-term)

### 1. Get a translated term by its key

[](#1-get-a-translated-term-by-its-key)

In this example, we will get a translated term from a key based translation.

```
use function Folded\getTranslation;

echo getTranslation("messages.home.title");
```

This implies you have this folder structure:

```
.
└── lang/
    ├── en/
    │   └── messages.php
    └── fr/
        └── messages.php

```

You can also get a translated term from the original term text itself. For this, we recommend using JSON based translation.

```
use function Folded\getTranslation;

echo getTranslation("Contact us for a custom tailored quotation");
```

This implies you have this folder structure:

```
.
└── lang/
    ├── en.json
    └── fr.json

```

### 2. Use placeholders in translated term

[](#2-use-placeholders-in-translated-term)

In this example, we will put values in a translation that contains placeholders.

```
use function Folded\getTranslation;

echo getTranslation("messages.home.welcome", ["name" => "John"]);
```

This implies you have a translation like following:

```
// lang/en/messages.php
return [
  "home" => [
    "welcome" => "Welcome, :name",
  ],
];
```

### 3. Get a pluralized translated term

[](#3-get-a-pluralized-translated-term)

In this example, will get a pluralizable term translation.

```
use function Folded\getVariableTranslation;

$numberOfPageViewed = 5000;

echo getVariableTranslation("messages.home.page-viewed", $numberOfPageViewed);
```

This implies you have the following folder structure:

```
.
└── lang/
    ├── en/
    │   └── messages.php
    └── fr/
        └── messages.php

```

And your `messages.php` file in the en folder contains:

```
return [
  "home" => [
    "page-viewed" => "{0} No page viewed|[1] One page viewed|[2,*] :count page viewed",
  ]
];
```

For more information, browse the [Laravel pluralized translation documentation](https://laravel.com/docs/7.x/localization#pluralization).

### 4. Change the lang before getting a translated term

[](#4-change-the-lang-before-getting-a-translated-term)

In this example, we will change the lang right before getting the translated term.

```
use function Folded\setTranslationLang;
use function Folded\getTranslation;

setTranslationLang("fr");

echo getTranslation("messages.home.title");
```

Version support
---------------

[](#version-support)

7.37.48.0v0.1.0❌✔️❓

###  Health Score

21

—

LowBetter than 18% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity44

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.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

2040d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/15908747?v=4)[Anwar](/maintainers/khalyomede)[@khalyomede](https://github.com/khalyomede)

---

Top Contributors

[![khalyomede](https://avatars.githubusercontent.com/u/15908747?v=4)](https://github.com/khalyomede "khalyomede (3 commits)")

---

Tags

localizationphppluralizationtranslation

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/folded-translation/health.svg)

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

###  Alternatives

[barryvdh/laravel-translation-manager

Manage Laravel Translations

1.7k3.6M17](/packages/barryvdh-laravel-translation-manager)[kkomelin/laravel-translatable-string-exporter

Translatable String Exporter for Laravel

3291.4M10](/packages/kkomelin-laravel-translatable-string-exporter)[tanmuhittin/laravel-google-translate

Translate translation files to other languages using google translate api

4312.2M11](/packages/tanmuhittin-laravel-google-translate)[tio/laravel

Add this package to localize your Laravel application (PHP, JSON or GetText).

170318.5k](/packages/tio-laravel)[vsch/laravel-translation-manager

Enhanced Laravel Translation Manager

184190.9k2](/packages/vsch-laravel-translation-manager)[laravel-lang/json-fallback

Adds support for fallback JSON string translation

162.2M4](/packages/laravel-lang-json-fallback)

PHPackages © 2026

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