Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase database and app localization

I am building a quiz game for both iOS & Android platforms and I want to be able to handle localization.

I am using Firebase's realtime database solution in order to pull all of the question the game is going to have. I am hardcoding the questions into the Firebase's database and every question object has 2 parameters:

ID - Obviously

Text - The question text itself e.g. "Who was John Kennedy?"

I am having hard time thinking about how to localize the questions I am pulling from Firebase. Obviously if the app is localized as Spanish I want to get the questions text translated to Spanish.

How do I go about it?

Thank you very very much :)

like image 268
Erez Hod Avatar asked Jun 07 '16 11:06

Erez Hod


People also ask

Does Firebase track location?

By the end of this tutorial, you'll be able to: Track individual driver's location, with their permission, using HTML5 Geolocation API after logging into the app. Store authenticated driver's location data to the Cloud Firestore as the location changes.

Can I change database location in Firebase?

After you set your project's default GCP resource location, you cannot change it. If you set up Cloud Firestore or Cloud Storage, you're prompted to select your project's default GCP resource location in the Firebase console workflow.

Can two apps use the same Firebase database?

Yes, You can use the same firebase database in more than one android application as below: In the Project Overview section of Firebase Console add an android application. For adding this application first you need to give that package name.

Can Firebase store HashMap?

By using the updateChildren() method of the database reference class, we can write the HashMap data structure into Firebase Realtime Database.


1 Answers

Database like this...

{
  "en": { "Q1": "Who was JFK?"    },
  "es": { "Q1": "¿Quién era JFK?" }
}

Accessed like this (JavaScript)...

var locale = fooLocale() || 'en'; // get locale, fallback to English
var firedb = firebase.database(); // init database
var content = firedb.ref(locale); // get reference to locale data

content.child('Q1').on('value', function (snapshot) {       // request Q1
  document.getElementById('Q1').innerHTML = snapshot.val(); // set UI text
});
like image 104
Webveloper Avatar answered Oct 18 '22 00:10

Webveloper