<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
- <content url="file://$MODULE_DIR$" />
+ <content url="file://$MODULE_DIR$">
+ <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" packagePrefix="Cubist\Azure\Translate\" />
+ <excludeFolder url="file://$MODULE_DIR$/vendor/carbonphp/carbon-doctrine-types" />
+ <excludeFolder url="file://$MODULE_DIR$/vendor/composer" />
+ <excludeFolder url="file://$MODULE_DIR$/vendor/doctrine/inflector" />
+ <excludeFolder url="file://$MODULE_DIR$/vendor/guzzlehttp/guzzle" />
+ <excludeFolder url="file://$MODULE_DIR$/vendor/guzzlehttp/promises" />
+ <excludeFolder url="file://$MODULE_DIR$/vendor/guzzlehttp/psr7" />
+ <excludeFolder url="file://$MODULE_DIR$/vendor/illuminate/cache" />
+ <excludeFolder url="file://$MODULE_DIR$/vendor/illuminate/collections" />
+ <excludeFolder url="file://$MODULE_DIR$/vendor/illuminate/conditionable" />
+ <excludeFolder url="file://$MODULE_DIR$/vendor/illuminate/contracts" />
+ <excludeFolder url="file://$MODULE_DIR$/vendor/illuminate/macroable" />
+ <excludeFolder url="file://$MODULE_DIR$/vendor/illuminate/support" />
+ <excludeFolder url="file://$MODULE_DIR$/vendor/nesbot/carbon" />
+ <excludeFolder url="file://$MODULE_DIR$/vendor/psr/clock" />
+ <excludeFolder url="file://$MODULE_DIR$/vendor/psr/container" />
+ <excludeFolder url="file://$MODULE_DIR$/vendor/psr/http-client" />
+ <excludeFolder url="file://$MODULE_DIR$/vendor/psr/http-factory" />
+ <excludeFolder url="file://$MODULE_DIR$/vendor/psr/http-message" />
+ <excludeFolder url="file://$MODULE_DIR$/vendor/psr/simple-cache" />
+ <excludeFolder url="file://$MODULE_DIR$/vendor/ralouphie/getallheaders" />
+ <excludeFolder url="file://$MODULE_DIR$/vendor/symfony/deprecation-contracts" />
+ <excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-mbstring" />
+ <excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-php80" />
+ <excludeFolder url="file://$MODULE_DIR$/vendor/symfony/translation" />
+ <excludeFolder url="file://$MODULE_DIR$/vendor/symfony/translation-contracts" />
+ <excludeFolder url="file://$MODULE_DIR$/vendor/voku/portable-ascii" />
+ </content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+ <component name="PhpIncludePathManager">
+ <include_path>
+ <path value="$PROJECT_DIR$/vendor/carbonphp/carbon-doctrine-types" />
+ <path value="$PROJECT_DIR$/vendor/doctrine/inflector" />
+ <path value="$PROJECT_DIR$/vendor/symfony/translation" />
+ <path value="$PROJECT_DIR$/vendor/symfony/polyfill-php80" />
+ <path value="$PROJECT_DIR$/vendor/symfony/translation-contracts" />
+ <path value="$PROJECT_DIR$/vendor/illuminate/support" />
+ <path value="$PROJECT_DIR$/vendor/illuminate/macroable" />
+ <path value="$PROJECT_DIR$/vendor/illuminate/collections" />
+ <path value="$PROJECT_DIR$/vendor/illuminate/cache" />
+ <path value="$PROJECT_DIR$/vendor/illuminate/contracts" />
+ <path value="$PROJECT_DIR$/vendor/illuminate/conditionable" />
+ <path value="$PROJECT_DIR$/vendor/guzzlehttp/guzzle" />
+ <path value="$PROJECT_DIR$/vendor/ralouphie/getallheaders" />
+ <path value="$PROJECT_DIR$/vendor/guzzlehttp/psr7" />
+ <path value="$PROJECT_DIR$/vendor/guzzlehttp/promises" />
+ <path value="$PROJECT_DIR$/vendor/composer" />
+ <path value="$PROJECT_DIR$/vendor/nesbot/carbon" />
+ <path value="$PROJECT_DIR$/vendor/voku/portable-ascii" />
+ <path value="$PROJECT_DIR$/vendor/symfony/polyfill-mbstring" />
+ <path value="$PROJECT_DIR$/vendor/symfony/deprecation-contracts" />
+ <path value="$PROJECT_DIR$/vendor/psr/http-factory" />
+ <path value="$PROJECT_DIR$/vendor/psr/http-client" />
+ <path value="$PROJECT_DIR$/vendor/psr/simple-cache" />
+ <path value="$PROJECT_DIR$/vendor/psr/http-message" />
+ <path value="$PROJECT_DIR$/vendor/psr/container" />
+ <path value="$PROJECT_DIR$/vendor/psr/clock" />
+ </include_path>
+ </component>
+ <component name="PhpProjectSharedConfiguration" php_language_level="7.2" />
+</project>
\ No newline at end of file
return file_get_contents($cacheFile);
}
$res = $this->_translate($text, $toLanguage, $fromLanguage);
- file_put_contents($cacheFile, $res);
+ if ($res) {
+ file_put_contents($cacheFile, $res);
+ }
return $res;
}
protected function _translate($text, $toLanguage, $fromLanguage)
{
- $res = $this->_call('/translate?api-version=3.0&from=' . $fromLanguage . '&to=' . $toLanguage, 'post', [
- 'Content-type' => 'application/json'
- ], json_encode([['Text' => $text]]));
- $data = json_decode($res->getBody(), true);
- return $data[0]['translations'][0]['text'];
+ try {
+ $res = $this->_call('/translate?api-version=3.0&from=' . $fromLanguage . '&to=' . $toLanguage, 'post', [
+ 'Content-type' => 'application/json'
+ ], json_encode([['Text' => $text]]));
+ $data = json_decode($res->getBody(), true);
+ return $data[0]['translations'][0]['text'];
+ } catch (\Exception $e) {
+ if (stristr($e->getMessage(), '429001')) {
+ sleep(60);
+ return $this->_translate($text, $toLanguage, $fromLanguage);
+ }
+ }
+ return false;
}