Giter Site home page Giter Site logo

auto-files-localizer's Introduction

Auto Files Localizer for Laravel

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Easy and Efficient Localiztion

A Laravel Localization package that auto generate json locale files

logo

Table of Contents

Features

  • Supports Laravel (8.X, 9.X, 10.X, 11.X).
  • 2 Modes (Dynamic Mode, Extraction Mode).
  • Fast and reliable.

Installation

You can install the package via composer:

composer require mahmoud217tr/auto-files-localizer

Config

To publish the package configuration file config/auto-localizer.php use the following command:

php artisan vendor:publish --tag="auto-files-localizer-config"

Usage

It will automatically generate the locale .json file where the localized new words are sorted alphabetically.

There are 2 modes for the package

Dynamic Mode

In this mode the translations will be generated dynamically (On Request) which means on upon calling the translation function the package will dynamically detect the current language and add the translations to the corresponding JSON file.

Notes

  • Note that this mode shouldn't work on production for performance purposes, but if you want to change this behavior via the configuration file.

  • This mode is not recommended using with vite development mode. If you want to use it please build your assets first using npm run build then activate the auto translation mode. OTHERWISE YOUR APP WILL STUCK IN RELOAD LOOP

Activiation

To activate the dynamic mode on non-production environment just add the following line to the .env file:

AUTO_LOCALIZER_ENABLED=true

And that's about it the autotranslator will add transaltions to there files sorted alphabetically. To deactivate the dynamic mode just set the previous value to false.

Configurations

This mode have the following configurations:

'dynamic' => [
    # Controls if the dynamic mode should work or not on non-production environments
    'enabled' => (bool) env('AUTO_LOCALIZER_ENABLED', false), 
    # Controls if the dynamic mode should work or on production environment (compined with the previous option)
    'production' => false,
],

Extraction Mode

In this mode the translations will be extracted automatically from views or php files detecting translation functions adding the translations to the corresponding JSON file.

Command

To extract the translations for a specific locale (ar for example) run the following command:

php artisan localizer:extract ar

The previous command will translate all non-localized phrases and all ar-localized phrases only.

Configurations

This mode have the following configurations:

'extraction' => [
    # The directories where the translation scanner will scan
    'directories' => [
        'resources/views',
    ],
    # The file patterns that the translation scanner will scan
    'patterns' => [
        '*.php'
    ],
    # The translation functions or directives that scanner will detect (you should add your custom functions here)
    'functions' => [
        '__',
        'trans',
        '@lang',
    ],
],

Testing

composer test

Changelog

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

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

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

auto-files-localizer's People

Contributors

mahmoud217tr avatar dependabot[bot] avatar github-actions[bot] avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.