Translation Manager for Laravel, built with TALL stack.

0.3.1 2022-10-11 10:23 UTC

This package is auto-updated.

Last update: 2024-04-15 09:06:09 UTC


README

Lingua Banner

👅 Lingua

Translation Manager for Laravel, built with TALL stack.

🇮🇹 From Italian: Lingua means both Tongue and Language

Latest Version on Packagist GitHub Tests Action StatusTotal Downloads Total Downloads

Lingua is a dashboard that allows you to create, manage and import your translations for your project.

This package is in pre-release with known issues. Please report them.

The new Release - 0.3 - bring a lot of changes, mainly in the interface. Screenshots here still outdated.

I would like to warmly thank Spatie and Freek to have taught me how to develop packages.

Requirements

  1. Install AlpineJS and include it in your JS file.
  2. Install Livewire.
  3. Then you can install the package via composer.

Installation

composer require alessandrobelli/lingua

This package needs a column called linguaprojects on the user table, as well as a table "translations".

You can publish and run the migrations with:

php artisan vendor:publish --provider="alessandrobelli\Lingua\LinguaServiceProvider" --tag="migrations"
php artisan migrate

Usage

You need to add the routes to your web.php file.

Route::lingua('desiredslug');

Then you can go to /desiredslug to see the dashboard.

Lingua_Dashboard

To use the translation files for Javascript files place this into your header:

    <script>
        window.trans = [];
        window.trans = <?php
        if(File::exists(resource_path() . "/lang/" . App::getLocale() . '.json'))
        {
            $json_file = File::get(resource_path() . "/lang/" . App::getLocale() . '.json');
            echo json_decode(json_encode($json_file, true));
        }
        else{
            echo "[]";
        }
        ?>;
    </script>

Then make a prototype function in Javascript to detect the trans() function inside your Javascript files, or use this, in case you use Vuejs and Lodash:

Vue.prototype.trans = (key) => {
    if (_.isUndefined(window.trans[key])) {
        return key;
    } else {
        if (window.trans[key] === "") return key;
        return window.trans[key];
    }
};

The language shown will be according to the locale of the browser, or you can use this tutorial which worked for me.

More

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email info@alessandrobelli.it instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.