How to call API only when the condition is met ?

Hello. I try to translate a text using Cloud Translate API when user's current languages are neither Japanese nor english, due to concerns about API usage.

However I don't know how to call API only when the condition is met.

[What I want to do]

  • The texts are fetched from Firebase, and texts have two values: Japanese and English.

  • If user's current language is Japanese or English, to set the text from database (Japanese or English).

  • If user's current language is neither Japanese nor English, call the API and return the translated value.

[Problem]

  • API Call which is set for the text field, is called even when the user's language is Japanese or English. ( It incurs a cost.)

  • I try to use custom function for calling the API only when the condition is met, but it seems that I cannot use "async*' methods" in custom function, so it couldn't work.

Is there any way to call API only when the condition is met?

1
7 replies