#wanna use google translate api to make my page different langueges but dunno excactly how

177 messages Β· Page 1 of 1 (latest)

austere helm
#

have a vid for reference but in js and dunno how to implement it to ts

#

This video demonstrates how to use the Google Translate API to quickly and easily translate text between different languages. It explains the basics of the API and shows how to set it up in a few simple steps. It also covers how to use the API to translate text from one language to another, how to detect the source language, and how to format th...

β–Ά Play video
#

so should look something like this

heavy lagoon
#

He says, dat this in je header moet

<div id="google_translate_element"></div> 

And dit needs to zijn aan het end..?

<script type="text/javascript">
function googleTranslateElementInit() {
  new google.translate.TranslateElement(
    {pageLanguage: 'en'},
    'google_translate_element'
  );
} 
</script>
<script type="text/javascript" src="https://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>
#

And, it appears to work

#

Put the translate element in a component that will always be visible ( like probably what you picked, the navigation )

#

You can use any element, and id/classname for it, as long as you change to code accordingly.

#
function googleTranslateElementInit() {
  new google.translate.TranslateElement(
    { pageLanguage: "en" },
     "google_translate_element" // <-- this one here
  );
}
#

The 3rd thing should probably be loaded in your head already.

#

so this one, in the main index.html, or whatever file it is πŸ™‚

<script type="text/javascript" src="https://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>
austere helm
#

but i don t have js using ts im kinda confused πŸ˜…

austere helm
#

@heavy lagoon

heavy lagoon
#

TS === JS πŸ™‚

#

The element itself can be placed anywhere, you might need to place the script (the script tag), before the function hits the page.

austere helm
heavy lagoon
#

if you remove function , it should work

#

cause you're in a class there

austere helm
#

so sort of npm install?

heavy lagoon
#

yeah, just put a // @ts-expect-error

#

no, google is loaded from the external file

austere helm
heavy lagoon
#

ah, right above that function

#
function googleTranslateElementInit() {
// @ts-expect-error
  new google.translate.TranslateElement(
    { pageLanguage: "en" },
     "google_translate_element" // <-- this one here
  );
}
#

or maybe 1 line below

#

^

austere helm
heavy lagoon
#

yay

#

you can remove my other comment πŸ˜› ( // <-- this one here )

heavy lagoon
#

:p

austere helm
#

now i need to show it when ng serve is on

heavy lagoon
#

Does an angular project not have just an index.html ?

austere helm
heavy lagoon
#

kk

austere helm
#

lol without the comment it gives an error with it not

heavy lagoon
#

Yeah, that's the point of the comment πŸ˜›

#

ts-expect-error, so if there IS an error, it will silence it

austere helm
#

but shouldn t the error be fixedthonk

heavy lagoon
#

Not in this case

#

Normally, yeah

#

Also, look

#

If there's NOT an error, the comment itself will error

#

;D

austere helm
heavy lagoon
#

Yeah, well it's really good in a lot of cases

austere helm
#

now need it to display

heavy lagoon
#

Yeah, it might not be allowed in those classes

#

Aren't there JS/TS files ? (not component.ts)

austere helm
#

i got service files

heavy lagoon
#

show me your project structure perhaps

austere helm
heavy lagoon
#

yeah that would work

#

we can also gewoon nederlands praten

#

of needen we then PM'en

austere helm
heavy lagoon
#

er is gewoon een index.html πŸ€¦πŸ»β€β™‚οΈ

#

πŸ˜„

austere helm
#

die staat onderaan klopt

heavy lagoon
#

yeah

#

probeer dit

#
<!doctype html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <title>INFIRFS - Webshop</title>
  <base href="/">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <link rel="icon" type="image/x-icon" href="favicon.ico">
</head>

<body>
  <app-root></app-root>
  <script type="text/javascript">
    function googleTranslateElementInit() {
      new google.translate.TranslateElement(
        {pageLanguage: 'en'},
        'google_translate_element'
      );
    }
    </script>
    <script type="text/javascript" src="https://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>
</body>

</html>
#

Opzich zou deze overal moeten kunnen..

<div id="google_translate_element"></div>
#

Mocht het niet lukken in een van die components, probeer dan ook ff in de index.html, gewoon net boven/onder <app-root> element

austere helm
#

is app-root nog belangrijk?

heavy lagoon
#

Ja, dat is waar de hele zooi op "mount"

#

oh, en je moet er geen 2 maken denk ik

#

;D

austere helm
heavy lagoon
#

xD

#

Dat zou, in theorie, gewoon moeten werken

austere helm
#

en dit kan ik dan gewoon weghalen neem ik aan en wat moet ik doen met het id?

heavy lagoon
#

Ja, haal die maar weer weg

#

behalve dus dat ene elementje

austere helm
heavy lagoon
#

Yes

#

Die moet je plaatsen waar je die knop wilt hebben

#

Dus bv, in de navigatie inddd

austere helm
#

in theorie zou er nu al wat moet verschijnen hoef geen tekstveld etc aan te geven in html toch?

heavy lagoon
#

yeah

#

doe eens de console openen dan in de browser

austere helm
heavy lagoon
#

hm m

austere helm
#

denk dat hij verbinding niet maakt maar geen flauw ideethonk

heavy lagoon
#

hmmhm

#

Check

#

Heb n angular project aangemaakt, werkt meteen

austere helm
heavy lagoon
#

ahahah

#

"Bij mij doet 'ie het gewoon"

#

ahah

austere helm
#
import { Component, OnInit } from '@angular/core';
import { RouterModule } from '@angular/router';

import { CartService } from '../services/cart.service';
import { Product } from '../models/product.model';

@Component({
  selector: 'app-navigation',
  standalone: true,
  imports: [RouterModule],
  templateUrl: './navigation.component.html',
  styleUrl: './navigation.component.scss'
})
export class NavigationComponent implements OnInit {
  public title: string = 'INFIRFS - Webshop';

  public amountOfProducts: number = 0;

  constructor(private cartService: CartService) { }

  ngOnInit() {
    this.cartService.$productInCart.subscribe((products: Product[]) => {
      this.amountOfProducts = products.length;
    })
  }

   googleTranslateElementInit() {
    // @ts-expect-error
      new google.translate.TranslateElement(
        { pageLanguage: "en" },
         "google_translate_element"
      );
    }
}
heavy lagoon
#

right, die googleTranslateElementInit werkt dar niet denk ik

#

wellicht mag het toch ook niet een li element zijn, verander die eens terug naar een div

#

en gewoon in de index.html zou de rest moeten kunnen

#

ala zo

austere helm
#
<!doctype html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <title>INFIRFS - Webshop</title>
  <base href="/">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <link rel="icon" type="image/x-icon" href="favicon.ico">
</head>

<body>
  <app-root></app-root>
  <script type="text/javascript">
    function googleTranslateElementInit() {
      new google.translate.TranslateElement(
        {pageLanguage: 'en'},
        'google_translate_element'
      );
    }
    </script>
    <script type="text/javascript" src="https://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>

</body>

</html>
#

index.html

#

dat is toch hetzelfde?

#

dus dit in nacigation.html

#

index.html

#

navigation.component

heavy lagoon
#

hm ja

#

en als je die div plaatst in index?

#

of laad alleen app-root element

austere helm
austere helm
heavy lagoon
#

nee dat kan zo te zien kloppen

#

bij mij ook niet

austere helm
#

πŸ€·β€β™‚οΈ

heavy lagoon
#

ga eens naar de app-root component

austere helm
heavy lagoon
#

ik denk ./app/app.component'

austere helm
heavy lagoon
#

ja, dan de html denk ik

#

app.component.html

austere helm
heavy lagoon
#

ziet er zo uit ong ```html
<app-navigation></app-navigation>
<div class="container">
<h1>pckenner</h1>
<div id="google_translate_element"></div>
<router-outlet></router-outlet>
</div>

#

yeah

#

klap hem daar eens in

#

zoals ik net gedaan heb

austere helm
#

heb wel goog translate daar maar dat is default?

heavy lagoon
#

xD

austere helm
#

nee it weet het oprecht niet

heavy lagoon
#

ja

#

moet je het ook elke keer compilen dan

#

of is het live-update

austere helm
heavy lagoon
#

hoe run je die localhost dan

austere helm
#

dus hier moet ergens een fout in zitten ig

austere helm
heavy lagoon
#

ok

#

ik zag geen package.json in je zip

austere helm
heavy lagoon
#

kk

austere helm
#

heb geen flauw idee wat er verkeerd is mara hoop het te fixen zodat het project weer een beetje clean isπŸ˜…

heavy lagoon
#

ja

#

maar iedereen kan toch native google translaten ook

#

op pc/telefoon etc

austere helm
heavy lagoon
#

lol

#

ah het is niet je eigen ding zeg maar πŸ˜›

austere helm
heavy lagoon
#

ah echt

austere helm
heavy lagoon
#

ΒΏ

austere helm
#

snap je niet

heavy lagoon
#

ik snap mezelf soms ook niet, scheelt dat weer

austere helm
#

heb alleen geen flauw idde waar de fout zit kan alles trg draaien ig maar moet och gebeuren was te lui om een repo aan te maken

heavy lagoon
#

vscode gebruik je ?

austere helm
#

yep webstorm is meh

heavy lagoon
#

F1 -> initialize git repo

#

;D

#

of Ctrl+Shift+P w/e

austere helm
#

done

heavy lagoon
#

;D

austere helm
#

wil die shitt nog wel fixen wnat wordt echt gek hiervan

heavy lagoon
#

als je je repo up hebt, stuur ff linkje

#

en anders gooi dit dicht dan doe je maar pm'en

austere helm
heavy lagoon
#

ohke

austere helm
#

wil het eigenlijk hierm ee connecten maar doet niks met ssh heb een zware overload error lol

#

hij is nergens mee verbonden

heavy lagoon
#

?

austere helm
#

wil het daarmee verbinden maar git heeft nu geen verbinding met een sitre dus vrij waardeloos