PHPackages                             mishalestev/laravel-files-translator - 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. mishalestev/laravel-files-translator

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

mishalestev/laravel-files-translator
====================================

Extract translations from HTML/Blade files and generate translation files.

1.0.1(1y ago)06MITPHPPHP &gt;=8.0

Since Dec 20Pushed 1y ago1 watchersCompare

[ Source](https://github.com/LestevMisha/laravel-files-translator)[ Packagist](https://packagist.org/packages/mishalestev/laravel-files-translator)[ GitHub Sponsors](https://github.com/LestevMisha)[ RSS](/packages/mishalestev-laravel-files-translator/feed)WikiDiscussions main Synced 1mo ago

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

Laravel Files Translator
========================

[](#laravel-files-translator)

**Files Translator for Laravel** - is a package designed to streamline the process of extracting and translating text content from Blade or HTML files in your Laravel applications.

---

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

[](#installation)

Run the following command in your Laravel project directory:

```
composer require mishalestev/laravel-files-translator
```

---

If you're unsure how this package works, please watch our short introductory video:

[![accessibility text](materials/export.jpg)](https://youtu.be/IsiUgIftRiw)

Under 10 minutes [✅ https://youtu.be/IsiUgIftRiw](https://youtu.be/IsiUgIftRiw)

---

### Example Use Case

[](#example-use-case)

Suppose you have a file with the following text (that is the 4th commandement):

```
Remember the sabbath day, to keep it holy.
Six days shalt thou labour, and do all thy work:
But the seventh day is the sabbath of the Lord thy God:
in it thou shalt not do any work, thou, nor thy son,
nor thy daughter, thy manservant, nor thy maidservant,
nor thy cattle, nor thy stranger that is within thy gates:
For in six days the Lord made heaven and earth,
the sea, and all that in them is, and rested the seventh day:
wherefore the Lord blessed the sabbath day, and hallowed it.
```

To translate this content into Spanish, run the following command:

```
php artisan translate:file --lang=es --input=resources/views/commandments.blade.php --output=lang/en/commandments.php
```

This command will:

1. **Generate a Translated Blade File:**
    It creates a new Blade file with the text replaced by `__()` translation calls. This file uses unique keys mapped to text segments, due to maintenance considerations.
2. **Produce Corresponding Translation Files:**
    It generates translation files within your `lang/` directory. You get both the source language and the target language files populated with key-value pairs, mapping each text snippet to its translation.

---

### Resulting Files

[](#resulting-files)

**Translated Blade File:**

*`resources/views/commandment_translated.blade.php`*

```
>

   {{ __('commandement.key_217762278049d3017bfd946d250bd8c1') }}
   {{ __('commandement.key_1eeafa582e3c49562668d54bb368c58e') }}
   {{ __('commandement.key_3238a9234abe3dcd02238d0d8b5c1fb5') }}
   {{ __('commandement.key_8381b742e34b685e1a0cfb81867efb98') }}
   {{ __('commandement.key_730695692e7cfd2b1470e572af9d8644') }}
   {{ __('commandement.key_a6c36c16f68a094a27ae3e2177911d6c') }}
   {{ __('commandement.key_236abf8e864840c6277606a1254e7b35') }}
   {{ __('commandement.key_346637a025ad4a8655361a22322999bc') }}
   {{ __('commandement.key_ec75f0ccfa23369829f182a6a3cb0e31') }}

```

**Translation Files:**

*`lang/es/commandement.php`*

```
