Download the PHP package zubs/translator without Composer
On this page you can find all versions of the php package zubs/translator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download zubs/translator
More information about zubs/translator
Files in zubs/translator
Package translator
Short Description A simple Laravel package that can translate between languages
License ISC
Informations about the package translator
Zubs/Translator
A simple Laravel package that can translate between languages.
Installation
You can install this package via composer using this command:
Then, the service provider is automatically registered.
Usage
Methods
This package provides the Zubs\Translator\Translate
and that provides the following methods:
getLanguages()
getLanguageCodes()
detectLanguage()
translate()
All the methods cache results for better performances. The cache defaults to 24hrs but can be changed by passing an extra parameter to the methods.
Get all available languages with getLanguages()
This function definition looks like this:
The target
parameter is optional and defaults to en
. This is the language that the returned array will be translated to.
The ttl
is used to set the time that the cache will be stored for. It defaults to 1 day.
The function returns an array of all available languages in the format, code => language
, like this:
Get the language codes of all available languages with getLanguageCodes()
This function definition looks like this:
This function takes just one parameter, ttl
, and returns the same array as the getLanguages()
function, but without the language names. Like this:
The ttl
is used to set the time that the cache will be stored for. It defaults to 1 day.
Detect the language of a string with detectLanguage()
This function definition looks like this:
This function takes a mandatory string, text
as a parameter. It also takes an optional parameter, ttl
.
The ttl
is used to set the time that the cache will be stored for. It defaults to 1 day.
The function returns the language code of the language that the string is written in. Like this:
Translate a string with translate()
This function definition looks like this:
This function takes a mandatory string, text
, as a parameter and returns the translated string.
The to
parameter is the language code of the language that the string should be translated to.
The from
parameter is the language code of the language that the string is written in.
If the from
parameter is not provided, the function will try to detect the language of the string.
The ttl
is used to set the time that the cache will be stored for. It defaults to 1 day.
The function can be used like this:
API
The package also exposes a few API endpoints that can be used to achieve the same results as the methods above.
GET /languages
- returns all available languagesGET /language/codes
- returns the language codes of all available languagesPOST /detect-language
- returns the language code of the language that a string is written inPOST /translate
- returns a translated string