Firebase数据库和应用程序本地化 [英] Firebase database and app localization

查看:75
本文介绍了Firebase数据库和应用程序本地化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为iOS& Android平台,我希望能够处理本地化.

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

我正在使用Firebase的实时数据库解决方案,以解决游戏将要遇到的所有问题. 我将问题硬编码到Firebase的数据库中,每个问题对象都有2个参数:

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 -显然

文本-问题文本本身,例如谁是约翰·肯尼迪?"

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

我很难思考如何本地化我从Firebase提出的问题.显然,如果该应用程序本地化为西班牙语,我想将问题文本翻译为西班牙语.

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.

我该怎么办?

非常感谢:)

推荐答案

像这样的数据库...

Database like this...

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

像这样访问(JavaScript)...

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
});

这篇关于Firebase数据库和应用程序本地化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆