Fireship · @fireship
Text Translation with Firebase Cloud Functions onWrite and Angular 4
Uploaded June 25, 2017 · Length 6:00
Summary
Building a text translation feature in Angular 4 using Firebase Cloud Functions and Google Translate API.
- angular 4
- firebase cloud functions
- google translate api
- text translation
- on write callback
- angular firebase
Transcript preview
The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.
- 0:00
in this episode we're going to build a
- 0:02
text translation feature in angular 4
- 0:04
and we're going to do it completely in
- 0:06
the background using firebase cloud
- 0:08
functions and the Google Translate API
- 0:12
this example is going to take a string
- 0:15
of English text and translate it to
- 0:17
French Spanish and Arabic we're able to
- 0:22
make this work using the on write call
- 0:24
back from the firebase database which
- 0:26
will trigger a cloud function that
- 0:28
handles the entire translation process
- 0:30
in other words we're going to build a
- 0:32
micro service specifically for
- 0:34
translation and we're going to trigger
- 0:36
this micro service to run every time new
- 0:38
data is added to the database the first
- 0:43
step is to model the data in this case
- 0:45
we just have a collection of translation
- 0:47
and each translation has a set of key
- 0:51
value pairs where the key is the
- 0:53
language and the value is the translated
- 0:56
text so the user will enter the text in
- 0:59
English and then the cloud function will
- 1:01
write the data at every other language
- 1:03
that we want to translate the first step
- 1:05
is to allow the user to input their tags
- 1:08
to the firebase database so we'll start
- 1:10
building that in a service the service
- 1:14
only needs one function called create
- 1:15
translation it starts by pushing the
- 1:18
user text to the database then it
- 1:20
returns that as an object observable so
- 1:23
we can update these or interface
- 1:24
asynchronously
- 1:27
[Music]
- 1:40
now we can start building the component
- 1:45
first we define a variable for the users
- 1:47
text and then we define another variable
- 1:50
for the current translation which is the
- 1:52
observable returned to us from the
- 1:54
service then we create a handle
- 1:56
translation function that will trigger
- 1:59
the entire process when the user submits


