Laravel Package to translate with a translation API

Today I would like to share about a laravel package that I wrote recently. That package is to translate languages easily using a translation API. I had to use a translation api in my project. Then I wanted to write short code for translation feature and reuse it for future. So I created this package locally.

Methods that can be used

After creating Translation Object, you can use the following methods.

$obj = new Translate();

Translation

$translated_text = $obj->translate('Hello World", 'EN', 'JA'); 

echo $translated_text;

Getting supported languages

$languages = $obj->languages();

foreach($languages as $lang){
    echo $lang['language']."-".$lang['name'].'<br>';
}

Getting supported sourcelanguages

$source_languages = $obj->languages('source');

foreach($source_languages as $lang){
    echo $lang['language']."-".$lang['name'].'<br>';
}

Getting supported targetlanguages

$target_languages = $obj->languages('target');

foreach($target_languages as $lang){
    echo $lang['language']."-".$lang['name'].'<br>';
}

You can monitor your usage of translation API

$usage= $obj->usage();

echo $usage['character_count'].' characters have been used. Maximum number of characters that can be translated in the current billing period are '.$usage['character_limit'];

You can setup a timeout in requesting api

$obj->setTimeout(10);

Hope you enjoyed that.

By Asahi



アプリ関連ニュース

お問い合わせはこちら

お問い合わせ・ご相談はお電話、またはお問い合わせフォームよりお受け付けいたしております。

tel. 06-6454-8833(平日 10:00~17:00)

お問い合わせフォーム