Skip to content

[BadgeDrawable] Cannot set locale to badgedrawable. Taking application locale for default translation of number #2465

@hiteshsarsava

Description

@hiteshsarsava

Description: When change the language of the App. The number format also gets translated into that selected language. I have issue where i want to keep the language of app in Arabic but number on badgeDrawable want to in English. As in below snippet, the NumberFormat.getInstance().format(getNumber()) taking the default locale. Developer can not set there any locale.

Expected behavior: Expected behavior is keep in english as that are numbers

Source code:

@NonNull
  private String getBadgeText() {
    // If number exceeds max count, show badgeMaxCount+ instead of the number.
    if (getNumber() <= maxBadgeNumber) {
      return NumberFormat.getInstance().format(getNumber());
    } else {
      Context context = contextRef.get();
      if (context == null) {
        return "";
      }

      return context.getString(
          R.string.mtrl_exceed_max_badge_number_suffix,
          maxBadgeNumber,
          DEFAULT_EXCEED_MAX_BADGE_NUMBER_SUFFIX);
    }
  }

Android API version: Android API 29

Material Library version: com.google.android.material:material:1.5.0-alpha05

Device: Pixel

To help us triage faster, please check to make sure you are using the latest version of the library.

We also happily accept pull requests.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions