`

【翻译】(31)本地化

 
阅读更多

【翻译】(31)本地化

 

see

http://developer.android.com/guide/topics/resources/localization.html

 

原文见

http://developer.android.com/guide/topics/resources/localization.html

 

-------------------------------

 

Localization

 

本地化

 

-------------------------------

 

Localization quickview

 

本地化快速概览

 

* Android lets you create different resource sets for different locales.

 

* Android让你为不同的语言环境创建不同的资源集。

 

* When your application runs, Android will load the resource set that match the device's locale.

 

* 当你的应用程序运行时,Android将加载匹配设备语言环境的资源集。

 

* If locale-specific resources are not available, Android falls back to defaults.

 

* 如果语言环境特定的应用程序不可用,那么Android会倒退回默认值。

 

* The emulator has features for testing localized apps.

 

* 模拟器有一些特性用于测试本地化应用。

 

In this document

 

本文目录

 

* Overview: Resource-Switching in Android 概览:Android中的资源切换

* Why Default Resources Are Important 为什么默认资源是重要的

* Using Resources for Localization 把资源用于本地化

* How to Create Default Resources  如何创建默认资源

* How to Create Alternative Resources 如何创建可选资源

* Which Resources Take Precedence? 哪个资源取得优先权?

* Referring to Resources in Java 在Java中引用资源

* Localization Strategies 本地化策略

* Testing Localized Applications 测试本地化的应用程序

* Testing on a Device 在设备上测试

* Testing on an Emulator 在模拟器上测试

* Testing for Default Resources 测试默认资源

* Publishing 发布

* Localization Checklists 本地化核对表

* Planning and Design Checklist 计划和设计核对表

* Content Checklist 内容核对表

* Testing and Publishing Checklist 测试和发布核对表

 

See also

 

另见

 

Hello, L10N Tutorial 你好,L10N教程

Providing Resources 提供资源

XML Layouts XML布局

Activity Lifecycle 活动生命周期

 

-------------------------------

 

Android will run on many devices in many regions. To reach the most users, your application should handle text, audio files, numbers, currency, and graphics in ways appropriate to the locales where your application will be used.

 

Android将运行在许多地区中的许多设备上。为了接触最多的用户,你的应用程序应该以适合应用程序将被使用在的语言环境的方式处理文本、音频文件、数字、货币,以及图形。

 

This document describes best practices for localizing Android applications. The principles apply whether you are developing your application using ADT with Eclipse, Ant-based tools, or any other IDE.

 

此文档描述本地化Android应用程序的最佳实践。这些原则应用在你是否正在使用带Eclipse的ADT、基于Ant的工具,或者其它任意IDE(注:集成开发环境的缩写)来开发你的应用程序。

 

You should already have a working knowledge of Java and be familiar with Android resource loading, the declaration of user interface elements in XML, development considerations such as Activity lifecycle, and general principles of internationalization and localization.

 

你应该总是有一套可行的Java知识并且熟悉Android资源加载,在XML中的用户界面元素的声明,开发考虑诸如Activity生命周期,以及国际化和本地化的通常原则。

 

It is good practice to use the Android resource framework to separate the localized aspects of your application as much as possible from the core Java functionality:

 

使用Android资源框架尽可能从核心的Java机制中分离出你的应用程序的本地化切面,是良好的实践:

 

* You can put most or all of the contents of your application's user interface into resource files, as described in this document and in Providing Resources.

 

* 你可以把你的应用程序用户界面的所有内容的大部分放进资源文件,正如这个文档和提供资源中所描述的那样。

 

* The behavior of the user interface, on the other hand, is driven by your Java code. For example, if users input data that needs to be formatted or sorted differently depending on locale, then you would use Java to handle the data programmatically. This document does not cover how to localize your Java code.

 

* 另一方面,用户界面的行为是被你的Java代码驱动的。例如,如果用户输入数据(注:这里多了个that?)需要被格式化或排序是依赖于语言环境而不同的。那么你将使用Java编程地处理数据。这个文档不涵盖如何本地化你的Java代码。

 

The Hello, L10N tutorial takes you through the steps of creating a simple localized application that uses locale-specific resources in the way described in this document.

 

你好,L10N教程一步步地教你创建一个简单的本地化应用程序,它用本文档中描述的方法来使用语言环境特定的资源。

 

-------------------------------

 

Overview: Resource-Switching in Android

 

概览:Android中的资源切换

 

Resources are text strings, layouts, sounds, graphics, and any other static data that your Android application needs. An application can include multiple sets of resources, each customized for a different device configuration. When a user runs the application, Android automatically selects and loads the resources that best match the device.

 

资源包括文本字符串,布局,声音,图形,以及你的Android应用程序使用的任意其它静态数据。一个应用程序可以包含多个资源集合,每种用于不同设备配置的定制资源。当一个用户运行应用程序时,Android自动地选择和加载最佳匹配设备的资源。

 

(This document focuses on localization and locale. For a complete description of resource-switching and all the types of configurations that you can specify — screen orientation, touchscreen type, and so on — see Providing Alternative Resources.)

 

(本文档把焦点放在本地化和语言环境。想获取资源切换和你可以指定的所有类型——屏幕方向,触摸屏类型,等等——的完整描述,请参见提供可选资源。)

 

* When you write your application: 

 

* 当你书写你的应用程序时:

 

You create a set of default resources, plus alternatives to be used in different locales.

 

你创建一个默认资源的集合,外加用在其它语言环境的可选项。

 

-->

 

* When a user runs your application: 

 

* 当一个用户运行你的应用程序时:

 

The Android system selects which resources to load, based on the device's locale.

 

Android系统选择加载哪个资源,基于设备的语言环境。

 

When you write your application, you create default and alternative resources for your application to use. To create resources, you place files within specially named subdirectories of the project's res/ directory.

 

当你书写你的应用程序时,你为你的应用程序创建要使用的默认和可选资源。为了创建资源,你把文件放在工程的res/目录下的特定命名的子目录中。

 

Why Default Resources Are Important

 

为什么默认资源是重要的

 

Whenever the application runs in a locale for which you have not provided locale-specific text, Android will load the default strings from res/values/strings.xml. If this default file is absent, or if it is missing a string that your application needs, then your application will not run and will show an error. The example below illustrates what can happen when the default text file is incomplete.

 

每当应用程序运行在你不曾提供语言环境特定文本的语言环境中时,Android将从res/values/strings.xml中加载默认字符串。如果这个默认文件不存在,或者如果它缺少你的应用程序需要的一个字符串,那么你的应用程序将不运行并且显示一个错误。下面的示例描述当默认文本文件不完整时可能发生的事情。

 

Example:

 

示例:

 

An application's Java code refers to just two strings, text_a and text_b. This application includes a localized resource file (res/values-en/strings.xml) that defines text_a and text_b in English. This application also includes a default resource file (res/values/strings.xml) that includes a definition for text_a, but not for text_b:

 

一个应用程序的Java代码只引用两个字符串,text_a和text_b。这个应用程序包含一个本地化资源文件(res/values-en/strings.xml),它用英语定义text_a和text_b。这个应用程序还包含一个默认资源文件(res/values/strings.xml),它包含text_a的定义,但没有定义text_b:

 

* This application might compile without a problem. An IDE such as Eclipse will not highlight any errors if a resource is missing.

 

* 这个应用程序可能编译没问题。如果缺少一个资源,一个IDE诸如Eclipse将不高亮任何错误。

 

* When this application is launched on a device with locale set to English, the application might run without a problem, because res/values-en/strings.xml contains both of the needed text strings.

 

* 当这个应用程序在设置语言环境为英语的设备上启动时,应用程序可能运行没问题,因为res/values-en/strings.xml都包含两个需要的文本字符串。

 

* However, the user will see an error message and a Force Close button when this application is launched on a device set to a language other than English. The application will not load.

 

* 然而,当应用程序启动在语言设置为不同于英语的设备上时,用户将看到错误消息和一个强制关闭按钮。应用程序将不加载。

 

To prevent this situation, make sure that a res/values/strings.xml file exists and that it defines every needed string. The situation applies to all types of resources, not just strings: You need to create a set of default resource files containing all the resources that your application calls upon — layouts, drawables, animations, etc. For information about testing, see Testing for Default Resources.

 

为了阻止这种情况,请确保res/values/strings.xml文件存在并且它定义每个需要的字符串。这种情形适用于所有类型的资源,不只是字符串:你需要创建一组默认资源文件,包含你的应用程序调用的所有资源——布局,可绘画对象,动画,等等。想获取关于测试的信息,请参见测试默认资源。

 

-------------------------------

 

Using Resources for Localization

 

把资源用于本地化

 

How to Create Default Resources

 

如何创建默认资源

 

Put the application's default text in a file with the following location and name:

 

放置应用程序的默认文本在带有以下位置和名称的文件中:

 

    res/values/strings.xml (required directory)

 

    res/values/strings.xml(必需目录)

 

The text strings in res/values/strings.xml should use the default language, which is the language that you expect most of your application's users to speak.

 

在res/values/strings.xml中的文本字符串应该使用默认语言,即你希望你的应用程序的大多数用户讲的语言。

 

The default resource set must also include any default drawables and layouts, and can include other types of resources such as animations. 

 

默认资源集合还必须包含任意默认的可绘画对象和布局,以及可能包含的其它类型资源诸如动画。

 

    res/drawable/(required directory holding at least one graphic file, for the application's icon in the Market)

 

    res/drawable/(必需目录,持有至少一个图形文件,它用于市场中的应用程序图标)

 

    res/layout/ (required directory holding an XML file that defines the default layout)

 

    res/layout/(必需目录,持有一个定义默认布局的XML文件)

 

    res/anim/ (required if you have any res/anim-<qualifiers> folders)

 

    res/anim/(必需的,如果你有任意res/anim-<修饰符>文件夹)

 

    res/xml/ (required if you have any res/xml-<qualifiers> folders)

 

    res/xml/(必需的,如果你有任意res/xml-<修饰符>文件夹)

 

    res/raw/ (required if you have any res/raw-<qualifiers> folders)

 

res/raw/(必需的,如果你有任意res/raw-<修饰符>文件夹)

 

-------------------------------

 

Tip: In your code, examine each reference to an Android resource. Make sure that a default resource is defined for each one. Also make sure that the default string file is complete: A localized string file can contain a subset of the strings, but the default string file must contain them all.

 

提示:在你的代码中,检查每个对Android资源的引用。确保每个引用的默认资源被定义。还要确保默认字符串文件是完整的:一个本地化字符串可以包含那些字符串的一个子集,但默认字符串文件必须包含它们全部。

 

-------------------------------

 

How to Create Alternative Resources

 

如何创建可选资源

 

A large part of localizing an application is providing alternative text for different languages. In some cases you will also provide alternative graphics, sounds, layouts, and other locale-specific resources.

 

本地化一个应用程序的大部分工作在于提供不同语言的可选文本。在一些情况中你还将提供可选图形、声音、布局,以及其它语言环境特定的资源。

 

An application can specify many res/<qualifiers>/ directories, each with different qualifiers. To create an alternative resource for a different locale, you use a qualifier that specifies a language or a language-region combination. (The name of a resource directory must conform to the naming scheme described in Providing Alternative Resources, or else it will not compile.)

 

一个应用程序可以指定许多res/<修饰符>/目录,每个目录带有的修饰符。为了为不同语言环境创建一个可选资源,你使用一个修饰符指定一个语言或语言-地区组合。(资源目录的名称必须符合提供可选资源中描述的命名模式,否则它将不能编译。)

 

Example:

 

示例:

 

Suppose that your application's default language is English. Suppose also that you want to localize all the text in your application to French, and most of the text in your application (everything except the application's title) to Japanese. In this case, you could create three alternative strings.xml files, each stored in a locale-specific resource directory:

 

假设你的应用程序的默认语言是英语。还假设你希望把你的应用程序的所有文本本地化为法语,以及把你的应用程序中的大多数文本(所有东西除了应用程序的标题)本地化为日语。在这种情况下,你可以创建三个可选strings.xml文件,每个文件保存在一个语言环境特定的资源目录中:

 

1. res/values/strings.xml

 

Contains English text for all the strings that the application uses, including text for a string named title.

 

包含用于你的应用程序使用的所有字符串的英语文本,包括用于命名标题的字符串的文本。

 

2. res/values-fr/strings.xml

 

Contain French text for all the strings, including title.

 

包含用于所有字符串的法语文本,包括标题。

 

3. res/values-ja/strings.xml

 

Contain Japanese text for all the strings except title.

 

包含用于所有字符串的日语文本,除了标题。

 

If your Java code refers to R.string.title, here is what will happen at runtime:

 

如果你的Java代码引用R.string.title,那么这里是将会在运行时发生的事情:

 

* If the device is set to any language other than French, Android will load title from the res/values/strings.xml file.

 

* 如果设备设置为任意不同于法语的语言,Android将加载the res/values/strings.xml文件中的标题。

 

* If the device is set to French, Android will load title from the res/values-fr/strings.xml file.

 

* 如果设备被设置为法语,Android将加载res/values-fr/strings.xml文件中的资源。

 

Notice that if the device is set to Japanese, Android will look for title in the res/values-ja/strings.xml file. But because no such string is included in that file, Android will fall back to the default, and will load title in English from the res/values/strings.xml file.

 

注意如果设备被设置为日语,那么Android将查找res/values-ja/strings.xml文件中的标题。但因为那个文件中没有包含这个字符串,所以Android将倒退回默认,并且将加载res/values/strings.xml文件中的英语标题。

 

Which Resources Take Precedence?

 

哪个资源取得优先权?

 

If multiple resource files match a device's configuration, Android follows a set of rules in deciding which file to use. Among the qualifiers that can be specified in a resource directory name, locale almost always takes precedence.

 

如果多个资源文件匹配一个设备配置,那么Android遵循一组决定使用哪个文件的规则。在可以在资源目录名称中指定的修饰符中,语言环境几乎总是持有优先权。

 

Example:

 

示例:

 

Assume that an application includes a default set of graphics and two other sets of graphics, each optimized for a different device setup:

 

假设一个应用程序包含一个图形的默认集合以及两个其它的图形集合,每个集合为不同设备配置而优化。

 

* res/drawable/

 

Contains default graphics.

 

包含默认图形

 

* res/drawable-small-land-stylus/

 

Contains graphics optimized for use with a device that expects input from a stylus and has a QVGA low-density screen in landscape orientation.

 

包含为使用期待来自手写笔的输入和拥有QVGA低密度屏幕的宽屏方向下的设备而优化的图形。

 

* res/drawable-ja/ 

 

Contains graphics optimized for use with Japanese.

 

包含为日语使用而优化的图形。

 

If the application runs on a device that is configured to use Japanese, Android will load graphics from res/drawable-ja/, even if the device happens to be one that expects input from a stylus and has a QVGA low-density screen in landscape orientation.

 

如果应用程序运行在配置使用日语的设备上,那么Android将加载来自res/drawable-ja/的图形,即便设备发生在期待来自手写笔的输入并且拥有一个QVGA低密度屏幕且在宽屏方向下的设备上。

 

-------------------------------

 

Exception: The only qualifiers that take precedence over locale in the selection process are MCC and MNC (mobile country code and mobile network code).

 

例外:在选择处理中唯一持有高于语言环境的优先权的修饰符是MCC和MNC(移动国家代码以及移动网络代码)。

 

-------------------------------

 

Example:

 

示例:

 

Assume that you have the following situation:

 

假设你有以下情况:

 

* The application code calls for R.string.text_a

 

* 应用程序代码请求R.string.text_a

 

* Two relevant resource files are available:

 

* 两个相应的资源文件可用:

 

* res/values-mcc404/strings.xml, which includes text_a in the application's default language, in this case English.

 

* res/values-mcc404/strings.xml,它包含应用程序默认语言下的text_a,在这个案例中是英语。

 

* res/values-hi/strings.xml, which includes text_a in Hindi.

 

* res/values-hi/strings.xml,它包含印地语下的text_a

 

* The application is running on a device that has the following configuration:

 

* 应用程序正在运行在拥有以下配置的设备上:

 

* The SIM card is connected to a mobile network in India (MCC 404).

 

* SIM卡被连接到印度的移动网络(MCC 404)

 

* The language is set to Hindi (hi).

 

* 语言设置为印地语(hi)。

 

Android will load text_a from res/values-mcc404/strings.xml (in English), even if the device is configured for Hindi. That is because in the resource-selection process, Android will prefer an MCC match over a language match.

 

Android将加载来自res/values-mcc404/strings.xml的text_a(英语),即便设备被配置为印地语。那是因为在资源选择处理中,Android将倾向于MCC匹配而非语言匹配。

 

The selection process is not always as straightforward as these examples suggest. Please read How Android Finds the Best-matching Resource for a more nuanced description of the process. All the qualifiers are described and listed in order of precedence in Table 2 of Providing Alternative Resources.

 

选择过程不总是如同这些示例建议的那样直观。请阅读Android如何找到最佳匹配资源以获得该处理的更多细致的描述。所有修饰符被描述并列举在提供可选资源的表2中的优先级次序。

 

Referring to Resources in Java

 

在Java中引用资源

 

In your application's Java code, you refer to resources using the syntax R.resource_type.resource_name or android.R.resource_type.resource_name. For more about this, see Accessing Resources.

 

在你的应用程序的Java代码中,你使用语法R.<资源类型>.<资源名称>或android.R.<资源类型>.<资源名称>来引用资源。想获取关于它的更多信息,参见访问资源。

 

-------------------------------

 

Localization Strategies

 

本地化策略

 

Design your application to work in any locale

 

设计你的应用程序以工作在任意语言环境

 

You cannot assume anything about the device on which a user will run your application. The device might have hardware that you were not anticipating, or it might be set to a locale that you did not plan for or that you cannot test. Design your application so that it will function normally or fail gracefully no matter what device it runs on.

 

你不能假设关于用户将把你的应用程序运行在的设备的任何东西。设备可能拥有你预料之外的硬件,或者它可能设置为你没有计划的语言环境或者你不能测试的语言环境。设计你的应用程序使它将正常地起作用或优雅地失败,不管它运行在什么设备上。

 

-------------------------------

 

Important: Make sure that your application includes a full set of default resources.

 

重要:确保你的应用程序包含默认资源的完全集合。

 

-------------------------------

 

Make sure to include res/drawable/ and a res/values/ folders (without any additional modifiers in the folder names) that contain all the images and text that your application will need.

 

确保包含res/drawable/和一个res/values/文件夹(在文件夹名称中不带任何附加的修饰符),它们包含你的应用程序将需要的所有图片和文本。

 

If an application is missing even one default resource, it will not run on a device that is set to an unsupported locale. For example, the res/values/strings.xml default file might lack one string that the application needs: When the application runs in an unsupported locale and attempts to load res/values/strings.xml, the user will see an error message and a Force Close button. An IDE such as Eclipse will not highlight this kind of error, and you will not see the problem when you test the application on a device or emulator that is set to a supported locale.

 

如果一个应用程序缺少甚至只是一个默认资源,它将不能运行在设置为一个不被支持的语言环境的设备上。例如,res/values/strings.xml默认文件可能缺乏应用程序需要的一个字符串:当应用程序运行在一个不支持的语言环境中并且尝试加载res/values/strings.xml时,用户将看到一个错误消息以及一个强制关闭按钮。一个IDE诸如Eclipse将不会高亮此类错误,而当你在设置为支持的语言环境的设备或模拟器上测试应用程序时你将看不到这个问题。

 

For more information, see Testing for Default Resources.

 

想获取更多信息,参见测试默认资源。

 

Design a flexible layout

 

设计灵活的布局

 

If you need to rearrange your layout to fit a certain language (for example German with its long words), you can create an alternative layout for that language (for example res/layout-de/main.xml). However, doing this can make your application harder to maintain. It is better to create a single layout that is more flexible.

 

如果你需要重新排列你的布局以适应某种语言(例如单词较长的德语),你可以为那种语言创建一个可选布局(例如res/layout-de/main.xml)。然而,这样做可能使你的应用程序更难维护。最好创建一个更灵活的单一布局。

 

Another typical situation is a language that requires something different in its layout. For example, you might have a contact form that should include two name fields when the application runs in Japanese, but three name fields when the application runs in some other language. You could handle this in either of two ways:

 

另一个典型的情形是一种语言需要它的布局中的东西不同。例如,当应用程序运行在日语中时你的联系表单可能应该包含两个名字域,但当应用程序运行在其它一些语言中时却要三个名字域。你可以用两种方式之一来处理这种情况:

 

* Create one layout with a field that you can programmatically enable or disable, based on the language, or

 

* 创建一个布局,带有你可以编程地基于语言来开启和关闭的域,或者

 

* Have the main layout include another layout that includes the changeable field. The second layout can have different configurations for different languages.

 

* 让主布局包含另一个包含可改变域的布局。第二个布局对于不同语言可以有不同的配置。

 

Avoid creating more resource files and text strings than you need

 

避免创建比你需要的还多的资源文件以及文本字符串

 

You probably do not need to create a locale-specific alternative for every resource in your application. For example, the layout defined in the res/layout/main.xml file might work in any locale, in which case there would be no need to create any alternative layout files.

 

你很可能不需要为你的应用程序中的每个资源创建一个语言环境特定的可选项。例如,定义在res/layout/main.xml文件中的布局可能工作于任意语言环境中,在这种情况下没必要创建任何可选的布局文件。

 

Also, you might not need to create alternative text for every string. For example, assume the following:

 

同样,你不必为每个字符串创建可选文本。例如,假设以下情况:

 

* Your application's default language is American English. Every string that the application uses is defined, using American English spellings, in res/values/strings.xml.

 

* 你的应用程序的默认语言是美式英语。应用程序使用的每个字符串被定义在res/values/strings.xml中,使用美式英语的拼写。

 

* For a few important phrases, you want to provide British English spelling. You want these alternative strings to be used when your application runs on a device in the United Kingdom.

 

* 对于一些重要的短语,你希望提供英式英语拼写。你希望当你的应用程序运行在英国的设备上时这些可选字符串被使用。

 

To do this, you could create a small file called res/values-en-rGB/strings.xml that includes only the strings that should be different when the application runs in the U.K. For all the rest of the strings, the application will fall back to the defaults and use what is defined in res/values/strings.xml.

 

为了做到这一点,你可以创建一个小文件叫res/values-en-rGB/strings.xml,它只包含应该在应用程序运行在英国时不同的字符串。对于其它字符串,应用程序将倒退回默认并使用定义在res/values/strings.xml中的字符串。

 

Use the Android Context object for manual locale lookup

 

把Android的Context对象用于手工语言环境查找

 

You can look up the locale using the Context object that Android makes available:

 

你可以使用Android使其可用的Context对象来查找语言环境:

 

-------------------------------

 

String locale = context.getResources().getConfiguration().locale.getDisplayName();

 

-------------------------------

 

-------------------------------

 

Testing Localized Applications

 

测试本地化的应用程序

 

Testing on a Device

 

在设备上测试

 

Keep in mind that the device you are testing may be significantly different from the devices available to consumers in other geographies. The locales available on your device may differ from those available on other devices. Also, the resolution and density of the device screen may differ, which could affect the display of strings and drawables in your UI.

 

谨记你正在测试的设备可能和对于其它地区的消费者来说可用的设备有很大的不同。你的设备上可用的语言环境可能不同于其它设备上可用的语言环境。同样,设备屏幕的分辨率和密度可能不同,这可能影响你的用户界面中字符串和可绘画对象的显示。

 

To change the locale on a device, use the Settings application (Home > Menu > Settings > Locale & text > Select locale).

 

为了改变设备上的语言环境,使用设置应用程序(主页>菜单>设置>语言环境和文本>选择语言环境)。

 

Testing on an Emulator

 

在模拟器上测试

 

For details about using the emulator, see See Android Emulator.

 

关于使用模拟器的细节,请参见查看Android模拟器。

 

Creating and using a custom locale

 

创建并使用一个自定义语言环境

 

A "custom" locale is a language/region combination that the Android system image does not explicitly support. (For a list of supported locales in Android platforms see the Version Notes in the SDK tab). You can test how your application will run in a custom locale by creating a custom locale in the emulator. There are two ways to do this:

 

一个“自定义”语言环境是一个语言/地区组合,Android系统镜像不能显式地支持它。(想获取Android平台中被支持的语言环境的列表,请参见在SDK标签页中版本注意)。你可以通过在模拟器上创建一个自定义语言环境,测试你的应用程序将如何运行在一个自定义语言环境中。有两种方式做到这一点:

 

* Use the Custom Locale application, which is accessible from the Application tab. (After you create a custom locale, switch to it by pressing and holding the locale name.)

 

* 使用自定义语言环境应用程序,它从应用程序标签页中可访问。(在你创建一个自定义语言环境后,通过按下并按住语言环境名称来切换到它。)

 

* Change to a custom locale from the adb shell, as described below.

 

* 从adb外壳中改变到一个自定义语言环境,正如下面描述的那样。

 

When you set the emulator to a locale that is not available in the Android system image, the system itself will display in its default language. Your application, however, should localize properly.

 

当你设置模拟器为一个在Android系统镜像中不可用的语言环境时,系统自身将用它默认的语言来显示。然而,你的应用程序应该正确地本地化。

 

Changing the emulator locale from the adb shell

 

从adb外壳中改变模拟器语言环境

 

To change the locale in the emulator by using the adb shell.

 

为了用adb外壳改变模拟器中的语言环境。

 

1. Pick the locale you want to test and determine its language and region codes, for example fr for French and CA for Canada.

 

1. 选取你希望测试的语言环境并且决定他的语言和地区代码,例如fr用于法语而CA用于加拿大。

 

2. Launch an emulator.

 

2. 启动模拟器。

 

3. From a command-line shell on the host computer, run the following command:

 

3. 从宿主计算机上的命令行外壳中,运行以下命令:

 

adb shell

 

or if you have a device attached, specify that you want the emulator by adding the -e option:

 

或者如果你有一个被依附的设备,通过添加-e选项来指定你希望的模拟器:

 

adb -e shell

 

4. At the adb shell prompt (#), run this command: 

 

4. 在adb外壳提示符(#)后,运行这个命令:

 

setprop persist.sys.language [language code];setprop persist.sys.country [country code];stop;sleep 5;start 

 

setprop persist.sys.language [语言代码];setprop persist.sys.country [国家代码];stop;sleep 5;start 

 

Replace bracketed sections with the appropriate codes from Step 1.

 

替换中括号内的部分为步骤1中的合适代码

 

For instance, to test in Canadian French:

 

例如,为了在加拿大法语语言环境中测试:

 

setprop persist.sys.language fr;setprop persist.sys.country CA;stop;sleep 5;start

 

This will cause the emulator to restart. (It will look like a full reboot, but it is not.) Once the Home screen appears again, re-launch your application (for example, click the Run icon in Eclipse), and the application will launch with the new locale.

 

这将导致模拟器重启。(它将看起来像完全的重引导,但它不是。)一旦主页屏幕再次显示,重启动你的应用程序(例如,点击Eclipse中的运行图标),而应用程序将用新的语言环境来启动。

 

Testing for Default Resources

 

测试默认资源

 

Here's how to test whether an application includes every string resource that it needs:

 

这里是如何测试一个应用程序是否包含每个它需要的字符串资源:

 

1. Set the emulator or device to a language that your application does not support. For example, if the application has French strings in res/values-fr/ but does not have any Spanish strings in res/values-es/, then set the emulator's locale to Spanish. (You can use the Custom Locale application to set the emulator to an unsupported locale.)

 

1. 设置模拟器或设备为你的应用程序不支持的语言。例如,如果应用程序在res/values-fr/中有法语字符串,但在res/values-es/中没有任何西班牙语字符串,那么设置模拟器的语言环境为西班牙语。(你可以使用自定义语言环境应用程序来设置模拟器为一个不支持的语言环境。) 

 

2. Run the application.

 

2. 运行应用程序。

 

3. If the application shows an error message and a Force Close button, it might be looking for a string that is not available. Make sure that your res/values/strings.xml file includes a definition for every string that the application uses.

 

3. 如果应用程序显示一个错误消息和一个强制关闭按钮,那么它可能正在查找一个不可用的字符串。确保你的res/values/strings.xml文件包含对应用程序使用的每个字符串的定义。

 

If the test is successful, repeat it for other types of configurations. For example, if the application has a layout file called res/layout-land/main.xml but does not contain a file called res/layout-port/main.xml, then set the emulator or device to portrait orientation and see if the application will run.

 

如果测试是成功的,对其它类型的配置重复这个测试。例如,如果应用程序有一个布局文件叫res/layout-land/main.xml,但不包含一个叫res/layout-port/main.xml的文件,那么设置模拟器或设备为竖屏并查看应用程序是否可以运行。

 

-------------------------------

 

Publishing Localized Applications

 

发布本地化的应用程序

 

The Android Market is the main application distribution system for Android devices. To publish a localized application, you need to sign your application, version it, and go through all the other steps described in Preparing to Publish.

 

Android市场是Android设备的主要应用程序分发系统。为了发布一个本地化系统,你需要签名你的应用程序,指定它的版本,并且依次执行在准备发布章节中描述的其它所有步骤。

 

If you split your application in several .apk files, each targeted to a different locale, follow these guidelines:

 

如果你把你的应用程序分割成几个.apk文件,每个的目标为一个不同的语言环境,请遵循这些指引:

 

* Sign each .apk file with the same certificate. For more about this, see Signing Strategies.

 

* 用相同的证书签名每个.apk文件,关于它的更多信息,请参见签名策略。

 

* Give each .apk file a different application name. Currently it is impossible to put two applications into the Android Market that have exactly the same name.

 

* 给每个.apk文件一个不同的应用程序名称。当前它不可能把两个完全相同名称的应用程序放进Android市场中。

 

* Include a complete set of default resources in each .apk file.

 

* 在每个.apk文件中包含默认资源的完整集合。

 

-------------------------------

 

Localization Checklists

 

本地化核对表

 

These checklists summarize the process of localizing an Android application. Not everything on these lists will apply to every application.

 

这些核对表总结本地化一个Android应用程序的处理过程。这些列表上不是所有东西都适合每个应用程序。

 

Planning and Design Checklist

 

计划和设计核对表

 

-------------------------------

 

* Choose a localization strategy. Which countries and which languages will your application support? What is your application's default country and language? How will your application behave when it does not have specific resources available for a given locale?

* 选择一个本地化策略。你的应用程序将支持哪个国家和那种语言?你的应用程序的默认国家和语言是什么?当对于一个给定的语言环境它没有可用的特定资源时,你的应用程序将如何行为?

* Identify everything in your application that will need to be localized:

 

* 标识你的应用程序中的将被本地化的任何东西:

 

* Consider specific details of your application — text, images, sounds, music, numbers, money, dates and times. You might not need to localize everything. For example, you don't need to localize text that the user never sees, or images that are culturally neutral, or icons that convey the same meaning in every locale.

 

* 考虑你的应用程序的特定细节——文本,图片,声音,音乐,数字,货币,日期,以及时间。你可能不需要本地化所有东西。例如,你不需要本地化用户从不看到的文本,或者从文化上中立的图片,或者在每种语言环境中表达相同意思的图标。

 

* Consider broad themes. For example, if you hope to sell your application in two very culturally different markets, you might want to design your UI and present your application in an entirely different way for each locale.

 

* 考虑宽阔的主题。例如,如果你希望在两个在文化上非常不同的市场上销售你的应用程序,你可能希望为每种语言环境用完全不同的方式设计你的用户界面和表现你的应用程序。

 

* Design your Java code to externalize resources wherever possible:

 

* 设计你的Java代码以在可能的任何地方外部化资源:

 

* Use R.string and strings.xml files instead of hard-coded strings or string constants.

 

* 使用R.string和strings.xml文件而非硬编码的字符串或字符串常量。

 

* Use R.drawable and R.layout instead of hard-coded drawables or layouts.

 

* 使用R.drawable和R.layout而非硬编码的可绘画对象或布局。

 

-------------------------------

 

Content Checklist

 

内容核对表

 

-------------------------------

 

* Create a full set of default resources in res/values/ and other res/ folders, as described in Creating Default Resources.

* 在res/values/和其它res/文件夹中创建一个默认资源的完全集合,正如创建默认资源中描述的那样。

* Obtain reliable translations of the static text, including menu text, button names, error messages, and help text. Place the translated strings in res/values-<qualifiers>/strings.xml files.

* 获得静态文本的可靠翻译,包括菜单文本,按钮名称,错误消息,以及帮助文本。放置翻译字符串在res/values-<修饰符>/strings.xml文件中。

* Make sure that your application correctly formats dynamic text (for example numbers and dates) for each supported locale. Make sure that your application handles word breaks, punctuation, and alphabetical sorting correctly for each supported language.

* 确保你的应用程序对于每个支持的语言环境能正确地格式化动态文本(例如数字和日期)。确保你的应用程序对于每个被支持语言而言正确地处理单词中断,标点符号,以及字母表排列。

* If necessary, create locale-specific versions of your graphics and layout, and place them in res/drawable-<qualifiers>/ and res/layout-<qualifiers>/ folders.

* 如果需要的话,创建你的图形和布局的语言环境特定的版本,并且把它们放置在res/drawable-<修饰符>/和res/layout-<修饰符>/文件夹中。

* Create any other localized content that your application requires; for example, create recordings of sound files for each language, as needed.

* 创建你的应用程序需要的其它任意本地化内容;例如,为每种语言创建声音文件的记录,如果需要的话。

-------------------------------

 

Testing and Publishing Checklist

 

测试和发布和核对表

 

-------------------------------

 

* Test your application for each supported locale. If possible, have a person who is native to each locale test your application and give you feedback.

* 为每个被支持的语言环境测试你的应用程序。如果可能,有一个熟悉每个语言环境的人测试你的应用程序并且给你反馈。

* Test the default resources by loading a locale that is not available on the device or emulator. For instructions, see Testing for Default Resources.

* 通过加载一个设备上或模拟器上不可用的语言环境来测试默认资源。想获取步骤,请参见测试默认资源。

* Test the localized strings in both landscape and portrait display modes.

* 在宽屏和竖屏显示模式下测试本地化字符串。

* Sign your application and create your final build or builds.

* 签名你的应用程序并创建一个或多个最终构建。

* Upload your .apk file or files to Market, selecting the appropriate languages as you upload. (For more details, see Publishing Your Applications.)

* 上传你一个或多个.apk文件到市场,在你上传时选择合适的语言。(想获取更多细节,请参见发布你的应用程序。)

 

-------------------------------

 

Except as noted, this content is licensed under Apache 2.0. For details and restrictions, see the Content License.

 

除特别说明外,本文在Apache 2.0下许可。细节和限制请参考内容许可证。

 

Android 4.0 r1 - 04 Jan 2012 0:53

 

-------------------------------

 

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

 

(此页部分内容基于Android开源项目,以及使用根据创作公共2.5来源许可证描述的条款进行修改)

 

(本人翻译质量欠佳,请以官方最新内容为准,或者参考其它翻译版本:

* ソフトウェア技術ドキュメントを勝手に翻訳

http://www.techdoctranslator.com/android

* Ley's Blog

http://leybreeze.com/blog/

* 农民伯伯

http://www.cnblogs.com/over140/

* Android中文翻译组

http://androidbox.sinaapp.com/


分享到:
评论

相关推荐

    eclipse4.7中文包

    "nl"通常代表“本地化”(Localization),"zh"表示中文,"4.7.0"对应Eclipse的版本号,而"v20171231020002"可能是版本发布的时间戳,表示这个汉化包是在2017年12月31日的凌晨2点02分完成的。这意味着该汉化包是最新...

    课题-QML基础-QML国际化(中文示例).pdf

    在开发跨语言的应用程序时,国际化和本地化是非常重要的步骤,尤其在Qt环境中。QML作为Qt的一个关键组件,提供了方便的方式来实现国际化。本篇主要介绍如何在QML中实现国际化,以中文为例,帮助开发者了解如何让QML...

    LoalizationExampleMicrosoftCore31

    在这个"LoalizationExampleMicrosoftCore31"项目中,我们将深入探讨如何在使用C#语言开发的基于.NET Core 3.1的应用程序中实现本地化。 .NET Core 3.1是微软提供的一个开源、跨平台的开发框架,用于构建高效、可...

    whthin__example.rar_对话框与窗口

    - 文件名中出现的“Gettext”通常与软件的本地化有关,Gettext是一个广泛使用的开源工具,用于提取、翻译和集成软件的字符串,使软件能够支持多种语言。 综上所述,这个压缩包包含了一个基于C++的Windows应用程序...

    Trados 2015

    整合后的系统能够实现本地化项目的自动化处理,增强团队协作,以及提高翻译生产效率。 文档中提到了版权和商标信息,强调了SDL集团对其产品的知识产权拥有完整的权利,并且指明了未经明确许可不得复制或传播该产品...

    rfc中文文档目录,包含部分翻译

    RFC1998 BGP 社区属性在多本地路由中的应用   RFC2002 IP移动性支持 RFC2003 在IP内封装IP RFC2004 IP最小封装 RFC2005 IP移动性的适用性陈述 RFC2011 SNMPv2 管理信息基础用于Internet 协议使用SMIv2 RFC...

    软件测试实验报告 软件测试 实验报告2

    实验报告的主题围绕着软件测试,特别是黑盒测试和软件本地化这两个关键领域。黑盒测试是一种不考虑软件内部结构和工作原理,仅基于其功能需求进行的测试方法。实验的目的在于让学生掌握黑盒测试中的三种主要技术:...

    eclipse 3.6 中文包 8.0

    汉化包不仅包含用户界面的翻译,还包括帮助文档和错误消息的本地化,确保用户在遇到问题时可以方便地查找解决方案。 安装Eclipse 3.6中文包8.0的方法非常简单,只需要将下载的压缩包解压后,将其中的文件复制到...

    matlab命令中文翻译大全.docx

    8. **Printopt**:配置本地打印机默认设置。 9. **Orient**:设置纸张方向。 10. **Semilogx** 和 **Semilogy**:创建半对数坐标图。 11. **Fill**:绘制二维多边形填充图。 其他命令: 1. **Capture**(版本3前)...

    cron中英文表达式

    此外,库还支持本地化,可以适应不同语言环境。 使用`jquery-cron`时,你需要首先引入jQuery库,然后引入`jquery-cron`的JavaScript和CSS文件。在HTML中添加一个元素作为cron选择器的容器,接着在JavaScript中初始...

    GNU C library reference

    7. 消息翻译:glibc支持国际化消息的翻译和格式化,利用gettext系列函数可以实现程序输出的国际化和本地化。 8. 搜索与排序:glibc提供了一系列的比较函数和搜索算法,以及快速排序和堆排序等排序函数,用于对数据...

    java关键字大全及解释

    27. `native`: 修饰符,表明方法的实现是在本地代码(如C或C++)中。 28. `new`: 创建一个新的对象实例。 29. `null`: 表示引用类型变量没有指向任何对象。 30. `package`: 将相关类组织在一起的命名空间,有助于...

    精通AngularJS part1

    本地化设置和AngularJS过滤器275 102处理翻译277 翻译AngularJS模板中的字符串277 使用过滤器278 使用指令279 翻译JavaScript代码中的字符串280 103范式、秘诀和技巧282 按照设定的地区初始化应用282 将地区...

    Linux_101_Hacks统稿by朱涛(经典英文版朋友翻译的)

    - **解释**:使用`date`命令的不同格式化选项可以定制显示时间的方式。 - **示例**:使用`date "+%Y-%m-%d %H:%M:%S"`以特定格式显示当前时间。 #### 技巧10:显示过去的日期和时间 - **解释**:可以使用`date`...

    几个常用语言的 三字符 简称

    - **简称意义**:“DAN”作为丹麦语的简称,有助于区分不同的日耳曼语种,确保翻译和本地化的准确性。 ### 8. 荷兰语(NLD) - **简介**:荷兰语是荷兰、比利时弗拉芒区等地的主要语言。 - **简称意义**:“NLD”...

    4年一轮回:李开复与刘允.docx

    李开复时代,谷歌中国推出了一系列本地化产品,如地图、翻译、音乐、输入法等,而刘允领导期间,新产品发布较少,团购服务“谷歌时惠”是在团购市场竞争激烈时才推出,缺乏竞争力。此外,谷歌在中国的Android系统和...

    软件测试英语专业词汇辉总

    在软件开发中,为了使软件能够适应不同国家和地区用户的语言习惯,通常需要对软件进行本地化处理,即根据目标市场的语言特点和文化习俗来调整软件界面、帮助文档等。NLV是一种针对特定地区或语言环境定制的软件版本...

    bluez5编译包 多版本5.44 5.34 5.54 mips平台

    1. **gettext-0.22.5.tar.gz**:这是一个用于软件本地化的工具包,它提供了处理翻译文本的能力,使得软件可以根据用户所在的地区显示正确的语言。 2. **ncurses-5.9.tar.gz**:NCURSES是一个用于控制终端的库,它...

    FoxitPDFCreator_30_enu(32位版)

    值得注意的是,"汉化补丁"可能包含了一个非官方的本地化版本,使得软件界面适应中文用户的需求。这些补丁通常由第三方开发者提供,目的是将原本英文的软件界面翻译成中文,使得不熟悉英文的用户也能顺畅地使用软件。...

Global site tag (gtag.js) - Google Analytics