30 億人使用性別化語言:即名詞、動詞、形容詞和介系詞會隨著交談或談論對象或目標的性別,而有不同變化形式的文法類別語言。一般來說,許多性別化語言都會使用陽性文法性別做為預設或通用性別。
若以錯誤的文法性別稱呼使用者,例如:以陽性文法性別稱呼女性,可能會對其表現及態度產生負面影響。相較之下,如果使用者介面的用語正確反映了使用者的文法性別,便可提高使用者參與度,同時提供更個人化且更自然親切的使用者體驗。
To help you build a user-centric UI for gendered languages, Android 14 introduces the Grammatical Inflection API, which lets you add support for grammatical gender without refactoring your app.
Example of inflection for grammatical gender
In gendered languages, grammatical gender can't be worked around the same way as it can in English. For example, in English to write a message telling the user that they are subscribed to your app's service, you could use a single phrase: "You are subscribed to...".
To provide a similar phrase in French, there are a few options:
- Masculine-inflected form: "Vous êtes abonné à..." (English: "You are subscribed to...")
- Feminine-inflected form: "Vous êtes abonnée à..." (English: "You are subscribed to...")
- Neutral phrasing that avoids inflection: "Abonnement à...activé" (English: "Subscription to ... enabled")
Similar to English, the first two options address the user directly. However, without any mechanism to accommodate this grammatical feature of French, you would only have the third option, which changes the tone of the message and might not be what you want to display in your user interface.
In these cases, the Grammatical Inflection API lowers the effort to display
strings relative to the viewer's grammatical gender—that is, the person who's
viewing the UI, not who's being talked about. To show users personalized
translations in your app, add translations that are inflected for each
grammatical gender for affected languages and then use the
GrammaticalInflectionManager
API to adjust which translations are shown
to each user.
In many languages, grammatical gender also applies to regular nouns in addition to people. For example, in French the word chaise (chair) is feminine, whereas oiseau (bird) is masculine. For situations other than addressing the user, you can use the existing ICU SelectFormat API.
Implement the API
After the user has indicated their grammatical gender (for example, either
through a settings section of your app or a user setup workflow), you can use
the setRequestedApplicationGrammaticalGender(int)
method to store the
value in your app's resources configuration.
For example, if you want to set a user's preferred grammatical gender to feminine, you would ask the user to select which grammatical gender they prefer and then call the API:
Kotlin
// Set app's grammatical gender to feminine val gIM = mContext.getSystemService(GrammaticalInflectionManager::class.java) gIM.setRequestedApplicationGrammaticalGender( Configuration.GRAMMATICAL_GENDER_FEMININE)
Java
// Set app's grammatical gender to feminine GrammaticalInflectionManager gIM = mContext.getSystemService(GrammaticalInflectionManager.class); gIM.setRequestedApplicationGrammaticalGender( Configuration.GRAMMATICAL_GENDER_FEMININE);
Here is example of how to declare configuration changes in your app's manifest file if you want to handle them yourself:
<activity android:name=".TestActivity"
android:configChanges="grammaticalGender"
android:exported="true">
</activity>
If your app needs to check the grammatical gender in the current resource
configuration, you can use the getApplicationGrammaticalGender()
method
to retrieve it:
Kotlin
val gIM = mContext.getSystemService(GrammaticalInflectionManager::class.java) val grammaticalGender = gIM.getApplicationGrammaticalGender()
Java
GrammaticalInflectionManager gIM = mContext.getSystemService(GrammaticalInflectionManager.class); int grammaticalGender = gIM.getApplicationGrammaticalGender();
Add translations for languages with grammatical gender
To provide localized text for languages with grammatical gender, create an alternative resources file and append the grammatical gender qualifier immediately after the locale name for those languages. The following table outlines the possible values:
Qualifier | String value | Example (French fr ) |
---|---|---|
Feminine | feminine |
res/values-fr-feminine/strings.xml |
Masculine | masculine |
res/values-fr-masculine/strings.xml |
Neuter | neuter |
res/values-fr-neuter/strings.xml |
You should only include strings that support grammatical gender inflections in these resources files. All strings must have a value in the default resource file that contains other localized strings. This default translation is shown whenever a gender-inflected translation is not available.
In the example provided for French earlier, the neutral phrasing would be
the value of the string in the default resources res/values-fr/strings.xml
file. The following code snippets show how each resource file would be formatted
to accommodate all the grammatical variations from the example in French:
Feminine
Include the feminine-inflected string in the res/values-fr-feminine/strings.xml
resources file:
<resources> ... <string name="example_string">Vous êtes abonnée à...</string> </resources>
Masculine
Include the masculine-inflected string in the res/values-fr-masculine/strings.xml
resources file:
<resources> ... <string name="example_string">Vous êtes abonné à...</string> </resources>
Neuter
Include the default string in the res/values-fr/strings.xml
resources file:
<resources> ... <string name="example_string">Abonnement à...activé</string> </resources>