Reputation: 1883
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 :)
Upvotes: 8
Views: 5863
Reputation: 1079
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
});
Upvotes: 7