Android的本地化/国际化的数据库。意表android_metadata这个? [英] Android l10n / i18n database. Is the table android_metadata intended for this?

查看:361
本文介绍了Android的本地化/国际化的数据库。意表android_metadata这个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用下面的教程pviously创建的数据库的$ P $:

http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/

我计划使用的数据库,用于存储为琐事类游戏的问题。随着一个表的基本设计:

  CREATE TABLE问题(
 回答文本,--text的答案
 create_by_user数字的,--boolean标志,真要是问题由用户创建
 _id INTEGER PRIMARY KEY,搭载Android --required
 本地化文本,--ISO 3个字母的code本地化
 问题文本--text的问题
);
 

和使用领域的本地化版本的本地化/国际化的目的,但我不知道如何Android使用 android_metadata 表。在本教程中连续用EN_US值插入,

  1. 在这张桌子一种内置的用于Android的本地化?
  2. 这将是明智的使用表android_metadata的本地化,而不是我自己的本地化领域?
  3. 如果我想在数据库存储不同语言的数据,并给选项给用户检索不同语言的问题?
  4. 我是否需要或者是它最好有每种语言一个数据库?
解决方案

Android的每次打开数据库的当前默认语言环境时更新的领域。这应该是系统的语言,除非您更改默认在您的应用程序。

<一个href="http://grep$c$c.com/file/repository.grep$c$c.com/java/ext/com.google.android/android/4.0.3_r1/android/database/sqlite/SQLiteDatabase.java#1012"相对=nofollow> SQLiteDatabase#的openDatabase

  db.setLocale(Locale.getDefault());
 

应该保存到​​使用现场,但我从来没有测试过。

这表的目的是AFAIK,让您可以使用<一个href="http://stackoverflow.com/questions/3480999/using-collate-in-android-sqlite-locales-is-ignored-in-like-statement">COLLATE属地化在你的陈述 - 与否如果指定<一个href="http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html#NO_LOCALIZED_COLLATORS"相对=nofollow> NO_LOCALIZED_COLLATORS

如果你想在不同的语言文本的数据库,然后再考虑使用自己的语言表,也许国外关键看你的文字表。

I am trying to use a previously created database following the tutorial:

http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/

I plan to use the database for storing questions for a trivia-like game. With the basic design of one table:

CREATE TABLE QUESTIONS (
 answer TEXT,             --text for answer
 create_by_user NUMERIC,  --boolean flag, true if question created by user
 _id INTEGER PRIMARY KEY, --required by Android
 l10n TEXT,               --ISO 3-letter code for localization
 question TEXT            --text for question
);

And using the field l10n for l10n/i18n purposes, but I am not sure about how Android uses android_metadata table. In the tutorial a row with "en_US" value is inserted,

  1. Is this table a sort of built-in l10n used by Android?
  2. It would be advisable to use the table android_metadata for l10n instead of my own l10n field?
  3. What if I want the database to store different languages data and to give the option to the user to retrieve questions from different languages?
  4. Do I need or is it better to have one database per language?

解决方案

Android updates that field each time you open the database to the current default locale. That should be the system language unless you change the default in your app.

SQLiteDatabase#openDatabase

db.setLocale(Locale.getDefault());

It should be save to use that field but I have never tested it.

The purpose of that table is AFAIK to allow you to use COLLATE LOCALIZED in your statements - or not if you specify NO_LOCALIZED_COLLATORS

If you want to have a database of texts in different languages then consider using your own table of languages maybe as foreign key to you text table.

这篇关于Android的本地化/国际化的数据库。意表android_metadata这个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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