PHPackages                             zachleigh/laravel-lang-bundler - 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. zachleigh/laravel-lang-bundler

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

zachleigh/laravel-lang-bundler
==============================

Create Laravel translations bundles.

v1.1.0(7y ago)2512.5kMITPHPPHP &gt;=7.1

Since Oct 30Pushed 7y ago1 watchersCompare

[ Source](https://github.com/zachleigh/laravel-lang-bundler)[ Packagist](https://packagist.org/packages/zachleigh/laravel-lang-bundler)[ RSS](/packages/zachleigh-laravel-lang-bundler/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (10)Dependencies (3)Versions (18)Used By (0)

Laravel Lang Bundler
====================

[](#laravel-lang-bundler)

[![Latest Stable Version](https://camo.githubusercontent.com/af86591b151650ba0d029bcc85114fa386f5ee77391f73841b97820efb8d7716/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7a6163686c656967682f6c61726176656c2d6c616e672d62756e646c65722e737667)](//packagist.org/packages/zachleigh/laravel-lang-bundler)[![License](https://camo.githubusercontent.com/074b89bca64d3edc93a1db6c7e3b1636b874540ba91d66367c0e5e354c56d0ea/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e737667)](//packagist.org/packages/zachleigh/laravel-lang-bundler)[![Build Status](https://camo.githubusercontent.com/573cfa273af5b99739f76a871f53cfc29eb549848a2cc2f631dc324505408882/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f7a6163686c656967682f6c61726176656c2d6c616e672d62756e646c65722f6d61737465722e737667)](https://travis-ci.org/zachleigh/laravel-lang-bundler)[![Quality Score](https://camo.githubusercontent.com/79669082f574bcda44b3a51cdd7f91d09b8530d2f363e170d6af6b27f31ba0bc/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f7a6163686c656967682f6c61726176656c2d6c616e672d62756e646c65722e737667)](https://scrutinizer-ci.com/g/zachleigh/laravel-lang-bundler/)[![StyleCI](https://camo.githubusercontent.com/20086f3cf06465e70b0f1ae01340ea6352c715f98a2125717510b68681e41852/68747470733a2f2f7374796c6563692e696f2f7265706f732f37323335323035382f736869656c643f7374796c653d666c6174)](https://styleci.io/repos/72352058)[![Total Downloads](https://camo.githubusercontent.com/c66b562c2ba71a76ca90e1eb9b73c32801a01225a3b64cfd7b8ecb9679e71f77/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7a6163686c656967682f6c61726176656c2d6c616e672d62756e646c65722e737667)](https://packagist.org/packages/zachleigh/laravel-lang-bundler)

##### Make bundles of translation values.

[](#make-bundles-of-translation-values)

### Contents

[](#contents)

- [Why](#why)
- [Upgrade Information](#upgrade-information)
- [Install](#install)
- [Usage](#usage)
- [Advanced Usage](#advanced-usage)
- [Commands](#commands)
- [Configuration](#configuration)
- [Limitations](#limitations)
- [Testing](#testing)
- [Contributing](#contributing)

### Why

[](#why)

Why use this package? Because this sucks:

```

```

And this is so much better:

```
toJson() }}
>
```

### Upgrade Information

[](#upgrade-information)

##### Version 1.0.\* to Version 1.1.\*

[](#version-10-to-version-11)

Version 1.1.0 drops support for PHP versions lower than 7.1.

##### Version 0.9.\* to Version 1.0.0

[](#version-09-to-version-100)

Version 1.0.0 is more a confimation of the current api and usage than anything else. Adds support for Laravel 5.4. If using Laravel 5.3, please use [Version 0.9.11](https://github.com/zachleigh/laravel-lang-bundler/tree/v0.9.11):

```
composer require zachleigh/laravel-lang-bundler:0.9.*

```

### Install

[](#install)

##### 1. Install through composer

[](#1-install-through-composer)

```
composer require zachleigh/laravel-lang-bundler

```

##### 2. Register the service provider

[](#2-register-the-service-provider)

In Laravel's config/app.php file, add the service provider to the array with the 'providers' key.

```
LaravelLangBundler\ServiceProvider::class

```

##### 3. Publish the config file:

[](#3-publish-the-config-file)

```
php artisan vendor:publish --tag=config

```

##### 4. Create a 'bundles' directory in resources/lang/.

[](#4-create-a-bundles-directory-in-resourceslang)

Do it manually or use the command:

```
php artisan langb:start

```

### Usage

[](#usage)

##### 1. Make a bundle.

[](#1-make-a-bundle)

Imagine we have two lang files, one called 'home.php' and one called 'user.php'.

home.php

```
    'welcome' => 'Welcome!',
    'login' => 'Login',
    'signup' => 'Signup',
```

user.php

```
    'profile' => 'Your Profile',
    'friends' => 'Your Friends',
    'body' => 'Enter body below',
```

We want all of these values in one bundle.

Simply register your bundle as an array anywhere in the bundles directory. For example, in the bundles directory, you could create a folder called 'components' and in it a file called 'bundle\_name' that looks like this:

```
return [
    'home.welcome',
    'home.login',
    'home.signup',
    'user.profile',
    'user.friends',
    'user.body'
];
```

Obviously, 'bundle\_name' is the name of the bundle. The other values represent keys found in the above lang files.

Like in other lang folders, any file/folder in the bundles directory is treated as a level in an array. So in the above example, our file path looks like this:

lang/bundles/components/bundle\_name.php

The path for the 'bundle\_name' bundle would be 'bundles.components.bundle\_name'. It is also possible to create multiple named bundles within a single file, but this is not recommended because you can not use auto-aliasing for multi-bundle files.

##### 2. Get the bundle using the transB() helper function.

[](#2-get-the-bundle-using-the-transb-helper-function)

Get your translated bundle by passing the bundle path to the transB() helper function.

```
transB('bundles.components.bundle_name');
```

Or use the auto-aliased name:

```
transB('bundle_name');
```

transB() returns a collection of translated values keyed by the original translation key. Continuing the example above, transB() would give us a collection that contains the following array:

```
[
    'welcome' => 'Welcome!',
    'login' => 'Login',
    'signup' => 'Signup',
    'profile' => 'Your Profile',
    'friends' => 'Your Friends',
    'body' => 'Enter body below',
];
```

##### 3. Pass parameters to your bundle.

[](#3-pass-parameters-to-your-bundle)

Like with the standard trans() function, you may pass parameters to the transB() function as the second argument.

```
transB('bundle_name', ['parameterName' => $value]);
```

If your bundle has conflicting parameter names, you can namespace them. In this example, three values require a `user` parameter.

user.php translation file:

```
return [
    'welcome_user' => 'Welcome :user',
    'message_to'   => 'You sent a message to :user',
    'invite_from'  => 'You have an invite from :user'
];
```

Bundle file:

```
return [
    'user.welcome_user',
    'user.message_to',
    'user.invite_from'
];
```

Avoid the naming conflict by namespacing the parameters when passing them to transB():

```
transB('bundle_name', [
    'welcome_user.user' => 'Bob',
    'message_to.user' => 'Sally',
    'invite_from.user' => 'George'
]);
```

##### 4. Pluralize values

[](#4-pluralize-values)

It is possible to pluralize lang items by passing a namespaced 'choice' parameter in the transB() function parameters. For example, if our lang file value looked like this:

```
'inbox_status' => 'You have a new message.|You have new messages'
```

We could register it in our bundle normally:

```
'home.inbox_status'
```

And then when calling transB(), pass a parameter called 'inbox\_status.choice' with the desired choice value:

```
transB('bundle_name', ['inbox_status.choice' => 3]);
```

The result will look be the pluralized string "You have new messages".

### Advanced Usage

[](#advanced-usage)

#### Modify return keys and values

[](#modify-return-keys-and-values)

To modify the key and value in the returned translation array, use the bundle\_item() helper on a specific bundle item.

```
bundle_item($id, $type, $parameters = []);
```

$id is the lang key. $type must be in the following format: 'target\_type'. 'target' declares what item is to be affected by the modification and can be set to either 'value', 'key', or 'both'. 'type' declares the type of modification (callback, change etc.). $parameters is an array of parameters to be sent to the class that performs the modification.

If using the same example as above we wanted to convert the 'welcome\_user' value to all caps, we could accomplish it by using the bundle\_item() helper function in the bundle file.
user.php translation file:

```
return [
    'welcome_user' => 'Welcome :user',
    'message_to'   => 'You sent a message to :user',
    'invite_from'  => 'You have an invite from :user'
];
```

Bundle file:

```
return [
    bundle_item('user.welcome_user', 'value_strtoupper'),
    'user.message_to',
    'user.invite_from'
];
```

Wrap the bundle key 'user.welcome\_user' in the bundle\_item() global function and pass the translation key ($id) plus the type (perform a 'strtoupper' on the returned 'value'). This returns the following values (assuming a non-namespaced user variable with the value 'Bob'):

```
[
    'welcome_user' => 'WELCOME BOB',
    'message_to'   => 'You sent a message to Bob',
    'invite_from'  => 'You have an invite from Bob'
];

```

If we wanted to do the same to the key, we could do this:

```
return [
    bundle_item('user.welcome_user', 'key_strtoupper'),
    'user.message_to',
    'user.invite_from'
];
```

Or, if we wanted to perform the modification on both the key and the value:

```
return [
    bundle_item('user.welcome_user', 'both_strtoupper'),
    'user.message_to',
    'user.invite_from'
];
```

##### Available modifiers

[](#available-modifiers)

###### callback

[](#callback)

Perform a callback on a key or value. Requires a 'callback' parameter.

```
bundle_item('user.welcome_user', 'value_callback', [
    'callback' => 'function_name'
]),
```

###### change

[](#change)

Change a key to a new value. Does nothing to values. Requires 'new' parameter.

```
bundle_item('user.invite_from', 'key_change', [
    'new' => 'newKey'
]),
```

###### explode

[](#explode)

Explode by given delimiter. Does nothing to key. Requires 'delimiter' parameter.

```
bundle_item('user.invite_from', 'value_explode', [
    'delimiter' => ' '
]),
```

###### strtolower

[](#strtolower)

Lowercase entrire string.

```
bundle_item('home.invite_from', 'value_strtolower')
```

###### strtoupper

[](#strtoupper)

Capitalize entire string.

```
bundle_item('home.invite_from', 'value_strtoupper')
```

###### ucfirst

[](#ucfirst)

Make first character in string capitalized.

```
bundle_item('home.invite_from', 'value_ucfirst')
```

###### values

[](#values)

If translation value is an array, run array\_values() on array and return only values keyed by integers. Does nothing to keys.

```
bundle_item('home.months', 'value_values')
```

##### Creating your own modifier

[](#creating-your-own-modifier)

Use the 'mod' command to create a new mod class in App/LangBundler/Mods:

```
langb:mod {name}

```

There are two abstract methods that must be implemented in your class:

```
    /**
     * Alter key and return.
     *
     * @param string $key
     *
     * @return string
     */
    abstract public function key($key);

    /**
     * Alter value and return.
     *
     * @param mixed $value
     *
     * @return mixed
     */
    abstract public function value($value);
```

The same class is used to modify both the value and key. Define your modification and return the desired key/value.

### Commands

[](#commands)

##### php artisan langb:start

[](#php-artisan-langbstart)

Get started by creating a bundles directory in your lang folder.

##### php artisan langb:new {path}

[](#php-artisan-langbnew-path)

Create a new bundle file located at path. For example:

```
php artisan langb:new components.user.profile

```

This would create the file lang/bundles/components/user/profile.php with an empty returned array.

##### php artisan langb:mod {name}

[](#php-artisan-langbmod-name)

Create an empty mod template in App/LangBundler/Mods.

### Configuration

[](#configuration)

##### aliases

[](#aliases)

To shorten the name of bundles, you can register aliases in config.

```
'aliases' [
    'alias' => 'full.path.to.bundle'
];
```

And then simply use the alias istead of the path in transB():

```
transB('alias');
```

##### key\_transform

[](#key_transform)

If you wish to transform lang file keys to snake\_case, StudlyCase, or camelCase, set `key_transform` to 'snake\_case', 'studly\_case', or 'camel\_case'. Default value is 'none'.
For example, this bundle contains snake cased variables:

```
return [
    'user.welcome_user',
    'user.message_to',
    'user.invite_from'
];
```

But in your javascript, you want to use came cased variables, set `key_transform` to 'camel\_case' to get this bundle:

```
return [
    'welcomeUser' => 'Welcome user!',
    'messageTo' => 'Message to user',
    'inviteFrom' => 'You have an invitation from user!',
];
```

Many other simple string functions (ucfirst, strtoupper, etc.) also work.

key\_transform is global and will transform all keys in your project. If you wish to transform a single key, see [modify return keys and values](#modify-return-keys-and-values).

##### global\_key\_namespace

[](#global_key_namespace)

If you keep all your translations in a single file, you can set `global_key_namespace` to the name of the file to save yourself some typing. For example, if all your translations are in a file called 'translations.php', you would have to register a bundle like this:

```
return [
    'bundle_name' => [
        'translations.home',
        'translations.navigation',
        'translations.menu',
        'translations.login'
    ];
];
```

However, if you set `global_key_namespace` to 'translations', you could register it like this:

```
return [
    'bundle_name' => [
        'home',
        'navigation',
        'menu',
        'login'
    ];
];
```

### Testing

[](#testing)

```
composer test

```

### Contributing

[](#contributing)

Contributions are more than welcome. Fork, improve and make a pull request. For bugs, ideas for improvement or other, please create an [issue](https://github.com/zachleigh/laravel-lang-bundler/issues).

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity28

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity67

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

Recently: every ~151 days

Total

16

Last Release

2790d ago

Major Versions

v0.9.11 → v1.0.02017-01-25

PHP version history (3 changes)v0.9.0PHP &gt;=5.5.9

v0.9.10PHP &gt;=5.6.0

v1.1.0PHP &gt;=7.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/00a76b63e84a85f8770b1b02b1190c03400c48528f0c33262f7789d35eca875d?d=identicon)[zachleigh](/maintainers/zachleigh)

---

Top Contributors

[![zachleigh](https://avatars.githubusercontent.com/u/5616626?v=4)](https://github.com/zachleigh "zachleigh (76 commits)")

---

Tags

languagelaravellocalisationtranslationlaravellocalizationlanguagetranslationlang

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/zachleigh-laravel-lang-bundler/health.svg)

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

###  Alternatives

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

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

2414.0k1](/packages/inpsyde-multilingual-press)[opgginc/codezero-laravel-localized-routes

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

2770.1k1](/packages/opgginc-codezero-laravel-localized-routes)[longman/laravel-multilang

Package to integrate multi language (multi locale) functionality in Laravel 5.x

5514.4k1](/packages/longman-laravel-multilang)[awes-io/localization-helper

Package for convenient work with Laravel's localization features

3527.1k4](/packages/awes-io-localization-helper)[herkod/laravel-tr

Laravel İçin Türkçe Çeviri Dosyaları

628.1k](/packages/herkod-laravel-tr)

PHPackages © 2026

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