Download the PHP package chrissantiago82/laravel-google-translate without Composer
On this page you can find all versions of the php package chrissantiago82/laravel-google-translate. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download chrissantiago82/laravel-google-translate
More information about chrissantiago82/laravel-google-translate
Files in chrissantiago82/laravel-google-translate
Package laravel-google-translate
Short Description Laravel package for the Google Translate API
License MIT
Informations about the package laravel-google-translate
Laravel package for the Google Translate API
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.
Installation
-
You can install this package via composer using this command:
-
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:
This will create the package's config file called googletranslate.php
in the config
directory. These are the contents of the published config file:
How to use
-
After setting up the config file values you are all set to use the following methods :smile:
-
Detecting the language. You can pass both, a single string or an array of multiple strings to it:
-
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: -
Get all the available translations from 'Google Translation' for a particular language by passing its language code:
-
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:
-
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.
-
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
- 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.
Testing
You can run the tests with:
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
- Harish Toshniwal
- All Contributors
License
The MIT License (MIT). Please see the License File for more information.