在Android的不同语言使用大的文本文件 [英] Using large text files in different languages in Android

查看:166
本文介绍了在Android的不同语言使用大的文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在应用我建,我使用多种语言。这很容易通过添加新的文件夹(例如:值-FR),以添加不同的语言转换成一个应用程序,并在那里加入了新的strings.xml文件。但我有pretty大的文本文件(完整的文章),我需要补充。这些文章也写在不同的语言。是什么将它们添加到我的应用程序的最佳方式?

In the app I'm building, I'm using multiple languages. It's easy to add a different language into an app by adding a new folder (for example: values-fr) and adding a new strings.xml file in there. But I have pretty large text files (complete articles) that I need to add. These articles are also written in different languages. What is the best way to add them to my app?

推荐答案

我会考虑使用 RES / raw-<预选赛> 作为替代资产。在原材料文件夹可以存储任意文件在他们 - 你猜对了 - 原始形式。例如,你好世界的文章写的法语和英语,将根据存储:

I'd consider using res/raw-<qualifiers> as alternative to the assets. The raw folder can store arbitrary files in their - you guessed it - raw form. For example, a 'Hello World' article written in French and English, would be stored under:


  • RES /生-FR

  • RES /生恩

  • res/raw-fr
  • res/raw-en

原始资源然后可以通过调用<一开href=\"http://developer.android.com/reference/android/content/res/Resources.html#openRawResource%28int%29\"相对=nofollow> openRawResource(INT ID) 一个资源对象,类似于它的工作原理像图形内容串等其他资源上的ID的生成该框架将在熟悉的格式 R.raw.filename (不含文件扩展名)。

The raw resource can then be opened by calling openRawResource(int id) on a resources object, similar to how it works for other resources like drawables, strings etc. The id's generated by the framework will be in the familiar format of R.raw.filename (without file extension).

使用这种方法的好处是,你可以充分利用Android的定位系统,这意味着,作为一个开发人员,你基本不用担心任何的,在所有。您还可以轻松添加更多的预选赛上的设备特性进一步过滤器(如屏幕尺寸,密度,平台版本等等等等 - 的在这里看到一个完整的概述)。缺点是,它规定了一些限制,在原文件名/扩展方面,不支持一个适当的文件夹/文件分层结构。

The benefit of using this approach is that you can fully leverage Android's localization system, meaning that as a developer you basically don't have to worry about any of that at all. You can also easily add more qualifiers to further filter on device characteristics (e.g. screen size, density, platform version etc etc - see here for a full overview). The downside is that it imposes some limitations in terms of the original file name/extension and doesn't support a proper folder/file hierarchy.

在'好'的办法(/生VS /资产即是)很可能将取决于项目的要求。

The 'better' approach (/raw vs /assets that is) will probably depend on your project's requirements.

这篇关于在Android的不同语言使用大的文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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