{"id":260231,"date":"2015-06-26T23:58:02","date_gmt":"2015-06-26T19:58:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=260231"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=260231","title":{"rendered":"\u042f\u043d\u0434\u0435\u043a\u0441-\u041f\u0435\u0440\u0435\u0432\u043e\u0434 \u0432 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b\u0435 \u0447\u0435\u0440\u0435\u0437 Java"},"content":{"rendered":"<p>     \t\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f API \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0447\u0438\u043a\u0430 \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u0434\u043b\u044f \u0441\u0435\u0431\u044f \u043f\u0440\u043e\u0441\u0442\u0443\u044e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0430 \u0441\u043b\u043e\u0432 \u0438 \u0444\u0440\u0430\u0437, \u0438 \u0447\u0442\u043e\u0431\u044b \u0438\u0437 \u043b\u044e\u0431\u043e\u0433\u043e \u043c\u0435\u0441\u0442\u0430 \u0440\u0430\u0431\u043e\u0442\u0430\u043b\u043e. \u0425\u043e\u0442\u0435\u043b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c curl, \u043d\u043e \u043d\u0435\u043f\u043e\u043d\u044f\u0442\u043d\u043e \u043f\u043e\u0447\u0435\u043c\u0443 \u043f\u043e\u043b\u0443\u0447\u0430\u043b \u043e\u0448\u0438\u0431\u043a\u0443 \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0433\u043e \u044f\u0437\u044b\u043a\u0430 \u043d\u0435\u0442.<\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0432\u043c\u0435\u0441\u0442\u043e \u0441\u043a\u0443\u0447\u043d\u043e\u0433\u043e, \u0430 \u0438\u043d\u043e\u0433\u0434\u0430 \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u043e\u0433\u043e, \u0430 \u0438\u043d\u043e\u0433\u0434\u0430 \u0442\u0430\u043a\u043e\u0433\u043e \u044f\u0440\u043a\u043e-\u0431\u0435\u043b\u043e\u0433\u043e \u043d\u043e\u0432\u043e\u0433\u043e \u0442\u0430\u0431\u0430 \u0441 \u043b\u0438\u0448\u043d\u0435\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0435\u0439 \u043f\u0438\u0448\u0443 \u0432 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b\u0435 <i>trans hello<\/i> \u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u044e \u043f\u0435\u0440\u0435\u0432\u043e\u0434 \u043d\u0430 \u0440\u0443\u0441\u0441\u043a\u0438\u0439, \u0430 \u0435\u0441\u043b\u0438 <i>trans \u043f\u0440\u0438\u0432\u0435\u0442<\/i> \u2014 \u043d\u0430 \u0430\u043d\u0433\u043b\u0438\u0439\u0441\u043a\u0438\u0439. \u0420\u0430\u0437\u0443\u043c\u0435\u0435\u0442\u0441\u044f \u043c\u043e\u0436\u043d\u043e \u0432\u0432\u043e\u0434\u0438\u0442\u044c \u0438 \u0444\u0440\u0430\u0437\u044b, \u0432 \u043a\u0430\u0432\u044b\u0447\u043a\u0430\u0445. \u0420\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0431\u044b\u0441\u0442\u0440\u0435\u043d\u044c\u043a\u043e.<br \/>  <a name=\"habracut\"><\/a>   <\/p>\n<pre><code class=\"java\">import java.io.IOException; import java.io.InputStream; import java.net.URL; import java.net.URLConnection;  public class YandexTranslate {     public static void main(String[] args) throws IOException {         System.out.println(translate(&quot;ru&quot;, args[0]));     }      private static String translate(String lang, String enteredText) throws IOException {         String textEscaped = enteredText.replace(&quot; &quot;, &quot;%20&quot;);         String url = &quot;https:\/\/translate.yandex.net\/api\/v1.5\/tr.json\/translate?key=trnsl.1.1.20150402T173446Z.82a90fe78ca2aeaf.a3bd7c7a0f72b260e28f5d92e4f242cf6ba189d3&lang=&quot;                 + lang + &quot;&text=&quot; + textEscaped;         URLConnection connection = null;         try {             connection = new URL(url).openConnection();         } catch (ArrayIndexOutOfBoundsException e) {             System.out.printf(&quot;No text for translate&quot;);         }         InputStream response = connection.getInputStream();         String json = new java.util.Scanner(response).nextLine();         int start = json.indexOf(&quot;[&quot;);         int end = json.indexOf(&quot;]&quot;);         String translated = json.substring(start + 2, end - 1);         if (translated.equals(enteredText)) { \t    \/\/ if return equal of entered text - we need change direction of translation             return translate(&quot;en&quot;, enteredText);         } else return translated;     } } <\/code><\/pre>\n<p>  \u0427\u0442\u043e\u0431\u044b \u043f\u0435\u0440\u0435\u0432\u043e\u0434 \u0440\u0430\u0431\u043e\u0442\u0430\u043b \u0432 \u043b\u044e\u0431\u043e\u0439 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438, \u043d\u0443\u0436\u043d\u043e \u0432 <i>\/usr\/bin<\/i> \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u044c .class-\u0444\u0430\u0439\u043b \u0438 <i>trans.sh<\/i> \u0434\u043b\u044f \u0435\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430:  <\/p>\n<pre><code class=\"bash\">#!\/bin\/bash #!\/bin\/bash if [ $# -eq 0 ]   then     echo &quot;Enter text for translate&quot;     exit 1; fi java -classpath \/usr\/bin\/ YandexTranslate &quot;$1&quot; <\/code><\/pre>\n<p>  \u0418 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u044b\u043c: <b>sudo chmod +x trans.sh<\/b><\/p>\n<p>  \u0415\u0441\u043b\u0438 \u0447\u0442\u043e \u2014 <a href=\"https:\/\/github.com\/vitaly-zdanevich\/yandex-translate-cli-bash-java\">\u043e\u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u043d\u043e \u043d\u0430 \u0413\u0438\u0442\u0445\u0430\u0431\u0435<\/a>.     \t<\/p>\n<div class=\"clear\"><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/261259\/\"> http:\/\/habrahabr.ru\/post\/261259\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>     \t\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f API \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0447\u0438\u043a\u0430 \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u0434\u043b\u044f \u0441\u0435\u0431\u044f \u043f\u0440\u043e\u0441\u0442\u0443\u044e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0430 \u0441\u043b\u043e\u0432 \u0438 \u0444\u0440\u0430\u0437, \u0438 \u0447\u0442\u043e\u0431\u044b \u0438\u0437 \u043b\u044e\u0431\u043e\u0433\u043e \u043c\u0435\u0441\u0442\u0430 \u0440\u0430\u0431\u043e\u0442\u0430\u043b\u043e. \u0425\u043e\u0442\u0435\u043b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c curl, \u043d\u043e \u043d\u0435\u043f\u043e\u043d\u044f\u0442\u043d\u043e \u043f\u043e\u0447\u0435\u043c\u0443 \u043f\u043e\u043b\u0443\u0447\u0430\u043b \u043e\u0448\u0438\u0431\u043a\u0443 \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0433\u043e \u044f\u0437\u044b\u043a\u0430 \u043d\u0435\u0442.<\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0432\u043c\u0435\u0441\u0442\u043e \u0441\u043a\u0443\u0447\u043d\u043e\u0433\u043e, \u0430 \u0438\u043d\u043e\u0433\u0434\u0430 \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u043e\u0433\u043e, \u0430 \u0438\u043d\u043e\u0433\u0434\u0430 \u0442\u0430\u043a\u043e\u0433\u043e \u044f\u0440\u043a\u043e-\u0431\u0435\u043b\u043e\u0433\u043e \u043d\u043e\u0432\u043e\u0433\u043e \u0442\u0430\u0431\u0430 \u0441 \u043b\u0438\u0448\u043d\u0435\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0435\u0439 \u043f\u0438\u0448\u0443 \u0432 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b\u0435 <i>trans hello<\/i> \u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u044e \u043f\u0435\u0440\u0435\u0432\u043e\u0434 \u043d\u0430 \u0440\u0443\u0441\u0441\u043a\u0438\u0439, \u0430 \u0435\u0441\u043b\u0438 <i>trans \u043f\u0440\u0438\u0432\u0435\u0442<\/i> \u2014 \u043d\u0430 \u0430\u043d\u0433\u043b\u0438\u0439\u0441\u043a\u0438\u0439. \u0420\u0430\u0437\u0443\u043c\u0435\u0435\u0442\u0441\u044f \u043c\u043e\u0436\u043d\u043e \u0432\u0432\u043e\u0434\u0438\u0442\u044c \u0438 \u0444\u0440\u0430\u0437\u044b, \u0432 \u043a\u0430\u0432\u044b\u0447\u043a\u0430\u0445. \u0420\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0431\u044b\u0441\u0442\u0440\u0435\u043d\u044c\u043a\u043e.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-260231","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/260231","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=260231"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/260231\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=260231"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=260231"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=260231"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}