Categoría
📚
AprendizajeTranscripción
00:00so hi guys uh this is barth and today i'm going to show you how you can actually use the google
00:08cloud translation api with the python code so guys uh let's begin so first of all head up
00:15to your google cloud console and now look up for the translate api you might find cloud translation
00:21api uh go to this section and now you can uh see the manage button which might be written as enable
00:29api if you haven't enabled it yet so now enable this api and now you're ready to go before that you can
00:36actually uh download the credential files for google cloud platform from the iam and admin
00:43section and then go into the service account now you can select the account which has the permissions
00:48for the cloud translation api which by default can be uh the user which is the owner which is
00:56this for me now you can go to the key section and now you can add key and then create a new key which
01:03will prompt you to download the gcp key file now you need to save that in the directory you want working
01:12or any other path so now we can start working on the actual code for google translate api
01:19so the first part uh we need to actually install the requirements which in this case is actually
01:28skip install google cloud translate this is the library which is required to run the translate api
01:36and create the clients for google cloud services all right you can install this api and now we can start
01:43working on the code so the first part is obviously to import uh the translate module from google dot cloud
01:53we can import translate v2 as translate so that is how that is a standard format in which you
02:00import uh the translate module all right so now we can actually create the client which can be used
02:06to learn functions of this uh of this service so now we can create the client by uh creating the translate dot
02:15client and to pass the service key you can actually use the from service account json
02:21uh function and now pass the path of the gcp key we have stored in i've stored the gcp key in
02:28the same directory that's why i've written uh just the name of the gcp key all right so now we can
02:35actually start uh inputting the text we want to translate supposedly i take some text like uh
02:45hello welcome to the google cloud so that's the text i want to uh translate to another language
02:51all right so how we are going to translate is by using the translate function of the client of the
02:57translate client basically which you have created the created above all right so for running this
03:02function we can run the client on translate then we can pass the text as the first parameter and
03:09now the target language is the language to which we are converting the current text so that is in my
03:16case uh french so this uh result should be uh should convert the current text to the uh the text in
03:26in the french language so we can now print results result is a dictionary in which translated text is
03:33the key for the value of the translated text which which has been converted from the client
03:39so we can run this code now which is python
03:45translate.py and they should give us the french conversion for that for our sample text which is bonjour
03:54uh this is written in french so yeah that's how we actually use google translate api
04:00also you can uh use some other functions of google translate api like uh detecting the language
04:07which we can use uh which we can uh actually access by using the detect language function of the client
04:16which is detect language and now we can uh actually enter the text we want to detect the language off
04:24in this case it should be printing english as the uh results so the language is basically stored as
04:33the language in the language key of the dictionary of result so if i run this uh code now
04:39i think i should get en yeah which represents english if i actually uh see what
04:47languages the translated text i can again run the code and now it says fr which represents the french
04:54language so yeah uh basically that's how google translate api works and these were some of the
04:59basic functions google translate api for your python code so yeah guys thank that's it for the video
05:05thank you for watching