Internationalisation and localisation in mobile applications involve far more than direct word translation. In highly inflected languages such as French, Spanish, German, Polish, Italian, and Arabic, sentence syntax and adjectives change dynamically based on the grammatical gender of the person being addressed or referred to (e.g., masculine, feminine, or neuter). Historically, developers had to construct awkward gender-neutral phrasing (such as slash-separated slurs or brackets) or build custom in-app profile gender toggles.
Starting with Android 14 (API level 34), Google introduced the Grammatical Inflection Framework and the system-level GrammaticalInflectionManager API. This framework allows users to declare their preferred grammatical gender system-wide or per-application, enabling apps to deliver grammatically accurate string resources automatically. System engineers and QA developers can use Android Debug Bridge (ADB) and the diagnostic service dumpsys grammar_inflection to inspect active gender states, verify package-level overrides, and debug localization flows.
Understanding Android Grammatical Inflection Architecture
The Android runtime supports three primary grammatical gender values defined within Configuration.java and the GrammaticalInflectionManager service:
GRAMMATICAL_GENDER_NOT_SPECIFIED(Value 0): The default neutral or fallback inflection state. Strings are resolved using standard default locale resources.GRAMMATICAL_GENDER_NEUTRAL(Value 1): Explicit gender-neutral phrasing, addressing the user without specific male or female inflection.GRAMMATICAL_GENDER_FEMININE(Value 2): Feminine grammatical inflection, matching feminine noun and adjective agreements in target languages.GRAMMATICAL_GENDER_MASCULINE(Value 3): Masculine grammatical inflection, matching masculine agreements.
At runtime, the GrammaticalInflectionService runs inside the Android system_server. When an application requests string resources or when the user changes gender preferences in Settings > System > Languages > Regional preferences, the service recalculates the asset configuration qualifiers (such as res/values-fr-feminine/strings.xml) and updates the process configuration without requiring a cold restart.
Connecting via ADB and Executing dumpsys grammar_inflection
Ensure USB Debugging is enabled on an Android 14 or later device, connect the phone to your computer, and verify detection:
adb devices
Execute the diagnostic dump for the grammatical inflection service:
adb shell dumpsys grammar_inflection
A typical diagnostic output displays system-wide gender settings and per-application configuration mappings:
GrammaticalInflectionManagerService:
System Grammatical Gender: 0 (NOT_SPECIFIED)
User ID: 0
com.example.messagingapp: 2 (FEMININE)
com.google.android.apps.photos: 0 (NOT_SPECIFIED)
com.example.shopping: 3 (MASCULINE)
Total package overrides: 2
Analysing System vs Per-App Grammatical Preferences
The diagnostic dump provides two critical tiers of information:
1. System Grammatical Gender
The top-level field System Grammatical Gender reports the system-wide default setting configured across the entire operating system. When an application has not explicitly set a per-app override, it inherits this system value. In Android 14+, users can select their preferred gender in system language settings, which applies across all participating applications on the device.
2. User ID and Package Overrides
Under each active User ID (e.g. User ID: 0 for the primary user, or secondary IDs for work profiles and guest accounts), the service lists individual package names that have invoked setRequestedApplicationGrammaticalGender(). This enables applications (such as social networks or email clients where users can choose distinct persona identities) to maintain app-specific grammatical preferences independently of the global system default.
Simulating and Overriding Grammatical Gender via ADB
During localisation QA testing, switching between system menus to test masculine, feminine, and neutral strings is slow and cumbersome. ADB provides direct commands to modify and verify grammatical inflection parameters programmatically.
Setting Per-App Grammatical Gender Overrides
To set the grammatical gender for a specific target package, use the cmd grammar_inflection shell command:
# Set package to Feminine (Value 2)
adb shell cmd grammar_inflection set-app-gender com.example.messagingapp 2
# Set package to Masculine (Value 3)
adb shell cmd grammar_inflection set-app-gender com.example.messagingapp 3
# Reset package back to Unspecified/System Default (Value 0)
adb shell cmd grammar_inflection set-app-gender com.example.messagingapp 0
Verifying Immediate Configuration Updates
After issuing the override command, execute dumpsys grammar_inflection to confirm the package has registered the new gender value:
adb shell dumpsys grammar_inflection | grep "com.example.messagingapp"
Simultaneously observe the target application’s active configuration using dumpsys activity:
adb shell dumpsys activity top | grep -i "mGrammaticalGender"
The output reveals the active grammatical gender qualifier bound to the foreground window: mGrammaticalGender=2.
Inspecting XML Resource Resolution and Asset Directories
To verify that an application correctly loads the targeted inflected resources, inspect how the APK structures its resource qualifiers:
values-es-feminine/strings.xml— Spanish strings addressed to female users.values-es-masculine/strings.xml— Spanish strings addressed to male users.values-es/strings.xml— Default fallback Spanish strings.
When the gender qualifier is set via ADB, the Android AssetManager automatically matches the qualified folder before falling back to the base language folder. You can trace resource lookups and verify that fallback logic does not trigger crash exceptions by inspecting logcat:
adb logcat -v time -s Resources:* GrammaticalInflectionManagerService:*
Troubleshooting Localization and Inflection Issues
If text strings fail to update or display unexpected agreements, check the following troubleshooting areas:
- Application Missing Dynamic Configuration Handling: If an app does not declare
android:configChanges="grammaticalGender"in itsAndroidManifest.xml, the Android system restarts the active Activity when the gender changes. If the activity fails to preserve state or drops UI inputs, ensure dynamic config handling or view-model state retention is implemented. - Permission Restrictions: Third-party apps can only modify their own grammatical gender. Only system applications possessing the
android.permission.CHANGE_CONFIGURATIONpermission can alter global system gender settings. - Cached String Resources: If string templates formatted with
MessageFormator custom formatting engines do not update, ensure the app invalidates in-memory string caches upon receivingonConfigurationChanged().