#wanna use google translate api to make my page different langueges but dunno excactly how
177 messages Β· Page 1 of 1 (latest)
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...
so should look something like this
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>
but i don t have js using ts im kinda confused π
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.
where so don t understand only feel confident in java and python lol
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
^
yeah i know XD
:p
now i need to show it when ng serve is on
Does an angular project not have just an index.html ?
noop is a webshop but my backend is broken rn asswell XD
kk
lol without the comment it gives an error with it not
Yeah, that's the point of the comment π
ts-expect-error, so if there IS an error, it will silence it
but shouldn t the error be fixed
Not in this case
Normally, yeah
Also, look
If there's NOT an error, the comment itself will error
;D
annoying injectables lol
Yeah, well it's really good in a lot of cases
now need it to display
Yeah, it might not be allowed in those classes
Aren't there JS/TS files ? (not component.ts)
show me your project structure perhaps
can also sent src in zip if you want that
yeah that would work
we can also gewoon nederlands praten
of needen we then PM'en
i don t mind but then it needs to be private maybe a bit easier for technological terms
die staat onderaan klopt
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
is app-root nog belangrijk?
Ja, dat is waar de hele zooi op "mount"
oh, en je moet er geen 2 maken denk ik
;D
oh lm dacht dat hij weg was
en dit kan ik dan gewoon weghalen neem ik aan en wat moet ik doen met het id?
<li id="gooogle_translate_element"></li> dit is het elementje?
Yes
Die moet je plaatsen waar je die knop wilt hebben
Dus bv, in de navigatie inddd
in theorie zou er nu al wat moet verschijnen hoef geen tekstveld etc aan te geven in html toch?
hm m
denk dat hij verbinding niet maakt maar geen flauw idee
oh oh de het werkt op mijn schermπββοΈ
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"
);
}
}
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
<!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
gebeurd ook niks
zou kunnen geen idee
π€·ββοΈ
ga eens naar de app-root component
ik denk ./app/app.component'
deze?
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
xD
nee it weet het oprecht niet
dat is niet echt het doel van angular ig
hoe run je die localhost dan
dus hier moet ergens een fout in zitten ig
ng serve
is alleen src staat erbuiten anders te groot
kk
heb geen flauw idee wat er verkeerd is mara hoop het te fixen zodat het project weer een beetje clean isπ
ze willen het er gewoon in hebben π€·ββοΈ
het is een schoolproject waar ik aan d bepaalde requierements moet voldoen
ah echt
?
ΒΏ
snap je niet
ik snap mezelf soms ook niet, scheelt dat weer
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
vscode gebruik je ?
yep webstorm is meh
done
;D
wil die shitt nog wel fixen wnat wordt echt gek hiervan
als je je repo up hebt, stuur ff linkje
en anders gooi dit dicht dan doe je maar pm'en
het is private want op de school zijn servers
ohke
wil het eigenlijk hierm ee connecten maar doet niks met ssh heb een zware overload error lol
hij is nergens mee verbonden
?
wil het daarmee verbinden maar git heeft nu geen verbinding met een sitre dus vrij waardeloos