PHPackages                             mr-ajay/localizer - 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. mr-ajay/localizer

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

mr-ajay/localizer
=================

A Laravel package to simplify language translations 🙂

v1.0.1(1y ago)257MITPHPPHP ^8.0

Since Jun 3Pushed 1y agoCompare

[ Source](https://github.com/ajaydhakal1/Localizer)[ Packagist](https://packagist.org/packages/mr-ajay/localizer)[ RSS](/packages/mr-ajay-localizer/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (3)Versions (3)Used By (0)

Localizer Package for Laravel
=============================

[](#localizer-package-for-laravel)

A Laravel package to automatically extract translatable texts from your Blade views or live pages, inject Laravel localization strings (`{{ __('text') }}`), and translate them into multiple languages using LibreTranslate.

---

Features
--------

[](#features)

- Crawl specified pages (local Blade views or live URLs) to extract visible texts.
- Skip scripts, styles, and already localized texts.
- Automatically wrap extracted texts in Blade templates with `{{ __('text') }}`.
- Backup and restore Blade files safely during localization injection.
- Translate extracted texts into configured languages using LibreTranslate.
- Artisan commands to automate crawling and translation.

---

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

[](#requirements)

- Laravel 8.x or higher
- PHP 8.0 or higher
- [LibreTranslate](https://libretranslate.com/) running locally or accessible via URL
- Composer

---

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

[](#installation)

### Require the package via Composer

[](#require-the-package-via-composer)

```
composer require mr-ajay/localizer
```

### Publish the config file

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

```
php artisan vendor:publish --provider="MrAjay\Localizer\LocalizerServiceProvider" --tag="config"
```

### Configure `.env` file

[](#configure-env-file)

Add your LibreTranslate API URL:

```
LIBRETRANSLATE_URL=http://localhost:5000
```

---

Configuration
-------------

[](#configuration)

Edit the published config file `config/localizer.php`:

```
return [
    // Pages to crawl and extract texts from
    'pages' => [
        '/',                 // homepage
        '/about',            // about page
        // add other URL paths or Blade relative paths here
    ],

    // Target languages for translation (ISO codes)
    'languages' => ['ja', 'fr', 'ko'],

    // LibreTranslate API URL
    'api_url' => env('LIBRETRANSLATE_URL', 'http://localhost:5000'),
];
```

---

Usage
-----

[](#usage)

### Crawl and Translate All Pages

[](#crawl-and-translate-all-pages)

Run the main Artisan command to crawl all pages and generate translation files:

```
php artisan localize:all
```

This command will:

- Crawl all configured pages asynchronously.
- Extract visible texts, excluding scripts and styles.
- Backup and update your Blade files to wrap texts in `{{ __('text') }}` unless already localized.
- Save English base texts in `resources/lang/en.json`.
- Translate texts to configured languages and save JSON files in `resources/lang/{lang}.json`.

---

### Crawl and Translate Specific Pages

[](#crawl-and-translate-specific-pages)

Run this Artisan command to crawl specific pages specified in config and generate translation files:

```
php artisan localize
```

This command will:

- Crawl specific pages asynchronously.
- Extract visible texts, excluding scripts and styles.
- Backup and update your Blade files to wrap texts in `{{ __('text') }}` unless already localized.
- Save English base texts in `resources/lang/en.json`.
- Translate texts to configured languages and save JSON files in `resources/lang/{lang}.json`.

---

How It Works
------------

[](#how-it-works)

- **CrawlPages Job:** Uses Guzzle HTTP client and Symfony DomCrawler to fetch page content and extract texts.
- **Backup Blade files:** Before modifying Blade templates, backups are made. On error, backups are restored.
- **Inject localization strings:** Texts are replaced with `{{ __('text') }}` only if not already localized.
- **TranslateTexts Job:** Sends texts to LibreTranslate API to generate translated JSON files.
- **Progress and status** are output in the console.

---

Customizing Page to Blade File Mapping
--------------------------------------

[](#customizing-page-to-blade-file-mapping)

The package attempts to map URL paths to Blade files automatically. You can customize this logic inside the `CrawlPages` job:

```
$mapPageToBlade = function (string $page) {
    if ($page === '/') {
        return resource_path('views/welcome.blade.php');
    }
    return resource_path('views/' . ltrim($page, '/') . '.blade.php');
};
```

Adjust this mapping if your Blade files are structured differently.

---

Handling Blade Backups
----------------------

[](#handling-blade-backups)

- Original Blade files are backed up with `.backup` extension before localization injection.
- If an error occurs during modification, the original file is restored from backup.
- After successful update, the backup is deleted.
- You can manually restore files from backup if needed.

---

Translation Progress Display
----------------------------

[](#translation-progress-display)

Translations show progress as a percentage in the console, e.g.:

```
Translated 80% to ja

```

---

Troubleshooting
---------------

[](#troubleshooting)

- **No pages specified error:** Ensure `pages` array is defined in `config/localizer.php`.
- **Translation API errors:** Verify your LibreTranslate server is running and reachable via the configured URL.
- **Blade file not found warnings:** Make sure your page paths map correctly to Blade files.

---

Extending the Package
---------------------

[](#extending-the-package)

- Add support for more languages in `config/localizer.php`.
- Customize the DOM selectors or extraction logic in `CrawlPages`.
- Add support for other translation APIs by modifying `TranslateTexts`.

---

License
-------

[](#license)

MIT License — feel free to use and modify.

---

Contributing
------------

[](#contributing)

Contributions, issues, and feature requests are welcome!
Feel free to check the issues page.

---

Author
------

[](#author)

Created by **Ajay Dhakal** — [GitHub Profile](https://github.com/ajaydhakal1)

---

**Happy localizing! 🌐🚀**

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance47

Moderate activity, may be stable

Popularity11

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 60% 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 ~0 days

Total

2

Last Release

395d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/375e4fe320bda82f873fbad3ffb77f2faea3121689307b364792d9cad89d2ad0?d=identicon)[mr-ajay](/maintainers/mr-ajay)

---

Top Contributors

[![ajaydkl99](https://avatars.githubusercontent.com/u/196902095?v=4)](https://github.com/ajaydkl99 "ajaydkl99 (3 commits)")[![ajaydhakal1](https://avatars.githubusercontent.com/u/131642635?v=4)](https://github.com/ajaydhakal1 "ajaydhakal1 (2 commits)")

### Embed Badge

![Health badge](/badges/mr-ajay-localizer/health.svg)

```
[![Health](https://phpackages.com/badges/mr-ajay-localizer/health.svg)](https://phpackages.com/packages/mr-ajay-localizer)
```

###  Alternatives

[craftcms/cms

Craft CMS

3.6k3.6M3.1k](/packages/craftcms-cms)[spatie/crawler

Crawl all internal links found on a website

2.8k18.5M66](/packages/spatie-crawler)[spatie/laravel-export

Create a static site bundle from a Laravel app

674146.0k6](/packages/spatie-laravel-export)[neuron-core/neuron-ai

The PHP Agentic Framework.

2.0k656.1k38](/packages/neuron-core-neuron-ai)[sproutcms/cms

Enterprise content management and framework

242.5k4](/packages/sproutcms-cms)[drupal/core-dev

require-dev dependencies from drupal/drupal; use in addition to drupal/core-recommended to run tests from drupal/core.

2022.6M343](/packages/drupal-core-dev)

PHPackages © 2026

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