This repository has been archived by the owner on Jun 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 330
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1877123 - Fix number localization in
TabCounter
and TabTools
- Loading branch information
1 parent
4dd7c2d
commit b044163
Showing
4 changed files
with
60 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
fenix/app/src/main/java/org/mozilla/fenix/compose/ext/Int.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
package org.mozilla.fenix.compose.ext | ||
|
||
import androidx.compose.ui.text.intl.Locale | ||
import java.text.NumberFormat | ||
import java.util.Locale as JavaLocale | ||
|
||
/** | ||
* Returns a localized string representation of the value. | ||
*/ | ||
fun Int.toLocaleString(): String = | ||
NumberFormat.getNumberInstance(JavaLocale(Locale.current.language)).format(this) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
fenix/app/src/test/java/org/mozilla/fenix/compose/ext/IntTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
package org.mozilla.fenix.compose.ext | ||
|
||
import org.junit.Assert.assertEquals | ||
import org.junit.Test | ||
import java.util.Locale as JavaLocale | ||
|
||
class IntTest { | ||
|
||
@Test | ||
fun `WHEN the language is Arabic THEN translate the number to the proper symbol of that locale`() { | ||
val expected = "٥" | ||
val numberUnderTest = 5 | ||
|
||
JavaLocale.setDefault(JavaLocale("ar")) | ||
|
||
assertEquals(expected, numberUnderTest.toLocaleString()) | ||
} | ||
|
||
} |