GithubHelp home page GithubHelp logo

adriandmitroca / laravel-localization-helpers Goto Github PK

View Code? Open in Web Editor NEW

This project forked from potsky/laravel-localization-helpers

0.0 3.0 0.0 319 KB

Laravel Localization Helpers : commands to generate and update lang files automatically and more.

License: GNU General Public License v3.0

PHP 100.00%

laravel-localization-helpers's Introduction

Laravel Localization Helpers

Latest Stable Version Latest Unstable Version Build Status Coverage Status Total Downloads

This branch is the current dev branch

LLH is a set of artisan commands to manage translations in your Laravel project. Key features :

  • parse your code and generate lang files
  • translate your sentences automatically, thanks to Microsoft Translator API
  • configure output according to your code style

Table of contents

  1. Installation
  2. Configuration
  3. Usage
  4. Support
  5. Upgrade Notices
  6. Change Log
  7. Contribute

1. Installation

  • Choose your version according to the version compatibility matrix:
Laravel Package
4.2.x 2.0.x
5.0.x 2.1.x
5.1.x 2.2.x
5.2.x 2.3.x
  • Add the following line in the require-dev array of the composer.json file and replace the version if needed according to your Laravel version:

    "potsky/laravel-localization-helpers" : "2.3.*"
  • Update your installation : composer update

  • Add the following line in the providers array of the config/app.php configuration file :

    'Potsky\LaravelLocalizationHelpers\LaravelLocalizationHelpersServiceProvider'
  • Now execute php artisan list and you should view the new localization commands:

    ...
    localization
    localization:clear          Remove lang backup files
    localization:find           Display all files where the argument is used as a lemma
    localization:missing        Parse all translations in app directory and build all lang files
    ...
    

You can add the facade in the Aliases if you need to manage translations in your code :

'LocalizationHelpers' => 'Potsky\LaravelLocalizationHelpers\Facade\LocalizationHelpers'

2. Configuration

To configure your fresh installed package, please create a configuration file by executing :

php artisan vendor:publish

Then you can modify the configuration in file :

app/config/laravel-localization-helpers.php

Add new folders to search for, add your own lang methods or functions, ...

Backup files

You should not include backup lang files in GIT or other versioning systems.

In your laravel folder, add this in .gitignore file :

# Do not include backup lang files
app/lang/*/[a-zA-Z]*20[0-9][0-9][0-1][0-9][0-3][0-9]_[0-2][0-9][0-5][0-9][0-5][0-9].php

3. Usage

3.1 Command localization:missing

This command parses all your code and generates translations according to lang files in all lang/XXX/ directories.

Use php artisan help localization:missing for more informations about options.

Examples

Generate all lang files
php artisan localization:missing
Generate all lang files without prompt
php artisan localization:missing -n
Generate all lang files without backuping old files
php artisan localization:missing -b
Generate all lang files with automatic translations
php artisan localization:missing -t

You need to set your Microsoft Bing Translator credentials More informations here : https://github.com/potsky/microsoft-translator-php-sdk#user-content-2-configuration

Generate all lang files without keeping obsolete lemmas
php artisan localization:missing -o
Generate all lang files without any comment for new found lemmas
php artisan localization:missing -c
Generate all lang files without header comment
php artisan localization:missing -d
Generate all lang files and set new lemma values

3 commands below produce the same output:

php artisan localization:missing
php artisan localization:missing -l
php artisan localization:missing -l "TODO: %LEMMA"

You can customize the default generated values for unknown lemmas.

The following command let new values empty:

php artisan localization:missing -l ""

The following command prefixes all lemma values with "Please translate this : "

php artisan localization:missing -l "Please translate this : %LEMMA"

The following command set all lemma values to "Please translate this !"

php artisan localization:missing -l 'Please translate this !'
Silent option for shell integration
#!/bin/bash

php artisan localization:missing -s
if [ $? -eq 0 ]; then
echo "Nothing to do dude, GO for release"
else
echo "I will not release in production, lang files are not clean"
fi
Simulate all operations (do not write anything) with a dry run
php artisan localization:missing -r
Open all must-edit files at the end of the process
php artisan localization:missing -e

You can edit the editor path in your configuration file. By default, editor is Sublime Text on Mac OS X :

'editor_command_line' => '/Applications/Sublime\\ Text.app/Contents/SharedSupport/bin/subl'

For PHPStorm on Mac OS X:

'editor_command_line' => '/usr/local/bin/phpstorm'

3.2 Command localization:find

This command will search in all your code for the argument as a lemma.

Use php artisan help localization:find for more informations about options.

Examples

Find regular lemma
php artisan localization:find Search
Find regular lemma with verbose
php artisan localization:find -v Search
Find regular lemma with short path displayed
php artisan localization:find -s "Search me"
Find lemma with a regular expression
php artisan localization:find -s -r "@Search.*@"
php artisan localization:find -s -r "/.*me$/"

PCRE functions are used

3.3 Command localization:clear

This command will remove all backup lang files.

Use php artisan help localization:clear for more informations about options.

Examples

Remove all backups
php artisan localization:clear
Remove backups older than 7 days
php artisan localization:clear -d 7

4. Support

Use the github issue tool to open an issue or ask for something.

5. Upgrade notices

From v2.x.1 to v2.x.2

  • Parameter obsolete_array_key has been added in the configuration file. Add it in your configuration file.

From v1.x.x to v2.x.x

  • First you need to update your composer file to set the correct version
  • Take a look at the configuration file in the package to add new parameters you don't have in your current package configuration file.

6. Change Log

v2.x.3

  • new: adding possibility to disable check for obsolete lemmas (#27)
  • fix: Short-Option for "output-flat" and "php-file-extension" changed because the two-letter-code doesn't work (#27)

v2.x.2

  • show obsolete lemma when it is in array (#21)
  • fix a bug when using obsolete option (#22)

v2.x.1

  • fix a bug when using backup files and when a dot is in your laravel installation path (#20)

v2.x.0

  • new command localization:clear to remove backups
  • new option to specify output formatting (#17)
  • new option to specify flat arrays style output (#18)
  • new option to let the command translate sentences for you with Bing Translator
  • new translations are now:
    • marked with the TODO: prefix by default (if you ran two times the missing artisan command without translating lemma next to the first run, your missing translation were lost in the lang file. Now by default, just search for TODO in your lang file!)
    • translated of course if option t is used
    • shorten to their minimal value ( trans( 'message.child.this is a text' ) will now generate ['child'] => 'TODO: this is a text', and no more ['child'] => 'TODO: child.this is a text',)

Internally :

  • totally refactored
  • unit tests
  • test coverage
  • facade to let you use localization helpers in your code (translations, find missing translations, etc...)

v1.3.3

  • End of life. Version 1.x is no more supported and no longer works. Please use the correct version according to your laravel version.

v1.3.2

  • fix incompatibility with Laravel 5.2 (#16)

v1.3.1

  • add resource folder for Laravel 5

v1.3

  • add full support for Laravel 5

v1.2.2

  • add support for @lang and @choice in Blade templates (by Jesper Ekstrand)

v1.2.1

  • add lang_folder_path parameter in configuration file to configure the custom location of your lang files
  • check lang files in app/lang by default for Laravel 4.x
  • check lang files in app/resources/lang by default for Laravel 5

v1.2

  • support for Laravel 5 (4.3)
  • add ignore_lang_files parameter in configuration file to ignore lang files (useful for validation file for example)

7. Contribute

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Tests are in tests. To run the tests: vendor/bin/phpunit.

Coverage cannot decrease next a merge. To track file coverage, run vendor/bin/phpunit --coverage-html coverage and open coverage/index.html to check uncovered lines of code.

Dev badges : Dev Status Dev Coverage Status

laravel-localization-helpers's People

Contributors

adriandmitroca avatar ckithika avatar liingon avatar mpociot avatar potsky avatar rockkeeper avatar

Watchers

 avatar  avatar  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.