PhpBotFramework  1.0.0
A framework for Telegram Bots' APIs.
Functions | Variables
Multilanguage

Functions

DanySpin97\PhpBotFramework\Bot::getLanguageDatabase ($default_language='en')
 Get current user language from the database, and set it in $language. More...
 
DanySpin97\PhpBotFramework\Bot::getLanguageRedis ($default_language='en')
 Get current user language from redis, and set it in language. More...
 
DanySpin97\PhpBotFramework\Bot::getLanguageRedisAsCache ($default_language='en', $expiring_time='86400')
 Get current user language from redis, as a cache, and set it in language. More...
 
 DanySpin97\PhpBotFramework\Bot::setLanguageRedisAsCache ($language, $expiring_time='86400')
 Set the current user language in both redis, sql database and $language. More...
 

Variables

 DanySpin97\PhpBotFramework\Bot::$language
 Store the language for a multi-language bot.
 
 DanySpin97\PhpBotFramework\Bot::$localization
 Store the array containing language.
 
 DanySpin97\PhpBotFramework\Bot::$user_table = '"User"'
 Table contaning bot users data in the sql database.
 
 DanySpin97\PhpBotFramework\Bot::$id_column = 'chat_id'
 Name of the column that represents the user id in the sql database.
 

Detailed Description

Function Documentation

§ getLanguageDatabase()

& DanySpin97\PhpBotFramework\Bot::getLanguageDatabase (   $default_language = 'en')

Get current user language from the database, and set it in $language.

Parameters
$default_languageOptional. Default language to return in case of errors.
Returns
Language set for the current user, $default_language on errors.

§ getLanguageRedis()

& DanySpin97\PhpBotFramework\Bot::getLanguageRedis (   $default_language = 'en')

Get current user language from redis, and set it in language.

Using redis database we get language stored and the value does not expires.

Parameters
$default_languageOptional. Default language to return in case of errors.
Returns
Language for the current user, $default_language on errors.

§ getLanguageRedisAsCache()

& DanySpin97\PhpBotFramework\Bot::getLanguageRedisAsCache (   $default_language = 'en',
  $expiring_time = '86400' 
)

Get current user language from redis, as a cache, and set it in language.

Using redis database as cache, seeks the language in it, if there isn't then get the language from the sql database and store it (with default expiring of one day) in redis. It also change $language parameter of the bot to the language returned.

Parameters
$default_languageOptional. Default language to return in case of errors.
$expiring_timeOptional. Set the expiring time for the language on redis each time it is took from the sql database.
Returns
Language for the current user, $default_language on errors.

§ setLanguageRedisAsCache()

DanySpin97\PhpBotFramework\Bot::setLanguageRedisAsCache (   $language,
  $expiring_time = '86400' 
)

Set the current user language in both redis, sql database and $language.

Save it on database first, then create the expiring key on redis.

Parameters
$languageThe new language to set.
$expiring_timeOptional. Time for the language key in redis to expire.
Returns
On sucess, return true, throw exception otherwise.