PHPackages                             wedesignit/laravel-translations-import - 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. [Database &amp; ORM](/categories/database)
4. /
5. wedesignit/laravel-translations-import

ActiveLibrary[Database &amp; ORM](/categories/database)

wedesignit/laravel-translations-import
======================================

Import translations from your Laravel translation files to your database.

v1.1.0(3y ago)116.3k↑266.7%4[6 issues](https://github.com/WeDesignIt/laravel-translations-import/issues)1MITPHPPHP ^7.4|^8.0CI failing

Since Jun 7Pushed 3y ago4 watchersCompare

[ Source](https://github.com/WeDesignIt/laravel-translations-import)[ Packagist](https://packagist.org/packages/wedesignit/laravel-translations-import)[ RSS](/packages/wedesignit-laravel-translations-import/feed)WikiDiscussions develop Synced 1mo ago

READMEChangelog (2)Dependencies (2)Versions (15)Used By (1)

Import your language files to the database (and much more)
==========================================================

[](#import-your-language-files-to-the-database-and-much-more)

This package provides you with commands to deal with your lang files and your database. Instead of manually adding translations to your database, this commandset gives you the tools needed to import and export translations, find unimported translations in your php/twig files, clean empty translations from your database and to delete all translations in one go!

Usefulness and credit
---------------------

[](#usefulness-and-credit)

It's particularly useful in the case you're using a package like
[Spatie's Laravel Translation Loader](https://github.com/spatie/laravel-translation-loader). In this case the lang files can be used as 'defaults' to import into a project. When you want to add new defaults, just add them to your lang file(s), rerun the import command and the newly added translations will be added for usage, without the existing translations being modified. You can export the files if you want the updated translations to be used as default.

Credit to [Barryvdh's Translation Manager](https://github.com/barryvdh/laravel-translation-manager) for creating this package which we could build on.

Upgrading
---------

[](#upgrading)

See [upgrading](upgrading.md) for details.

Usage
-----

[](#usage)

### The import command

[](#the-import-command)

```
php artisan translations:import

```

This command will import all translation files located in the set lang folder.

The command offers 6 options:

- `ignore-locales`: Allows you to set locales that should **not** be imported.
    Example: `--ignore-locales=fr,de`.
- `ignore-groups`: Allows you to set groups that should **not** be imported.
    Example: `--ignore-groups=routes,admin/dashboard,frontend/employer`.
- `only-groups`: Allows you to set groups that should **only** be imported. No other group will be imported. Works like `ignore-groups`.
- `overwrite`: Option to enable overwriting existing translations in the database. Shortcut `o`.
- `allow-vendor`: Option to allow vendor translation overrides to be imported (The lang files at `lang/vendor/{package}/`). Shortcut `a`.
- `allow-json`: Option to allow JSON translations to be imported. Shortcut `j`.

Command options should be split by commas.
For groups, a wildcard (\*) can be used at the end to allow all subdirectories to be processed as well (for either `ignore` or `only`). Example: `--only-groups=admin/*`.

### The export command

[](#the-export-command)

```
php artisan translations:export

```

This command will take all translations in the database, and write them to the lang folder. Existing translations will be overwritten (except for files that don't exist in the database).

The command offers 4 options:

- `ignore-groups`
- `only-groups`
- `allow-vendor`
- `allow-json`

These options work the same as explained with the import command

### The find command

[](#the-find-command)

```
php artisan translations:find

```

This command will find all translations in your php/twig files, and import them if they do not exist in the database.

*Keep in mind that this command should be handled with care, imagine we have this in a blade and trans file:*

```
@foreach(__('admin/employers.datatables.filter.statuses') as $value => $translation)
    {{$translation}}
@endforeach
```

```
// admin/employers.php
'datatables' => [
    'filter' => [
        'statuses' => [
            'active' => 'Actief',
            'not-active' => 'Inactief',
            'approved' => 'Goedgekeurd',
            'declined' => 'Afgekeurd',
        ],
    ],
];
```

*The command will find this translation and import it, it will encode the value of the 'statuses'.*

The command offers 1 option:

- `path`: By default, the find command starts in the root directory. Using this option, you can point the command to only search in a subdirectory.
    Example: `--path=resources/lang`.
- `force-confirm`: Option to enable automatically confirming all found translations. Without this, you have to confirm each import manually. Shortcut `c`.

### The clean command

[](#the-clean-command)

```
php artisan translations:clean

```

This command will remove all translations which do not have a stored value.

The command has no options.

### The delete command

[](#the-delete-command)

```
php artisan translations:nuke

```

This command will remove all translations.

The command has 1 option:

- `only-groups`

This options works the same as explained with the import command

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

[](#installation)

You can install the package via composer:

```
composer require wedesignit/laravel-translations-import
```

Config
------

[](#config)

By default, the config sets the tables and columns following the `language_lines`table from the [Spatie's Laravel Translation Loader](https://github.com/spatie/laravel-translation-loader)migration, with the following structure:

- `group`: Stores the group (`string`).
- `key`: Stores the key (`string`).
- `text`: Stores the translation (in JSON format) (`text`).

Optionally you could publish the config file to change table and column names.

```
php artisan vendor:publish --provider="WeDesignIt\LaravelTranslationsImport\TranslationsImportServiceProvider" --tag="config"
```

This is the content of the published config file:

```
