使用伪语言区域测试您的应用
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
伪语言区域是一种语言区域,其目的是模拟在翻译应用时可导致出现界面、布局和其他翻译相关问题的语言特征。伪语言区域是由所有可本地化消息的即时自动翻译(可用英语表示)创建的。非伪本地化的文本指向源代码中不可翻译的消息。
使用伪语言区域,可以帮助您节省时间和成本,因为您可以先对界面文本及其布局进行调整,然后再将消息提交到之后要送交翻译的源代码库。有关潜在翻译问题的列表,请参阅发现本地化问题部分。
图 1. 英语 (XA) 伪语言区域。
Android 伪语言区域名称遵循标准的语言区域命名惯例,其语言区域 ID 可以由任何符合 BCP 47 规范的编程语言解析。从这个意义上讲,伪语言区域和任何其他语言区域(如法语、中文或俄语)没什么两样。
Android 平台提供了以下两种伪语言区域,分别表示从左到右 (LTR) 和从右到左 (RTL) 显示的语言:
图 2. AR (XB) 伪语言区域。
英语 (XA):在基本英文界面文本中添加拉丁语重音符号,通过添加不带重音符号的文本扩展原始文本,并用方括号将每个消息单元括起来,以使扩展文本中的潜在问题暴露出来。潜在的问题可能是布局损坏和消息语法错误,例如句子被分成多个部分,显示为多条由括号括住的消息。英语 (XA) 伪语言区域如图 1 所示。
AR (XB):将从左到右显示的原始消息的文本方向设为从右到左的方向,这会颠倒原始消息中字符的顺序。AR (XB) 伪语言区域如图 2 所示。
即使您在书面和口头上都不使用 RTL 语言,伪语言区域也可以帮助您创建应用的 RTL 版本。
启用伪语言区域
伪语言区域通常会添加到面向开发者的版本中。当您在设备上选择伪语言区域时,支持伪语言区域的所有应用都会呈现出所选伪语言区域的特征,包括所有系统应用,如“设置”应用和“快捷设置”面板等。
如要使用 Android 伪语言区域,您的设备必须搭载 Android 4.3(API 级别 18)或更高版本,并启用开发者选项。启用开发者选项后,您还必须重新启动设备。
以下步骤介绍了如何启用伪语言区域:
在 Android Studio 中,可以通过将以下配置添加到 build.gradle
文件来为特定应用启用伪语言区域:
Kotlin
android {
...
buildTypes.getByName("debug") {
isPseudoLocalesEnabled = true
}
}
构建和运行您的应用
图 3. 选择伪语言区域。
使用“设置”应用来选择伪语言区域。此步骤会因 Android 版本而异,具体如下:
Android 5.0(API 级别 21)或更高版本
- 在设备上打开“设置”应用,然后依次点按语言和输入法 > 语言偏好设置。
- 在语言偏好设置列表中,拖动相关标签页以将伪语言区域移到列表顶部,使其成为活跃语言(详见图 3)。
Android 4.4.4(API 级别 19)或更低版本
- 在设备上打开“设置”应用,然后依次点按语言和输入法 > 语言偏好设置 > 添加语言。
- 点按一个伪语言区域,将其添加到语言偏好设置列表中。
- 在语言偏好设置列表中,拖动相关标签页以将伪语言区域移到列表顶部,使其成为活跃语言(详见图 3)。
发现本地化问题
伪语言区域可帮助您识别以下方面的问题,让您既省时又有效地发现界面中可能存在的本地化问题:
- 硬编码字符串不能送交翻译,这些字符串会以不带重音符号的文本的形式显示在伪语言区域中,以便于识别。
- 由文本扩展导致的界面布局问题,显示了可由文本长度导致界面断开的位置。
字符串串联,表现为一条消息被拆分成由方括号括住的两个或更多个部分。这可能会增加翻译的难度,因为翻译人员必须独立地翻译每个部分,而不知道这些部分是相关的。字符串串联还可能让翻译人员无法做出正确的翻译,因为不同的语言可能会要求以不同的顺序组织各个部分或采用完全不同的句子结构。例如,日语、韩语和泰米尔语等语言会将动词放在句末。当句子被串联时,翻译人员将无法根据需要更改词序。
双向 (BIDI) 文本问题,例如当一种文本方向的内容中包含了相反文本方向的内嵌语句时,会导致字符串难以阅读。
从右到左 (RTL) 的问题,比如元素未被镜像。例如,界面元素没有向左移动、文本没有反转并向左移动,或者标点符号放错位置,例如“pseudolocales rule!”变成了“elur selacoloduesp!”,而不是“!elur selacoloduesp”。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-27。
[null,null,["最后更新时间 (UTC):2025-07-27。"],[],[],null,["# Test your app with pseudolocales\n\nA pseudolocale is a locale that is designed to simulate characteristics of\nlanguages that cause UI, layout, and other translation-related problems when an\napp\nis translated. Pseudolocales are created by instant and automatic translations\nthat are readable in English for all *localizable* messages.\nUn-pseudolocalized text points to untranslatable messages in your source code.\n\nPseudolocales save time\nand money because you can make adjustments to the UI text and its layout before\nyou commit your messages to the source repository to be sent for translation\nlater. For a list of potential translation problems, see the\n[Spot localization issues](#spot_localization_issues) section. \n\n**Figure 1.** English (XA) pseudolocale.\n\nThe Android pseudolocale names follow standard locale naming conventions, and\ntheir locale IDs can be parsed by any BCP 47 compliant programming language.\nIn this sense, pseudolocales are just like any other locales, such as French,\nChinese, or Russian.\n\nThe Android platform provides the following two pseudolocales to represent\nleft-to-right (LTR) and right-to-left (RTL) languages: \n\n**Figure 2.** AR (XB) pseudolocale.\n\n**English (XA):** adds Latin accents to the base English UI text, expands the\noriginal text by adding non-accented text, and brackets each message unit to\nexpose potential issues from expanded text. Potential issues can be layout\nbreakage and badly formed message syntax, such as a sentence split\ninto multiple parts displaying as multiple bracketed messages. The English (XA)\npseudolocale is shown in figure 1.\n\n**AR (XB):** sets the text direction of the original left-to-right messages to\nthe right-to-left direction, which reverses the order of the characters in the\noriginal message. The AR (XB) pseudolocale is shown in figure 2.\n\nPseudolocales can help you make an RTL version of your app, even if you don't\nwrite or speak any RTL languages.\n\nEnable pseudolocales\n--------------------\n\nPseudolocales are usually added to developer-oriented builds. When you choose a\npseudolocale on your device, all the apps that support pseudolocales take on\nthe characteristics of the selected pseudolocale, including all the system apps\nsuch as the Settings app and Quick Settings panel.\n\n\u003cbr /\u003e\n\n\nTo use the Android pseudolocales, you must be running\nAndroid 4.3 (API level 18) or higher and have\n[developer options](/studio/debug/dev-options) enabled\non your device. You must also reboot your device after enabling\ndeveloper options.\n\nThe following procedure explains how to enable pseudolocales:\n\n1. In Android Studio, enable pseudolocales for a specific app by adding the\n following configuration to your `build.gradle` file:\n\n ### Groovy\n\n ```groovy\n android {\n ...\n buildTypes {\n debug {\n pseudoLocalesEnabled true\n }\n }\n }\n ```\n\n ### Kotlin\n\n ```kotlin\n android {\n ...\n buildTypes.getByName(\"debug\") {\n isPseudoLocalesEnabled = true\n }\n }\n ```\n2. [Build and run your app](/studio/run).\n\n **Figure 3.** Select a pseudolocale.\n3. Use the Settings app to select a pseudolocale. This step varies based on your\n Android version, as follows:\n\n **Android 5.0 (API level 21) or higher**\n 1. On the device, open the Settings app and tap **Languages and input \\\u003e\n Language preferences**.\n 2. In the **Language preferences** list, drag the tab to move a pseudolocale to the top of the list and make it the active language. See figure 3.\n\n **Android 4.4.4 (API level 19) or lower**\n 1. On the device, open the Settings app and tap **Languages and input \\\u003e\n Language preferences \\\u003e Add a language**.\n 2. Tap a pseudolocale to add it to the **Language preferences** list.\n 3. In the **Language preferences** list, drag the tab to move a pseudolocale to the top of the list and make it the active language See figure 3.\n\nSpot localization issues\n------------------------\n\nPseudolocales provide a time-saving and effective way to spot potential\nlocalizability issues in the UI by helping you identify problems in the\nfollowing areas:\n\n- Hardcoded strings, which can't be sent to translation, display as unaccented text in the pseudolocale to make them noticeable.\n- UI layout issues caused by text expansion, showing where the UI can break due to text length.\n- String concatenation, which displays as one message split across two or\n more brackets. This can make correct translation difficult, because translators\n have to translate each part independently without knowing that the parts\n are related. String concatenation can also make correct translation impossible,\n because different\n languages might require a different order of parts or a completely different\n sentence structure. For example, languages such as Japanese, Korean, and\n Tamil place the verb at the end of a sentence. When a sentence is concatenated,\n translators can't change the word order as needed.\n\n- Bidirectional (BIDI) text problems, such as when content in one text\n direction\n includes an inline phrase in the opposite text direction, making the string\n difficult to read.\n\n- Right-to-left (RTL) problems, such as elements not being mirrored. Some examples are\n a UI element not moving to the left, text not reversing and moving to the\n left, or misplaced punctuation, such as \"pseudolocales rule!\" changing to\n \"elur selacoloduesp!\" instead of \"!elur selacoloduesp\"."]]