Are you happy with your logging solution? Would you help us out by taking a 30-second survey? Click here

laravel-translation-manager

Manage Laravel translation files

Subscribe to updates I use laravel-translation-manager


Statistics on laravel-translation-manager

Number of watchers on Github 803
Number of open issues 134
Average time to close an issue 9 days
Main language PHP
Average time to merge a PR 5 days
Open pull requests 42+
Closed pull requests 11+
Last commit over 1 year ago
Repo Created over 5 years ago
Repo Last Updated over 1 year ago
Size 166 KB
Organization / Authorbarryvdh
Latest Releasev0.4.2
Contributors13
Page Updated
Do you use laravel-translation-manager? Leave a review!
View open issues (134)
View laravel-translation-manager activity
View on github
Fresh, new opensource launches 🚀🚀🚀
Trendy new open source projects in your inbox! View examples

Subscribe to our mailing list

Evaluating laravel-translation-manager for your project? Score Explanation
Commits Score (?)
Issues & PR Score (?)

Laravel 5 Translation Manager

For Laravel 4, please use the 0.1 branch!

This is a package to manage Laravel translation files. It does not replace the Translation system, only import/export the php files to a database and make them editable through a webinterface. The workflow would be:

- Import translations: Read all translation files and save them in the database
- Find all translations in php/twig sources
- Optionally: Listen to missing translation with the custom Translator
- Translate all keys through the webinterface
- Export: Write all translations back to the translation files.

This way, translations can be saved in git history and no overhead is introduced in production.

Screenshot

Installation

Require this package in your composer.json and run composer update (or run composer require barryvdh/laravel-translation-manager directly):

"barryvdh/laravel-translation-manager": "0.2.x@dev"

After updating composer, add the ServiceProvider to the providers array in config/app.php

'Barryvdh\TranslationManager\ManagerServiceProvider',

You need to run the migrations for this package.

$ php artisan vendor:publish --provider="Barryvdh\TranslationManager\ManagerServiceProvider" --tag=migrations
$ php artisan migrate

You need to publish the config file for this package. This will add the file config/translation-manager.php, where you can configure this package.

$ php artisan vendor:publish --provider="Barryvdh\TranslationManager\ManagerServiceProvider" --tag=config

In order to edit the default template, the views must be published as well. The views will then be placed in resources/views/vendor/translation-manager.

$ php artisan vendor:publish --provider="Barryvdh\TranslationManager\ManagerServiceProvider" --tag=views

Routes are added in the ServiceProvider. You can set the group parameters for the routes in the configuration. You can change the prefix or filter/middleware for the routes. If you want full customisation, you can extend the ServiceProvider and override the map() function.

This example will make the translation manager available at http://yourdomain.com/translations

Laravel >= 5.2

The configuration file by default only includes the auth middleware, but the latests changes in Laravel 5.2 makes it that session variables are only accessible when your route includes the web middleware. In order to make this package work on Laravel 5.2, you will have to change the route/middleware setting from the default

    'route' => [
        'prefix' => 'translations',
        'middleware' => 'auth',
    ],

to

    'route' => [
        'prefix' => 'translations',
        'middleware' => [
            'web',
            'auth',
        ],
    ],

NOTE: This is only needed in Laravel 5.2 (and up!)

Usage

Web interface

When you have imported your translation (via buttons or command), you can view them in the webinterface (on the url you defined with the controller). You can click on a translation and an edit field will popup. Just click save and it is saved :) When a translation is not yet created in a different locale, you can also just edit it to create it.

Using the buttons on the webinterface, you can import/export the translations. For publishing translations, make sure your application can write to the language directory.

You can also use the commands below.

Import command

The import command will search through app/lang and load all strings in the database, so you can easily manage them.

$ php artisan translations:import

Translation strings from app/lang/locale.json files will be imported to the _json group.

Note: By default, only new strings are added. Translations already in the DB are kept the same. If you want to replace all values with the ones from the files, add the --replace (or -R) option: php artisan translations:import --replace

Find translations in source

The Find command/button will look search for all php/twig files in the app directory, to see if they contain translation functions, and will try to extract the group/item names. The found keys will be added to the database, so they can be easily translated. This can be done through the webinterface, or via an Artisan command.

$ php artisan translations:find

If your project uses translation strings as keys, these will be stored into then _json group.

Export command

The export command will write the contents of the database back to app/lang php files. This will overwrite existing translations and remove all comments, so make sure to backup your data before using. Supply the group name to define which groups you want to publish.

$ php artisan translations:export <group>

For example, php artisan translations:export reminders when you have 2 locales (en/nl), will write to app/lang/en/reminders.php and app/lang/nl/reminders.php

To export translation strings as keys to JSON files , use the --json (or -J) option: php artisan translations:import --json. This will import every entries from the _json group.

Clean command

The clean command will search for all translation that are NULL and delete them, so your interface is a bit cleaner. Note: empty translations are never exported.

$ php artisan translations:clean

Reset command

The reset command simply clears all translation in the database, so you can start fresh (by a new import). Make sure to export your work if needed before doing this.

$ php artisan translations:reset

Detect missing translations

Most translations can be found by using the Find command (see above), but in case you have dynamic keys (variables/automatic forms etc), it can be helpful to 'listen' to the missing translations. To detect missing translations, we can swap the Laravel TranslationServiceProvider with a custom provider. In your config/app.php, comment out the original TranslationServiceProvider and add the one from this package:

//'Illuminate\Translation\TranslationServiceProvider',
'Barryvdh\TranslationManager\TranslationServiceProvider',

This will extend the Translator and will create a new database entry, whenever a key is not found, so you have to visit the pages that use them. This way it shows up in the webinterface and can be edited and later exported. You shouldn't use this in production, just in development to translate your views, then just switch back.

TODO

This package is still very alpha. Few thinks that are on the todo-list:

- Add locales/groups via webinterface
- Improve webinterface (more selection/filtering, behavior of popup after save etc)
- Seed existing languages (https://github.com/caouecs/Laravel-lang)
- Suggestions are welcome :)
laravel-translation-manager open issues Ask a question     (View All Issues)
  • almost 3 years Does not work if group contains slash
  • almost 3 years Unsupported operand types
  • almost 3 years Export resources
  • about 3 years array_merge(): Argument #2 is not an array
  • about 3 years Duplicate translations
  • about 3 years File creation fails if folder does not exist.
  • about 3 years Add default group
  • about 3 years [L5.3.x] BadMethodCallException: Method controller does not exist
  • about 3 years Separate locale, possible?
  • over 3 years Using jquery-ujs, ajaxSetup, and php in the javascript
  • over 3 years Import / export to JSON
  • over 3 years Make the package translatable
  • over 3 years Use [] syntax for arrays in exported files
  • over 3 years Export to ZIP instead of directly into app directory
  • over 3 years Refactor UI files
  • over 3 years Support vendor package translations files
  • over 3 years how to add a new key?
  • over 3 years postDelete bug
  • over 3 years ErrorException in Manager.php line 63: Array to string conversion in Laravel v.5.2.30
  • over 3 years This package is awesome
  • over 3 years Export to excel
  • over 3 years Can find in language have sub directory?
  • over 3 years Custom translation blade view
  • over 3 years Unable to install with Laravel 5.2.11
  • over 3 years Support for emoji
  • over 3 years [Permission denied] Error exception not handled
  • over 3 years Can't import from subfolder
  • almost 4 years Feature request: a separate middleware for each language
  • almost 4 years feature request: view only items not translated in a specific language
  • almost 4 years Requirements could not be resolved [Composer]
laravel-translation-manager open pull requests (View All Pulls)
  • Update README URLs based on HTTP redirects
  • PostgreSQL compatibility
  • Changed migration class name.
  • allow custom template
  • --added flag that allows disabling the option for adding new keys
  • --added flag that can hide keys from the list
  • --added possibility to set certain locales to be read-only
  • [FIX] trim value to avoid trailing spaces in the translations
  • Configurable base and language directory paths.
  • Improve web interface (L5 compatible only)
  • added the option to create new group
  • Implement subgroups (nested language files)
  • Ability to hide specified languages from Translation Manager Interface
  • Support sub-directories
  • add auto translate button for each group
  • Find translate like admin/menu.users
  • managing the subgroups (deep : 1)
  • Add info about the publish mechanism failing
  • Fix the import of subfolders on linux
  • Support for laravel package translations
  • Possibility to run migrations without publishing them
  • Add custom CSS file in public directory to allow override styles
  • Added support for nested translation files
  • Add default group for translation
  • Change view parameter to prevent 404 not found error
  • Default "group" dropdown translation and table filtering.
  • Feature :: Export All translations in Bulk
  • Re-introduce search function from 0.1
  • Add support for vue file import
  • Added a slash as separator to iterate with subdirectories when use find command.
  • Fix code style
  • Add beauty array print option
  • Updated routes to allow dictionaries in subfolders
  • Add new locale
  • create default value from key
  • Add auto translate with Google Translate
  • Converted Index View to Blade Syntax
  • Adds Support for third-party vendor packages
  • Fix Manager class preventing Artisan tests when this package is installed
  • Added orderBy clause to alphabetically order top level groups dropdown
  • Subfolders when exporting group
  • Provide possibility to exclude subfolder e.g. vendor
laravel-translation-manager list of languages used
Other projects in PHP