All Projects → JoggApp → Laravel Google Translate

JoggApp / Laravel Google Translate

Licence: mit
This package makes using the Google Translate API in your laravel app a breeze with minimum to no configuration, clean syntax and a consistent package API.

Projects that are alternatives of or similar to Laravel Google Translate

Blogetc
Easily add a full Laravel blog (with built in admin panel and public views) to your laravel project with this simple package.
Stars: ✭ 198 (+104.12%)
Mutual labels:  laravel, laravel-package, package
Laravel Natural Language
This package makes using the Google Natural API in your laravel app a breeze with minimum to no configuration, clean syntax and a consistent package API.
Stars: ✭ 119 (+22.68%)
Mutual labels:  laravel, laravel-package, package
Laravel Short Url
A Laravel package to shorten urls
Stars: ✭ 127 (+30.93%)
Mutual labels:  laravel, laravel-package, package
Laravel Multilingual Routes
A package to handle multilingual routes in your Laravel application.
Stars: ✭ 241 (+148.45%)
Mutual labels:  laravel, laravel-package, package
Laravel Gitscrum
GitScrum is a Project Management Tool, developed to help entrepreneurs, freelancers, managers, and teams Skyrocket their Productivity with the Agile methodology and Gamification.
Stars: ✭ 2,686 (+2669.07%)
Mutual labels:  laravel, laravel-package, package
Laravel Aws Sns
Laravel package for the AWS SNS Events
Stars: ✭ 24 (-75.26%)
Mutual labels:  laravel, laravel-package, package
Package Skeleton
📦 My base for PHP packages.
Stars: ✭ 6 (-93.81%)
Mutual labels:  laravel, laravel-package, package
Laravel Pdf
A Simple package for easily generating PDF documents from HTML. This package is specially for laravel but you can use this without laravel.
Stars: ✭ 79 (-18.56%)
Mutual labels:  laravel, laravel-package, package
Laravel Mixpanel
Intuitive drop-in analytics.
Stars: ✭ 80 (-17.53%)
Mutual labels:  laravel, package
Laravel Schedule List
Laravel package to add command to list all scheduled artisan commands
Stars: ✭ 84 (-13.4%)
Mutual labels:  laravel, laravel-package
Flex Env
🌳 Manage your .env file in Laravel projects through artisan
Stars: ✭ 95 (-2.06%)
Mutual labels:  laravel, package
Admin One Laravel Dashboard
Admin One — Free Laravel Dashboard (Bulma Buefy Vue.js SPA)
Stars: ✭ 94 (-3.09%)
Mutual labels:  laravel, laravel-package
Laravel Url Shortener
Powerful URL shortening tools in Laravel
Stars: ✭ 80 (-17.53%)
Mutual labels:  laravel, laravel-package
Bigbluebutton
Package that provides easily communicate between bigbluebutton server and laravel framework
Stars: ✭ 85 (-12.37%)
Mutual labels:  laravel, laravel-package
Laravel Console Logger
Logging and Notifications for Laravel Console Commands.
Stars: ✭ 79 (-18.56%)
Mutual labels:  laravel, laravel-package
Laravel Id Generator
Easy way to generate custom ID from database table in Laravel framework.
Stars: ✭ 88 (-9.28%)
Mutual labels:  laravel, laravel-package
Laravel Sync Migration
Developer tool helps to sync migrations without refreshing the database
Stars: ✭ 89 (-8.25%)
Mutual labels:  laravel, laravel-package
Eloquent Approval
Approval process for Laravel Eloquent models
Stars: ✭ 79 (-18.56%)
Mutual labels:  laravel, laravel-package
Laravel Nullable Fields
Handles saving empty fields as null for Eloquent models
Stars: ✭ 88 (-9.28%)
Mutual labels:  laravel, package
Laravel Package Maker
Get a 📦 skeleton and all other `make` commands from laravel base for package development.
Stars: ✭ 89 (-8.25%)
Mutual labels:  laravel, package

Laravel package for the Google Translate API

Latest Version Total Downloads

This package makes using the Google Translate API in your laravel app a breeze with minimum to no configuration, clean syntax and a consistent package API.

translate

Installation

  • You can install this package via composer using this command:
composer require joggapp/laravel-google-translate
  • The package will automatically register itself.

  • We have documented how to setup the project and get the necessary configurations from the Google Cloud Platform console in a step by step detailed manner over here.

  • You can publish the config file using the following command:

php artisan vendor:publish --provider="JoggApp\GoogleTranslate\GoogleTranslateServiceProvider"

This will create the package's config file called googletranslate.php in the config directory. These are the contents of the published config file:

return [
    /*
    |----------------------------------------------------------------------------------------------------
    | The ISO 639-1 code of the language in lowercase to which the text will be translated to by default.
    |----------------------------------------------------------------------------------------------------
    */
    'default_target_translation' => 'en',

    /*
    |-------------------------------------------------------------------------------
    | Path to the json file containing the authentication credentials.
    |
    | The process to get this file is documented in a step by step detailed manner
    | over here:
    | https://github.com/JoggApp/laravel-google-translate/blob/master/google.md
    |-------------------------------------------------------------------------------
    */
    'api_key' => env('GOOGLE_TRANSLATE_API_KEY'),
];

How to use

  • After setting up the config file values you are all set to use the following methods 😄

  • Detecting the language. You can pass both, a single string or an array of multiple strings to it:

GoogleTranslate::detectLanguage('Hello world'): array

GoogleTranslate::detectLanguage(['Hello world', 'Laravel is the best']);

// Returns multi-dimensional array containing result set for all the array elements.
  • Translating the string(s): The translate method accepts a second optional argument which can be the code of the language you want the string to be translated in. You can specify the default option in the config file:
GoogleTranslate::translate('Hello world'): array

GoogleTranslate::translate(['Hello world', 'Laravel is the best']);

// Returns multi-dimensional array containing result set for all the array elements.
  • Get all the available translations from 'Google Translation' for a particular language by passing its language code:
GoogleTranslate::getAvaliableTranslationsFor('en'): array
  • Translate unless the language is same as the first argument. This method is a clean way to ask the package to detect the language of the given string, if it is same as the first argument, translation isn't performed. It accepts an optional third argument which is the language code you want the string to be translated in. You can specify the default option in the config file. If the languages are same, the input string is returned as it is, else an array is returned containing the translation results:
GoogleTranslate::unlessLanguageIs('en', string $text);
  • Translating and just returning back the translated string. It accepts an optional second argument which is the language code you want the string to be translated in. You can specify the default option in the config file.
GoogleTranslate::justTranslate(string $text): string
  • There is is an optional third parameter for format to take advantage for better html translation support. Google Translate API currently supports 'text' and 'html' as parameters. The default for this parameter is 'text' as it has the best use case for most translations. Google Translate API Docs
GoogleTranslate::unlessLanguageIs('en', string $text, string $format);
  • There is also a nice blade helper called @translate that comes with the package to make its use more neat in the view files. It accepts an optional second argument which is the language code you want the string to be translated in. You can specify the default option in the config file.
@translate('Hello World')

Testing

You can run the tests with:

vendor/bin/phpunit

Changelog

Please see the CHANGELOG for more information about what has changed recently.

Security

If you discover any security related issues, please email them to [email protected] instead of using the issue tracker.

Credits

License

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].