使用虛擬語言代碼測試應用程式
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
虛擬語言代碼是一種語言代碼,用於模擬在翻譯應用程式時,會引發使用者介面、版面配置和其他翻譯相關問題的語言特徵。虛擬語言代碼是由所有「可本地化」的訊息的即時自動翻譯 (以英文判讀) 建立。未經過虛擬本地化的文字會指向原始碼中無法翻譯的訊息。
虛擬語言代碼可以節省時間和成本,因為您可以先調整 UI 文字及其版面配置,然後再將訊息提交至之後要送交翻譯的原始碼存放區。如需潛在翻譯問題的清單,請參閱「找出本地化問題」一節。
圖 1. 英文 (XA) 虛擬語言代碼。
Android 虛擬語言代碼名稱遵循標準的語言代碼命名慣例,且其語言代碼 ID 可由任何符合 BCP 47 規定的程式設計語言剖析。就這點而言,虛擬語言代碼就和任何其他語言代碼一樣,例如法文、中文或俄文。
Android 平台提供下列兩種虛擬語言代碼,代表文字方向從左到右 (LTR) 和從右到左 (RTL) 的語言:
圖 2. AR (XB) 虛擬語言代碼。
英文 (XA):在基礎英文 UI 文字中加入拉丁文重音符號,透過加入無重音符號的文字擴展原始文字內容,並且為每個訊息單元加上括號,以從擴展的文字內容中找出潛在問題。潛在問題可能是版面配置未完整顯示和訊息語法格式不佳,例如同一個句子分割為多段由括號括住的訊息。英文 (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 所示。
找出本地化問題
虛擬語言代碼可協助辨識以下方面的問題,方便您找出 UI 中潛在的本地化問題,省時又省力:
- 無法提交翻譯的硬式編碼字串。這類字串會在虛擬語言代碼中以無重音符號的文字形式顯示,以便找出這類字串。
- 因文字內容擴展導致的 UI 版面配置問題。虛擬語言代碼中會顯示 UI 可能因文字長度而中斷的位置。
字串串連,將一段訊息顯示為兩段以上由括號括住的分割片段。這可能會使譯者難以提供正確翻譯,因為他們必須分別翻譯每個片段,但不知道這些片段彼此相關。字串串連也可能使譯者無法提供正確翻譯,因為不同語言可能需使用不同的段落順序,或截然不同的語句結構。舉例來說,日文、韓文和泰米爾文等語言會將動詞置於句尾。如果將句子串連,譯者會無法視需要變更字詞順序。
雙向 (BIDI) 文字問題,例如一種文字方向的內容中含有文字方向相反的內嵌詞組,導致字串難以閱讀。
從右到左 (RTL) 的問題,例如元素未鏡像顯示。相關例子包括 UI 元素未移至左側、文字並未對調方向並移至左側,或標點符號放錯位置,例如「pseudolocales rule!」變更為「elur selacoloduesp!」而非「!elur selacoloduesp」。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-07-27 (世界標準時間)。
[null,null,["上次更新時間: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\"."]]