{"id":10820,"date":"2021-10-26T10:00:00","date_gmt":"2021-10-26T01:00:00","guid":{"rendered":"https:\/\/www.gigas-jp.com\/appnews\/?p=10820"},"modified":"2021-10-25T20:52:54","modified_gmt":"2021-10-25T11:52:54","slug":"laravel-package-to-translate-with-deepl-api","status":"publish","type":"post","link":"https:\/\/www.gigas-jp.com\/appnews\/archives\/10820","title":{"rendered":"Laravel Package to translate with a translation API"},"content":{"rendered":"\n<p><font><font>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<\/font><\/font><font><font> <\/font><\/font><font><font> <font>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<\/font> <font>locall<font>y.<\/font> <\/font> <\/font><\/font> <\/p>\n\n\n\n<h4>Methods that can be used<\/h4>\n\n\n\n<p><font>After creating Translat<\/font><font>i<\/font><font>o<\/font><font>n<\/font><font> Object,\u3000you can use the following methods<\/font><font>.<\/font><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$obj = new Translate();<\/code><\/pre>\n\n\n\n<h4><font>T<\/font><font>r<\/font><font>a<\/font><font>n<\/font><font><font>s<\/font><font>l<\/font><font>a<\/font><font>t<\/font><\/font><font>i<\/font><font>o<\/font>n<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>$translated_text = $obj-&gt;translate('Hello World\", 'EN', 'JA'); \n\necho $translated_text;\n<\/code><\/pre>\n\n\n\n<h4><font><font>G<\/font><font>e<\/font><font>t<\/font><font>t<\/font><font>i<\/font><font>n<\/font><font>g<\/font> <font>s<\/font><font>u<\/font><font>p<\/font><font>p<\/font><font>o<\/font><font>r<\/font><font>t<\/font><font>e<\/font><font>d<\/font><font> l<\/font><font>a<\/font><font>n<\/font><font>g<\/font><font>u<\/font><font>a<\/font><font>g<\/font><font>e<\/font><font>s<\/font><\/font><font><\/font><\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>$languages = $obj-&gt;languages();\n\nforeach($languages as $lang){\n    echo $lang&#091;'language'].\"-\".$lang&#091;'name'].'&lt;br&gt;';\n}\n<\/code><\/pre>\n\n\n\n<h4><font><font>G<\/font><font>e<\/font><\/font><font><font>t<\/font><font>t<\/font><\/font><font><font>i<\/font><font>n<\/font><\/font><font><font>g<\/font> <font> s<\/font><\/font><font>u<\/font><font>p<\/font><font>p<\/font><font>o<\/font><font>r<\/font><font>t<\/font><font>e<\/font><font>d<\/font><font> <\/font><font>s<\/font><font>o<\/font><font>u<\/font><font>r<\/font><font>c<\/font><font>e<\/font><font>&#8211;<\/font><font>l<\/font><font>a<\/font><font>n<\/font><font>g<\/font><font>u<\/font><font>a<\/font><font>g<\/font><font>e<\/font>s<font><\/font><\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>$source_languages = $obj-&gt;languages('source');\n\nforeach($source_languages as $lang){\n    echo $lang&#091;'language'].\"-\".$lang&#091;'name'].'&lt;br&gt;';\n}\n<\/code><\/pre>\n\n\n\n<h4><font>G<\/font><font><font>e<\/font><font>t<\/font><\/font><font><font>t<\/font><font>i<\/font><\/font><font>n<\/font><font><font>g<\/font> <\/font><font>s<\/font><font>u<\/font><font>p<\/font><font>p<\/font><font>o<\/font><font>r<\/font><font>t<\/font><font>e<\/font><font>d<\/font><font> <\/font><font>t<\/font><font>a<\/font><font>r<\/font><font>g<\/font><font>e<\/font><font>t<\/font><font>&#8211;<\/font><font>l<\/font><font>a<\/font><font>n<\/font><font>g<\/font><font>u<\/font><font>a<\/font><font>g<\/font><font>e<\/font>s<font><\/font><\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>$target_languages = $obj-&gt;languages('target');\n\nforeach($target_languages as $lang){\n    echo $lang&#091;'language'].\"-\".$lang&#091;'name'].'&lt;br&gt;';\n}\n<\/code><\/pre>\n\n\n\n<h4><font>Y<\/font><font>o<\/font><font>u<\/font><font> <\/font><font>c<\/font><font>a<\/font><font>n<\/font><font> <\/font><font>m<\/font><font>o<\/font><font>n<\/font><font>i<\/font><font>t<\/font><font>o<\/font><font>r<\/font><font> <\/font><font>y<\/font><font>o<\/font><font>u<\/font><font>r<\/font><font> <\/font><font>u<\/font><font>s<\/font><font>a<\/font><font>g<\/font><font>e<\/font><font> <\/font><font>o<\/font><font>f<\/font><font> <\/font><font>t<\/font><font>r<\/font><font>a<\/font><font>n<\/font><font>s<\/font><font>l<\/font><font>a<\/font><font>t<\/font><font>i<\/font><font>o<\/font><font>n<\/font><font> <\/font><font>A<\/font><font>P<\/font>I<font><\/font><\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>$usage= $obj-&gt;usage();\n\necho $usage&#091;'character_count'].' characters have been used. Maximum number of characters that can be translated in the current billing period are '.$usage&#091;'character_limit'];\n<\/code><\/pre>\n\n\n\n<h4><font>Y<\/font><font>o<\/font><font>u<\/font><font> <\/font><font>c<\/font><font>a<\/font><font>n<\/font><font> <\/font><font>s<\/font><font>e<\/font><font>t<\/font><font>u<\/font><font>p<\/font><font> <\/font><font>a<\/font><font> <\/font><font>t<\/font><font>i<\/font><font>m<\/font><font>e<\/font><font>o<\/font><font>u<\/font><font>t<\/font><font> <\/font><font>i<\/font><font>n<\/font><font> <\/font><font>r<\/font><font>e<\/font><font>q<\/font><font>u<\/font><font>e<\/font><font>s<\/font><font>t<\/font><font>i<\/font><font>n<\/font><font>g<\/font><font> <\/font><font>a<\/font><font>p<\/font>i<font><\/font><\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>$obj-&gt;setTimeout(10);\n<\/code><\/pre>\n\n\n\n<p><font><\/p>\n\n\n\n<p><font>Hope you enjoyed that<\/font>.<\/p>\n\n\n\n<p><font>B<\/font><font>y<\/font><font> <\/font><font>A<\/font><font>s<\/font><font>a<\/font><font>h<\/font>i<font><font><\/font><\/p>\n\n\n\n<h4><font><\/h4>\n\n\n\n<p><font><\/p>\n<div class='wp_social_bookmarking_light'>\n            <div class=\"wsbl_google_plus_one\"><g:plusone size=\"medium\" annotation=\"none\" href=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/10820\" ><\/g:plusone><\/div>\n            <div class=\"wsbl_hatena_button\"><a href=\"\/\/b.hatena.ne.jp\/entry\/https:\/\/www.gigas-jp.com\/appnews\/archives\/10820\" class=\"hatena-bookmark-button\" data-hatena-bookmark-title=\"Laravel Package to translate with a translation API\" data-hatena-bookmark-layout=\"standard\" title=\"\u3053\u306e\u30a8\u30f3\u30c8\u30ea\u30fc\u3092\u306f\u3066\u306a\u30d6\u30c3\u30af\u30de\u30fc\u30af\u306b\u8ffd\u52a0\"> <img src=\"\/\/b.hatena.ne.jp\/images\/entry-button\/button-only@2x.png\" alt=\"\u3053\u306e\u30a8\u30f3\u30c8\u30ea\u30fc\u3092\u306f\u3066\u306a\u30d6\u30c3\u30af\u30de\u30fc\u30af\u306b\u8ffd\u52a0\" width=\"20\" height=\"20\" style=\"border: none;\" \/><\/a><script type=\"text\/javascript\" src=\"\/\/b.hatena.ne.jp\/js\/bookmark_button.js\" charset=\"utf-8\" async=\"async\"><\/script><\/div>\n            <div class=\"wsbl_twitter\"><a href=\"https:\/\/twitter.com\/share\" class=\"twitter-share-button\" data-url=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/10820\" data-text=\"Laravel Package to translate with a translation API\" data-via=\"GIGASJAPAN_APPS\" data-lang=\"ja\">Tweet<\/a><\/div>\n            <div class=\"wsbl_facebook_like\"><div id=\"fb-root\"><\/div><fb:like href=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/10820\" layout=\"button_count\" action=\"like\" width=\"100\" share=\"false\" show_faces=\"false\" ><\/fb:like><\/div>\n            <div class=\"wsbl_facebook_send\"><div id=\"fb-root\"><\/div><fb:send href=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/10820\" colorscheme=\"light\" ><\/fb:send><\/div>\n    <\/div>\n<br class='wp_social_bookmarking_light_clear' \/>\n","protected":false},"excerpt":{"rendered":"<p>Today I would like to share about a laravel package that I wrote recently. That package is to translate langua [&hellip;]<\/p>\n","protected":false},"author":20,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1,100],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts\/10820"}],"collection":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/users\/20"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/comments?post=10820"}],"version-history":[{"count":16,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts\/10820\/revisions"}],"predecessor-version":[{"id":10842,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts\/10820\/revisions\/10842"}],"wp:attachment":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/media?parent=10820"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/categories?post=10820"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/tags?post=10820"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}