Implementacja tłumaczenia Google Cloud AI API vs Google Translate dla Laravel

urządzenia elektroniczne, czarno-białe
Spis treści

Dla tych z Was, którzy posiadają strony internetowe oparte na Laravel, zapewnienie dokładnej i naturalnej treści tłumaczenia jest bardzo ważne, aby tłumaczyć swoją stronę internetową i zapewnić dobre doświadczenie użytkownika.

Fortunately, several automatic translation services are available to help developers overcome this challenge, including Google Cloud AI API Translation and Google Translate. Both services offer translation capabilities using machine technology.

W tym artykule omówimy główne różnice między implementacją tłumaczenia Google Cloud AI i Google Translate dla Laravel aplikacji i polecimy najlepsze usługi tłumaczeniowe dla Twojej Laravel strony internetowej.

Czym są tłumaczenia Google Cloud AI API i Google Translate?

Przed przystąpieniem do dyskusji omówimy odpowiednie znaczenia interfejsu API Google Cloud AI i tłumaczeń Google Translate.

Tłumaczenie API Google Cloud AI

Serwer Google Cloud i magazyn w chmurze

Tłumaczenie Google Cloud AI API to zaawansowana usługa automatycznego tłumaczenia dostarczana przez Google Cloud Platform. Usługa ta wykorzystuje najnowsze technologie sztucznej inteligencji (AI) i uczenia maszynowego, aby dostarczać dokładne i naturalne tłumaczenia tekstu, głosu i dokumentów.

Google Cloud AI API Translation uses neural translation models based on deep learning, which allows it to capture language nuances and context better, providing more idiomatic translations that align with actual language usage. Additionally, using Google Cloud AI Translation for up to 500,000 characters is free of charge, while the next 75,000 characters will incur a cost of $20 per million characters. 

Tłumacz Google

Interfejs ustawień tłumaczenia. Opcje ustawień języka.

Tymczasem Google Translate jest długoletnią i szeroko znaną automatyczną usługą tłumaczenia tekstu. Wykorzystuje bardziej tradycyjne statystyczne podejście do tłumaczenia, które generuje tłumaczenia oparte na wzorcach i prawdopodobieństwach wyuczonych z dużych zbiorów danych treningowych.

Chociaż nie jest tak zaawansowany jak Google Cloud AI API Translation pod względem dokładności i obsługi niuansów językowych, Google Translate pozostaje popularnym wyborem ze względu na łatwość użycia i dostępność bezpłatną dla celów niekomercyjnych.

Zaimplementuj translację Google Cloud AI API na Laravel

Several translation services, including Linguise, use AI Translation cloud technology to translate websites.

Laravel Laravel

Utwórz konto Linguise

Aby korzystać z Linguise, musisz zarejestrować konto najpierw. Możesz to zrobić za darmo lub zapisać się na miesiąc lub rok. Musisz podać tylko informacje takie jak Twój adres e-mail, nazwa użytkownika i hasło.

Dodaj informacje o stronie Laravel

Następnie dodaj informacje o stronie internetowej, którą będziesz używać, wprowadź dane konta Linguise i adres URL, wybierz platformę Laravel i dodaj domyślny język oraz język, który chcesz dodać do strony internetowej.

 

Animacja ładowania

Następnie pobierz skrypt PHP za pomocą poniżonego przycisku i zapisz go na komputerze lokalnym.

Prześlij i skonfiguruj skrypt PHP

Po pobraniu skryptu, rozpakuj go i wgraj do folderu głównego, gdzie zainstalowany jest Laravel . Upewnij się, że znajduje się on u podstawy Twojej instalacji Laravel (zwykle tam, gdzie znajdują się pliki Twojego CMS). Upewnij się, że folder jest nazwany „linguise” (domyślna nazwa, gdy folder jest rozpakowany).

Menu nawigacji systemu plików komputera

Następnie klucz API Linguise musi być skopiowany do pliku …/linguise/Configuration.php, który przesłałeś na swój serwer. Edytuj plik i wklej swój klucz API pomiędzy cudzysłowami, zastępując tekst REPLACE_BY_YOUR_TOKEN.

Screenshot of code configuration

Wstaw skrypt przełącznika języka

Następnie wstaw skrypt przełączania języka, który otrzymałeś z Linguise panelu.

Przełącznik skryptów językowych - Implementacja Tłumaczenia Google Cloud AI vs Tłumacz Google dla Laravel

Wstawiono do pliku front.blade.php w katalogu resources/views/layouts/. Oto podgląd wstawionego skryptu.

Terminal window with code output

Skonfiguruj .htaccess

Na koniec, adresy URL oparte na języku muszą być skonfigurowane w pliku .htaccess. Jeśli Twój plik zawiera „RewriteBase /”, po prostu skopiuj i wklej poniższy kod po tej linii.

				
					<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteRule ^(af|sq|am|ar|hy|az|eu|be|bn|bs|bg|ca|ceb|ny|zh-cn|zh-tw|co|hr|cs|da|nl|en|eo|et|tl|fi|fr|fy|gl|ka|de|el|gu|ht|ha|haw|iw|hi|hmn|hu|is|ig|id|ga|it|ja|jw|kn|kk|km|ko|ku|ky|lo|la|lv|lt|lb|mk|mg|ms|ml|mt|mi|mr|mn|my|ne|no|ps|fa|pl|pt|pa|ro|ru|sm|gd|sr|st|sn|sd|si|sk|sl|so|es|su|sw|sv|tg|ta|te|th|tr|uk|ur|uz|vi|cy|xh|yi|yo|zu|zz-zz)(?:$|/)(.*)$ linguise/linguise.php?linguise_language=$1&original_url=$2 [L,QSA]
</IfModule>
				
			

Zrobione. W tym momencie pomyślnie zaimplementowałeś tłumaczenie chmurowe AI API na serwisach Linguise. Teraz możesz sprawdzić Laravel stronę internetową. Przełącznik języka pojawi się domyślnie, a Ty możesz dostosować przełącznik języka dla Laravel

a man with a dark background, mysterious atmosphere

Zaimplementuj Tłumacza Google na Laravel

Teraz postaramy się zaimplementować Tłumacza Google w Laravel. Zakładamy tutaj, że udało Ci się utworzyć projekt Laravel i wystarczy dodać Tłumacza Google.

Laravel

Install Google Translator Package

Aby zainstalować pakiet Tłumacza Google, otwórz wiersz polecenia projektu i wprowadź następujące polecenie. Ten pakiet umożliwi Ci wykorzystanie funkcji roboczych języka tłumacza-google.

				
					composer require stichoza/google-translate-php
				
			

Ustawienia pakietu tłumacza Google

Musimy skonfigurować „pakiet tłumacza google” w aplikacji. Otwórz plik app.php w folderze /config, znajdź sekcję „aliases” i dodaj następujący wiersz kodu.

Terminal komputerowy z kodowaniem tekstu na ekranie. Wyświetlacz pokazuje różne linie kodu.
				
					/*
|--------------------------------------------------------------------------
| Class Aliases
|--------------------------------------------------------------------------
|
| This array of class aliases will be registered when this application
| is started. However, feel free to register as many as you wish as
| the aliases are "lazy" loaded so they don't hinder performance.
|
*/

'aliases' => Facade::defaultAliases()->merge([
    // 'Example' => App\Facades\Example::class,
    'GoogleTranslate' => Stichoza\GoogleTranslate\GoogleTranslate::class,
])->toArray(),

				
			

Konfiguracja kontrolera języka

Musisz utworzyć plik kontrolera języka jak poniżej

				
					php artisan make:controller LangController
				
			

Utworzy plik LangController.php wewnątrz folderu /app/Http/Controllers.

Ekran komputera pokazujący linie kodu
				
					<?php

namespace App\Http\Controllers;

use Illuminate\Contracts\View\View;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\App;

class LangController extends Controller
{
    public function index(): View
    {
        return view('lang');
    }

    public function change(Request $request)
    {
        App::setLocale($request->lang);
        
        session()->put('locale', $request->lang);

        return redirect()->back();
    }
}


				
			

Utwórz plik szablonu Blade

Przejdź do folderu /resources/views i utwórz plik o nazwie lang.blade.php. Otwórz plik i wstaw następujący kod do niego.

Obraz kodu na ekranie komputera. Tekst programowania.
				
					<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Laravel 10 Create Multi Language Website Tutorial</title> <script type="litespeed/javascript" data-src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script type="application/ld+json" class="gnpub-schema-markup-output">{"@context":"https:\/\/schema.org\/","@type":"NewsArticle","@id":"https:\/\/www.linguise.com\/blog\/guide\/implement-google-cloud-ai-api-translation-vs-google-translate-for-laravel\/#newsarticle","url":"https:\/\/www.linguise.com\/blog\/guide\/implement-google-cloud-ai-api-translation-vs-google-translate-for-laravel\/","image":{"@type":"ImageObject","url":"https:\/\/www.linguise.com\/wp-content\/uploads\/2024\/05\/Implement-Google-Cloud-AI-API-translation-vs-Google-Translate-for-Laravel-150x150.png","width":150,"height":150},"headline":"Implement Google Cloud AI API translation vs Google Translate for Laravel","mainEntityOfPage":"https:\/\/www.linguise.com\/blog\/guide\/implement-google-cloud-ai-api-translation-vs-google-translate-for-laravel\/","datePublished":"2024-05-31T07:32:47+00:00","dateModified":"2024-08-26T19:19:15+00:00","description":"For those of you who own Laravel-based websites, providing accurate and natural translation content is very important to translate your website and offer a good","articleSection":"Guide","articleBody":"For those of you who own Laravel-based websites, providing accurate and natural translation content is very important to translate your website and offer a good user experience.\nFortunately, several automatic translation services are available to help developers overcome this challenge, including Google Cloud AI API Translation and Google Translate. Both services offer translation capabilities using machine technology.\nIn this article, we will explore the main differences between implementing Google Cloud AI Translation and Google Translate for Laravel applications and recommend the best translation services for your Laravel website.&nbsp;\t\t\n\t\t\tWhat are Google Cloud AI API translation &amp; Google Translate?\n\t\t\n\t\tBefore entering into the discussion, we will discuss the respective meanings of Google Cloud AI API and Google Translate translations.\t\t\n\t\t\tGoogle Cloud AI API translation\n\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\n\t\tGoogle Cloud AI API Translation is an advanced automatic translation service provided by Google Cloud Platform. This service leverages the latest artificial intelligence (AI) and machine learning technologies to deliver accurate and natural translations of text, voice, and documents.Google Cloud AI API Translation uses neural translation models based on deep learning, which allows it to capture language nuances and context better, providing more idiomatic translations that align with actual language usage. Additionally, using Google Cloud AI Translation for up to 500,000 characters is free of charge, while the next 75,000 characters will incur a cost of $20 per million characters.\u00a0\t\t\n\t\t\tGoogle Translate\n\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\n\t\tMeanwhile, Google Translate is a long-standing and widely known automatic text translation service. It uses a more traditional statistical translation approach, which generates translations based on patterns and probabilities learned from large training datasets.Although it is not as advanced as Google Cloud AI API Translation in terms of accuracy and handling language nuances, Google Translate remains a popular choice due to its ease of use and free availability for non-commercial use.\t\t\n\t\t\tImplement Google Cloud AI API translation on Laravel\n\t\t\n\t\tSeveral translation services, including Linguise, use AI Translation cloud technology to translate websites.The language translation service uses cloud AI API as one of its translation technologies. The following are the implementation steps on the Laravel website. We assume here that you already have a ready Laravel project website.\t\t\n\t\t\tCreate Linguise account\n\t\t\n\t\tTo use Linguise, you must register an account first. You can do this for free or subscribe for one month or a year. You only need to provide information such as your email, username, and password.\t\t\n\t\t\tAdd Laravel website info\n\t\t\n\t\tAfter that, add information about the website you will use, enter your Linguise account info and web URL, select the Laravel platform, and add the default language and the language you want to add to the website.\u00a0\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\n\t\tThen download the PHP script via the following button and save it on your local computer.\t\t\n\t\t\t\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\tDOWNLOAD PHP-JS TRANSLATION SCRIPT\n\t\t\t\t\t\n\t\t\tUpload and configure the PHP script\n\t\t\n\t\tAfter downloading the script, unzip it and upload it to the root folder where Laravel is installed. Ensure it is located at the root of your Laravel installation (typically where your CMS files are). Ensure the folder is named \"linguise\" (the default name when the folder is unzipped).\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\n\t\tThen, the Linguise API key must be copied into the \u2026\/linguise\/Configuration.php file you uploaded to your server. Edit the file and paste your API key between the quotes, replacing the text REPLACE_BY_YOUR_TOKEN.\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\n\t\t\tInsert script of language switcher\t\t\n\t\tNext, insert the language switch script that you got from the Linguise dashboard.\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\n\t\tInserted into the front.blade.php file in the resources\/views\/layouts\/ directory. Here is a preview of the inserted script.\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\n\t\t\tConfigure .htaccess\n\t\t\n\t\tLastly, language-based URLs need to be configured in the .htaccess file. If your file includes \"RewriteBase \/,\" simply copy and paste the following code after that line.\t\t\n\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n  RewriteEngine On\n  RewriteRule ^(af|sq|am|ar|hy|az|eu|be|bn|bs|bg|ca|ceb|ny|zh-cn|zh-tw|co|hr|cs|da|nl|en|eo|et|tl|fi|fr|fy|gl|ka|de|el|gu|ht|ha|haw|iw|hi|hmn|hu|is|ig|id|ga|it|ja|jw|kn|kk|km|ko|ku|ky|lo|la|lv|lt|lb|mk|mg|ms|ml|mt|mi|mr|mn|my|ne|no|ps|fa|pl|pt|pa|ro|ru|sm|gd|sr|st|sn|sd|si|sk|sl|so|es|su|sw|sv|tg|ta|te|th|tr|uk|ur|uz|vi|cy|xh|yi|yo|zu|zz-zz)(?:$|\/)(.*)$ linguise\/linguise.php?linguise_language=$1&original_url=$2 [L,QSA]\n\n\t\t\t\t\n\t\t\t\n\t\tDone. At this point, you have successfully implemented cloud AI API Translation on the Linguise service. Now, you can check the Laravel website. A default language switcher will appear, and you can customize the Language switcher for Laravel via the dashboard.\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\n\t\t\tImplement Google Translate on Laravel\t\t\n\t\tNow we will try to implement Google Translate in Laravel. Here we assume that you have successfully created a Laravel project and just need to add Google Translate.You can also find the following installation steps on the official Laravel website.\t\t\n\t\t\tInstall Google Translator Package\n\t\t\n\t\tTo install the Google Translator Package, open the project prompt and input the following command. This package will enable you to utilize the working functions of the google-translator-language.\t\t\n\t\t\t\n\t\t\t\t\n\t\t\t\t\tcomposer require stichoza\/google-translate-php\n\t\t\t\t\n\t\t\t\n\t\t\tSetting of Google Translator Package\n\t\t\n\t\tWe must set up the \"google translator package\" within the the application. Open the app.php file in the \/config folder, find the \"aliases\" section, and add the following line of code.\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\n\t\t\t\n\t\t\t\t\n\t\t\t\t\t\/*\n|--------------------------------------------------------------------------\n| Class Aliases\n|--------------------------------------------------------------------------\n|\n| This array of class aliases will be registered when this application\n| is started. However, feel free to register as many as you wish as\n| the aliases are \"lazy\" loaded so they don't hinder performance.\n|\n*\/\n'aliases' => Facade::defaultAliases()->merge([\n    \/\/ 'Example' => AppFacadesExample::class,\n    'GoogleTranslate' => StichozaGoogleTranslateGoogleTranslate::class,\n])->toArray(),\n\n\t\t\t\t\n\t\t\t\n\t\t\tSetup Language Controller\n\t\t\n\t\tYou need to create a language controller file like the following\t\t\n\t\t\t\n\t\t\t\t\n\t\t\t\t\tphp artisan make:controller LangController\n\t\t\t\t\n\t\t\t\n\t\tIt will create LangController.php file inside \/app\/Http\/Controllers folder.","keywords":"","name":"Implement Google Cloud AI API translation vs Google Translate for Laravel","thumbnailUrl":"https:\/\/www.linguise.com\/wp-content\/uploads\/2024\/05\/Implement-Google-Cloud-AI-API-translation-vs-Google-Translate-for-Laravel-150x150.png","wordCount":809,"timeRequired":"PT3M35S","mainEntity":{"@type":"WebPage","@id":"https:\/\/www.linguise.com\/blog\/guide\/implement-google-cloud-ai-api-translation-vs-google-translate-for-laravel\/"},"author":{"@type":"Person","name":"Tristan","url":"https:\/\/www.linguise.com\/author\/tristan\/","sameAs":[],"image":{"@type":"ImageObject","url":"https:\/\/secure.gravatar.com\/avatar\/50d7238660b192d8d54ebf6367be5e97bb41c24dbd190daae062d931efd351ae?s=96&d=mm&r=g","height":96,"width":96}},"editor":{"@type":"Person","name":"Tristan","url":"https:\/\/www.linguise.com\/author\/tristan\/","sameAs":[],"image":{"@type":"ImageObject","url":"https:\/\/secure.gravatar.com\/avatar\/50d7238660b192d8d54ebf6367be5e97bb41c24dbd190daae062d931efd351ae?s=96&d=mm&r=g","height":96,"width":96}}}</script> </head>

<body>
    <div class="container mt-5">
        <div class="row">
            <div class="col-md-12">
                <div class="card w-75 m-auto">
                    <div class="card-header text-center bg-primary text-white">
                        <h4 style="font-size: 17px;">Laravel 10 Create Multi Language Website Tutorial</h4>
                    </div>
                    <div class="card-body">
                        <div class="row">
                            <div class="col-md-4">
                                <strong>Select Language: </strong>
                            </div>
                            <div class="col-md-4">
                                <select class="form-select changeLang">
                                    <option value="en" {{ session()->get('locale') == 'en' ? 'selected' : '' }}>
                                        English
                                    </option>
                                    <option value="fr" {{ session()->get('locale') == 'fr' ? 'selected' : '' }}>
                                        French
                                    </option>
                                    <option value="ar" {{ session()->get('locale') == 'ar' ? 'selected' : '' }}>
                                        Arabic
                                    </option>
                                    <option value="hi" {{ session()->get('locale') == 'hi' ? 'selected' : '' }}>
                                        Hindi
                                    </option>
                                </select>
                            </div>
                        </div>

                        <div style="margin-top: 20px;">
                            <p>{{ GoogleTranslate::trans('Welcome to Online Web Tutor', app()->getLocale()) }}</p>
                            <p>{{ GoogleTranslate::trans('It is a passionate and innovative Web Development Community dedicated to empowering aspiring web developers with the latest tools and techniques. Our platform offers a comprehensive range of web development courses, including PHP and its frameworks, Node.js, MySQL, Javascript and WordPress.', app()->getLocale()) }}
                            </p>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

     <script data-no-optimize="1">var litespeed_vary=document.cookie.replace(/(?:(?:^|.*;\s*)_lscache_vary\s*\=\s*([^;]*).*$)|^.*$/,"");litespeed_vary||fetch("/wp-content/plugins/litespeed-cache/guest.vary.php",{method:"POST",cache:"no-cache",redirect:"follow"}).then(e=>e.json()).then(e=>{console.log(e),e.hasOwnProperty("reload")&&"yes"==e.reload&&(sessionStorage.setItem("litespeed_docref",document.referrer),window.location.reload(!0))});</script><script data-optimized="1" type="litespeed/javascript" data-src="https://www.linguise.com/wp-content/litespeed/js/4efcce905aeba23da8ea1c66b8bc70f0.js?ver=0275f"></script><script>window.litespeed_ui_events=window.litespeed_ui_events||["mouseover","click","keydown","wheel","touchmove","touchstart"];var urlCreator=window.URL||window.webkitURL;function litespeed_load_delayed_js_force(){console.log("[LiteSpeed] Start Load JS Delayed"),litespeed_ui_events.forEach(e=>{window.removeEventListener(e,litespeed_load_delayed_js_force,{passive:!0})}),document.querySelectorAll("iframe[data-litespeed-src]").forEach(e=>{e.setAttribute("src",e.getAttribute("data-litespeed-src"))}),"loading"==document.readyState?window.addEventListener("DOMContentLoaded",litespeed_load_delayed_js):litespeed_load_delayed_js()}litespeed_ui_events.forEach(e=>{window.addEventListener(e,litespeed_load_delayed_js_force,{passive:!0})});async function litespeed_load_delayed_js(){let t=[];for(var d in document.querySelectorAll('script[type="litespeed/javascript"]').forEach(e=>{t.push(e)}),t)await new Promise(e=>litespeed_load_one(t[d],e));document.dispatchEvent(new Event("DOMContentLiteSpeedLoaded")),window.dispatchEvent(new Event("DOMContentLiteSpeedLoaded"))}function litespeed_load_one(t,e){console.log("[LiteSpeed] Load ",t);var d=document.createElement("script");d.addEventListener("load",e),d.addEventListener("error",e),t.getAttributeNames().forEach(e=>{"type"!=e&&d.setAttribute("data-src"==e?"src":e,t.getAttribute(e))});let a=!(d.type="text/javascript");!d.src&&t.textContent&&(d.src=litespeed_inline2src(t.textContent),a=!0),t.after(d),t.remove(),a&&e()}function litespeed_inline2src(t){try{var d=urlCreator.createObjectURL(new Blob([t.replace(/^(?:<!--)?(.*?)(?:-->)?$/gm,"$1")],{type:"text/javascript"}))}catch(e){d="data:text/javascript;base64,"+btoa(t.replace(/^(?:<!--)?(.*?)(?:-->)?$/gm,"$1"))}return d}</script></body>

</html>

				
			

Ustawienia pośredniczącego języka

Otwórz terminal projektu i uruchom to polecenie,

				
					php artisan make:middleware LanguageManager


				
			

Utworzy plik LanguageManager.php wewnątrz folderu /app/Http/Middleware i wkleić to.

Czarno-biały pikselowy obraz. Brak widocznych szczegółów.
				
					<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
use Illuminate\Support\Facades\App;

class LanguageManager
{
    /**
     * Handle an incoming request.
     *
     * @param  \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response)  $next
     */
    public function handle(Request $request, Closure $next): Response
    {
        if (session()->has('locale')) {

            App::setLocale(session()->get('locale'));
        }

        return $next($request);
    }
}

				
			

Zarejestruj Middleware języka za pomocą Kernel.php

Otwórz plik Kernel.php znajdujący się w katalogu /app/Http. Poszukaj tablicy $middlewareGroups i przejdź do sekcji web.

Rozmyty obraz tekstu na czarnym tle. Tekst jest nieczytelny.
				
					/**
 * The application's route middleware groups.
 *
 * @var array<string, array<int, class-string|string>>
 */
protected $middlewareGroups = [
    'web' => [
        
        //...

        \App\Http\Middleware\LanguageManager::class,
    ],

    'api' => [
        
        //...
    ],
];

				
			

Dodaj trasę

Otwórz web.php z folderu /routes i dodaj te trasy do niego.

Web.php - Implementacja tłumaczenia Google Cloud AI API vs Tłumaczenie Google dla Laravel
				
					//...
use App\Http\Controllers\LangController;

//...

Route::get('lang/home', [LangController::class, 'index']);
Route::get('lang/change', [LangController::class, 'change'])->name('changeLang');


				
			

Testowanie strony internetowej

Wykonaj to polecenie w terminalu projektu, aby uruchomić serwer deweloperski.

				
					php artisan serve
				
			

Oto wyświetlenie strony Laravel z witryny onlinewebtutorblog.com, która została utworzona, jak widać na poniższym wyświetleniu, znajduje się tam lista rozwijana Tłumacza Google.

Zniekształcony obraz tego, co wydaje się być ekranem komputera.

Wtedy tak wygląda strona Laravel po przetłumaczeniu na język arabski.

Uszkodzony ekran komputera. Wyświetlanie zniekształconego kodu i tekstu.

Jaka jest różnica między implementacją tłumaczenia Google Cloud AI a Google Translate na Laravel?

Po zrozumieniu implementacji Google Cloud AI i tłumaczenia Google Translate w Laravel, omówimy ich różnice.

Proces instalacji i konfiguracji

Ilustracja czarno-biała. Ludzie stojący obok dużego celu.
  • Tłumaczenie Google Cloud AI: Proces instalacji i konfiguracji jest bardziej skomplikowany, ponieważ musisz utworzyć projekt na platformie Google Cloud Platform (GCP), włączyć interfejs API Cloud Translation, utworzyć konto usługi, wygenerować klucze API i skonfigurować klienta API w swojej Laravel aplikacji. Obejmuje to kilka kroków i wymaga ważnego konta GCP.
  • Tłumacz Google: Instalacja i konfiguracja są znacznie prostsze. Wystarczy zainstalować pakiet lub bibliotekę innej firmy za pośrednictwem Composer, np. stichoza/stichoza-google-translate-php. Następnie możesz skonfigurować klucz API Tłumacza Google w pliku konfiguracyjnym Laravel.

Dokładność tłumaczenia

Group of people gathered around a computer.
  • Tłumaczenie Google Cloud AI API: Dzięki swoim możliwościom głębokiego uczenia się, ta usługa może lepiej wychwycić złożone konteksty językowe i niuanse. To pozwala na bardziej dokładne tłumaczenie idiomatycznych wyrażeń, przenośnych fraz i gierek słownych, które są trudne do przetłumaczenia dosłownie.
  • Tłumaczenie Google:

Prędkość odpowiedzi

Rakieta kosmiczna startująca z laptopa i telefonu komórkowego.
  • Tłumaczenie Google Cloud AI API: generalnie szybsze w odpowiadaniu na żądania tłumaczenia, ponieważ korzysta z zoptymalizowanych neuronalnych modeli tłumaczenia maszynowego hostowanych na solidnej infrastrukturze chmurowej Google. Zapewnia to krótsze czasy odpowiedzi, szczególnie w przypadku dłuższych tekstów lub dużych wolumenów tłumaczeń.
  • Tłumacz Google: Może być nieco wolniejszy w odpowiadaniu na żądania tłumaczenia, szczególnie dla dłuższych dokumentów lub tekstów. Dzieje się tak, ponieważ używa bardziej tradycyjnego połączenia statystycznych i neuronowych podejść do tłumaczenia.

Możliwości dostosowania i kontroli

Zniekształcony ekran komputera z efektami glitchy. Obraz wydaje się być uszkodzony.
  • Tłumaczenie Google Cloud AI API: Oferuje więcej opcji dostosowywania i kontroli procesu tłumaczenia, takich jak ustawianie preferencji tłumaczenia, wgrywanie własnych słowników oraz dostęp do interfejsu edytora tłumaczeń na żywo, aby ręcznie edytować wyniki tłumaczenia. Dzięki temu użytkownicy mogą poprawić dokładność tłumaczenia zgodnie ze swoimi potrzebami.
  • Tłumacz Google: Ma bardziej ograniczone możliwości dostosowania i kontroli. Użytkownicy muszą polegać na automatycznych wynikach tłumaczenia bez większej możliwości edycji lub bezpośredniego dostosowania wyników.

Zaawansowane funkcje

Ekran komputera z funkcjami dostępności i filiżanką kawy
  • Tłumaczenie Google Cloud AI API: Technologia tłumaczenia Google Cloud AI ma kilka zaawansowanych funkcji, takich jak glosariusz, wybór modelu i modele AutoML. Dodatkowo, w kontekście tłumaczenia AI w chmurze z Linguise, posiada również zaawansowane funkcje, takie jak wykluczenia tłumaczeń
  • Google Translate: Google Translate installed in Laravel cannot translate audio documents or others. It can only translate text on the website into another language without the ability to edit the translation results.
Przełam bariery językowe
Żegnaj się z barierami językowymi i witaj nieograniczony wzrost! Wypróbuj nasze automatyczne usługi tłumaczeniowe już dziś.

Czynniki, które należy wziąć pod uwagę przy wyborze usługi tłumaczeniowej dla witryny Laravel

Oto kilka kwestii do rozważenia przy wyborze najlepszej usługi tłumaczeniowej dla Twojej strony internetowej.

  • Wysoka dokładność tłumaczenia – Jednym z najważniejszych czynników jest dokładność generowanego tłumaczenia. Jeśli Twoja strona internetowa wymaga bardzo dokładnych tłumaczeń, szczególnie w przypadku złożonej treści i subtelnego języka, to Tłumaczenie Google Cloud AI API może być lepszym wyborem niż Tłumacz Google.
  • Łatwość integracji i konfiguracji — Rozważ instalację i konfigurację usługi tłumaczenia w swojej Laravel aplikacji. Tłumacz Google jest zazwyczaj łatwiejszy w integracji, ponieważ jest dostępny jako pakiet lub biblioteka PHP. Tymczasem Tłumaczenie Google Cloud AI API wymaga bardziej złożonej konfiguracji na platformie Google Cloud.
  • Features and Customization Options – If you need additional features such as a glossary or specialized terminology translation, editor translation results, or other customization options, Google Cloud AI API Translation offers more choices than Google Translate.
  • Szybkość i czas odpowiedzi – W przypadku aplikacji o dużych wolumenach tłumaczeń lub wymagających szybkiej odpowiedzi, Tłumaczenie Google Cloud AI API zazwyczaj reaguje na żądania tłumaczenia szybciej niż Tłumacz Google.
  • Koszt i budżet – Tłumaczenie Google jest dostępne bezpłatnie do użytku niekomercyjnego, podczas gdy Tłumaczenie Google Cloud AI API korzysta z płatnego modelu rozliczeniowego opartego na zużyciu. Rozważ swój budżet i szacowaną objętość tłumaczeń, aby wybrać najbardziej opłacalną usługę.
  • Wsparcie i dokumentacja – Rozważ także dostępną pomoc techniczną i dokumentację dla każdej usługi. Tłumaczenie Google Cloud AI API może mieć bardziej kompleksową dokumentację i wsparcie od Google.

Linguise, najlepsza chmura AI tłumaczenie dla witryny Laravel

Profesjonalne usługi projektowania i rozwoju stron internetowych, optymalizacja SEO

Do tego momentu znasz już względy wyboru usługi tłumaczenia dla Laravel; prawie wszystkie wymienione powyżej czynniki są obecne w usłudze tłumaczenia Linguise .

Linguise tłumaczenia stron internetowych wykorzystująca technologię tłumaczenia AI w chmurze do tworzenia tłumaczeń treści. Usługa ta może być najlepszym rozwiązaniem do tłumaczenia stron internetowych opartych na Laravel. Dlaczego tak jest? Ponieważ Linguise odnosi się do kwestii wymienionych powyżej.

  • Linguise ma doskonałą jakość tłumaczenia. Chociaż ta dokładność różni się w zależności od pary językowej, Linguise może pochwalić się wskaźnikiem dokładności wynoszącym prawie 97%, podobnie jak tłumaczenie ludzkie
  • Linguise jest również zintegrowany z ponad 40 systemami CMS i narzędziami do budowania stron internetowych, a także zintegrowany ze stronami internetowymi opartymi na PHP, takimi jak Laravel
  • Chociaż tłumaczy automatycznie, Linguise ma edytor na żywo, który może być używany do edycji wyników tłumaczenia. W ten sposób tłumaczenie może być dostosowane do preferencji biznesowych.
  • Czas ładowania stron wielojęzycznych jest tylko o 5% dłuższy niż w przypadku stron w oryginalnym języku.
  • Nasza usługa jest dostępna w trzech pakietach w cenie od 15 do 45 dolarów miesięcznie. Chociaż jest to usługa płatna, oferujemy również darmowy okres próbny trwający 30 dni z limitem 600 000 słów, które można przetłumaczyć.
  • Wreszcie, Linguise obsługuje wszystkie formy pomocy dla klientów, w tym artykuły przewodników, dokumentację, wiadomości produktowe, samouczki wideo na YouTube i czat wsparcia 24/7.

Z powyższych punktów, Linguise może być chmurowym rozwiązaniem technologicznym tłumaczenia AI dla Laravel.

Gotowy do eksploracji nowych rynków? Wypróbuj nasze automatyczne usługi tłumaczeniowe za darmo z naszą bezpłatną próbą miesięczną. Nie wymagamy karty kredytowej!

Wnioski

W tym artykule zbadaliśmy główne różnice między wdrażaniem Tłumaczenia API Google Cloud AI a Google Translate dla aplikacji internetowych.

Tłumaczenie Google Cloud AI API wyróżnia się dokładnością i spełnia potrzeby tłumaczeń o wysokiej dokładności. Jednak ta usługa wymaga bardziej złożonej konfiguracji i jest droższa niż Tłumacz Google. Z drugiej strony, Tłumacz Google oferuje łatwość integracji, ale ma ograniczenia w zakresie dokładności i opcji dostosowywania.

Linguise pojawia się jako alternatywna usługa tłumaczeniowa oparta na chmurze AI, kompatybilna ze stronami internetowymi. Z poziomami dokładności niemal dorównującymi tłumaczeniom ludzkim, opcjami edytora tłumaczeń, szybkim czasem ładowania i kompleksową obsługą klienta, Linguise staje się doskonałym rozwiązaniem tłumaczeniowym dla Twojej strony internetowej.

If you want to try Linguise, you can sign up for a free account and enjoy a 30-day trial period with a limit of 600,000 translated words. Visit linguise.com for more information!

Możesz być również zainteresowany/a przeczytaniem

Nie przegap!
Zapisz się do naszego biuletynu

Otrzymuj wiadomości o automatycznym tłumaczeniu witryny, międzynarodowym SEO i nie tylko!

Invalid email address
Wypróbuj. Raz na miesiąc, a możesz zrezygnować w dowolnym momencie.

Nie odchodź bez podania swojego adresu e-mail!

Nie możemy zagwarantować, że wygrasz w loterii, ale możemy obiecać ciekawe wiadomości informacyjne dotyczące tłumaczenia i okazjonalne zniżki.

Nie przegap!
Invalid email address