在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):eko/GoogleTranslateBundle开源软件地址(OpenSource Url):https://github.com/eko/GoogleTranslateBundle开源编程语言(OpenSource Language):PHP 78.0%开源软件介绍(OpenSource Introduction):GoogleTranslateBundleFeatures
InstallationAdd the bundle to your {
"require" : {
"eko/googletranslatebundle": "dev-master"
}
} Add this to app/AppKernel.php <?php
public function registerBundles()
{
$bundles = array(
...
new Eko\GoogleTranslateBundle\EkoGoogleTranslateBundle(),
);
...
return $bundles;
} ConfigurationEdit app/config.ymlThe following configuration lines are required: eko_google_translate:
api_key: <your key api string> UsagesDetect a string languageRetrieve the detector service and call the $detector = $this->get('eko.google_translate.detector');
$value = $detector->detect('Hi, this is my string to detect!');
// This will return 'en' Translate a stringRetrieve the translator service and call the $translator = $this->get('eko.google_translate.translator');
$value = $translator->translate('Hi, this is my text to detect!', 'fr', 'en');
// This will return 'Salut, ceci est mon texte à détecter!' Translate a string from unknown language (use detector)Retrieve the translator service and call the $translator = $this->get('eko.google_translate.translator');
$value = $translator->translate('Hi, this is my text to detect!', 'fr');
// This will return 'Salut, ceci est mon texte à détecter!' Translate multiple stringsRetrieve the translator service and call the $translator = $this->get('eko.google_translate.translator');
$value = $translator->translate(array('Hi', 'This is my second text to detect!'), 'fr', 'en');
// This will return the following array:
// array(
// 0 => 'Salut',
// 1 => 'Ceci est mon second texte à détecter !',
// ) Note that you can also use an "economic mode" to translate multiple strings in a single request which is better for your application performances. Your translations will be concatenated in one single Google request. To use it, simply add $translator = $this->get('eko.google_translate.translator');
$value = $translator->translate(array('Hi', 'This is my second text to detect!'), 'fr', 'en', true);
// This will return the following array:
// array(
// 0 => 'Salut',
// 1 => 'Ceci est mon second texte à détecter !',
// ) Obtain all languages codes availableRetrieve the languages service and call the $languages = $this->get('eko.google_translate.languages')->get();
// This will return:
// array(
// array('language' => 'en'),
// array('language' => 'fr'),
// ...
// ) Obtain all languages codes available with their names translatedRetrieve the languages service and call the $languages = $this->get('eko.google_translate.languages')->get('fr');
// This will return:
// array(
// array('language' => 'en', 'name' => 'Anglais'),
// array('language' => 'fr', 'name' => 'Français'),
// ...
// ) Notice: this will consume a detector API call. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论