Translation
TranslationGoogle Translate

Google Translate

Inject the Google Translate API as a translation provider into directive @strTranslate, to translate a field value to over 190 languages.

Description

Make Google Translate's API available as a translation provider in directive @strTranslate.

Add directive @strTranslate to any field of type String, to translate it to the desired language.

For instance, this query translates the post's title and content fields from English to French using the Google Translate API:

{
  posts {
    title @strTranslate(
      from: "en",
      to: "fr",
      provider: google_translate
    )
    
    content @strTranslate(
      from: "en",
      to: "fr",
      provider: google_translate
    )
  }
}

List of languages

You can translate your content to any of the following languages:

CodeLanguage
abAbkhaz
aceAcehnese
achAcholi
afAfrikaans
sqAlbanian
alzAlur
amAmharic
arArabic
hyArmenian
asAssamese
awaAwadhi
ayAymara
azAzerbaijani
banBalinese
bmBambara
baBashkir
euBasque
btxBatak Karo
btsBatak Simalungun
bbcBatak Toba
beBelarusian
bemBemba
bnBengali
bewBetawi
bhoBhojpuri
bikBikol
bsBosnian
brBreton
bgBulgarian
buaBuryat
yueCantonese
caCatalan
cebCebuano
nyChichewa (Nyanja)
zhChinese (Simplified)
zh-CNChinese (Simplified)
zh-TWChinese (Traditional)
cvChuvash
coCorsican
crhCrimean Tatar
hrCroatian
csCzech
daDanish
dinDinka
dvDivehi
doiDogri
dovDombe
nlDutch
dzDzongkha
enEnglish
eoEsperanto
etEstonian
eeEwe
fjFijian
filFilipino (Tagalog)
tlFilipino (Tagalog)
fiFinnish
frFrench
fr-FRFrench (French)
fr-CAFrench (Canadian)
fyFrisian
ffFulfulde
gaaGa
glGalician
lgGanda (Luganda)
kaGeorgian
deGerman
elGreek
gnGuarani
guGujarati
htHaitian Creole
cnhHakha Chin
haHausa
hawHawaiian
iwHebrew
heHebrew
hilHiligaynon
hiHindi
hmnHmong
huHungarian
hrxHunsrik
isIcelandic
igIgbo
iloIloko
idIndonesian
gaIrish
itItalian
jaJapanese
jwJavanese
jvJavanese
knKannada
pamKapampangan
kkKazakh
kmKhmer
cggKiga
rwKinyarwanda
ktuKituba
gomKonkani
koKorean
kriKrio
kuKurdish (Kurmanji)
ckbKurdish (Sorani)
kyKyrgyz
loLao
ltgLatgalian
laLatin
lvLatvian
lijLigurian
liLimburgan
lnLingala
ltLithuanian
lmoLombard
luoLuo
lbLuxembourgish
mkMacedonian
maiMaithili
makMakassar
mgMalagasy
msMalay
ms-ArabMalay (Jawi)
mlMalayalam
mtMaltese
miMaori
mrMarathi
chmMeadow Mari
mni-MteiMeiteilon (Manipuri)
minMinang
lusMizo
mnMongolian
myMyanmar (Burmese)
nrNdebele (South)
newNepalbhasa (Newari)
neNepali
nsoNorthern Sotho (Sepedi)
noNorwegian
nusNuer
ocOccitan
orOdia (Oriya)
omOromo
pagPangasinan
papPapiamento
psPashto
faPersian
plPolish
ptPortuguese
pt-PTPortuguese (Portugal)
pt-BRPortuguese (Brazil)
paPunjabi
pa-ArabPunjabi (Shahmukhi)
quQuechua
romRomani
roRomanian
rnRundi
ruRussian
smSamoan
sgSango
saSanskrit
gdScots Gaelic
srSerbian
stSesotho
crsSeychellois Creole
shnShan
snShona
scnSicilian
szlSilesian
sdSindhi
siSinhala (Sinhalese)
skSlovak
slSlovenian
soSomali
esSpanish
suSundanese
swSwahili
ssSwati
svSwedish
tgTajik
taTamil
ttTatar
teTelugu
tetTetum
thThai
tiTigrinya
tsTsonga
tnTswana
trTurkish
tkTurkmen
akTwi (Akan)
ukUkrainian
urUrdu
ugUyghur
uzUzbek
viVietnamese
cyWelsh
xhXhosa
yiYiddish
yoYoruba
yuaYucatec Maya
zuZulu

Google Translate API Configuration

In order to use Google Translate, it is mandatory to provide the API key, via tab "Plugin Management => Google Translate API" on the Settings page.

Create the API key in Google Cloud Platform, following the instructions here.

Then follow one of the methods below to input the value.

By Settings

Input the API key in the corresponding input in the Settings page, and click on "Save Changes (All)":

Setting Google Translate's API key
Setting Google Translate's API key

In wp-config.php

Add constant GATOGRAPHQL_GOOGLE_TRANSLATE_API_KEY in wp-config.php:

define( 'GATOGRAPHQL_GOOGLE_TRANSLATE_API_KEY', 'your API key' );

By environment variable

Define environment variable GOOGLE_TRANSLATE_API_KEY.

Prev