Skip to content

fix: using Arabic numbers instead of Urdu numbers in Arabic localization#53

Merged
nixrajput merged 3 commits intonixrajput:masterfrom
Monder232:fix-arabic-numbers
Mar 18, 2026
Merged

fix: using Arabic numbers instead of Urdu numbers in Arabic localization#53
nixrajput merged 3 commits intonixrajput:masterfrom
Monder232:fix-arabic-numbers

Conversation

@Monder232
Copy link
Copy Markdown
Contributor

@Monder232 Monder232 commented Mar 8, 2026

Pull Request Checklist

What does this PR do?

  • Fixes incorrect numeral usage in Arabic localization by replacing Urdu numbers with proper Arabic numerals
  • Adds a new convertToArabicNumbers() utility function to correctly format Arabic time messages
  • Updates all Arabic message methods to use the correct Arabic numeral system (٠-٩) instead of Urdu numerals

Checklist

Code Changes

  • I have fixed existing issues (e.g., incorrect formatting, performance bottlenecks)

Documentation

  • I have updated the README file or relevant documentation with the changes
  • I have added code usage examples or updated existing examples to reflect changes
  • I have updated the package version in the pubspec.yaml file

Testing

General Tests

  • The package correctly formats time differences into human-readable strings
  • The package supports dynamic updates (e.g., changing locales, thresholds)

Localization

  • The package supports all documented languages
  • Custom locales can be added and work as expected
  • Language fallback works correctly if a specific locale is missing

Custom Thresholds

  • Custom time thresholds are applied correctly
  • The package handles edge cases like just now, future dates, or extreme past dates

Error Handling

  • The package handles null or invalid inputs gracefully
  • Fallback behavior works for unexpected or incorrect configurations

Responsiveness

  • The package adapts to time-zone differences accurately
  • The formatting responds correctly to locale changes in the app

Performance

  • The package performs efficiently, even when processing frequent or large updates
  • Performance tests show no regressions

How did you verify your code works?

  • I have verified that the Arabic localization now correctly uses Arabic numerals (٠-٩) instead of Urdu numerals
  • I tested the convertToArabicNumbers() function with various input numbers to ensure proper conversion
  • I manually verified that all Arabic time messages (seconds, minutes, hours, days) now display with the correct numeral system
  • The changes maintain backward compatibility while fixing the numeral display issue for Arabic users

Summary by CodeRabbit

  • New Features
    • Improved Arabic localization: relative time messages (seconds, minutes, hours, days) now display Arabic‑Indic digits.
    • Added a public utility to convert Western digits to Arabic‑Indic numerals, ensuring consistent Arabic number formatting.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 8, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 10e630ea-ceca-4453-845c-aef1705ada37

📥 Commits

Reviewing files that changed from the base of the PR and between b85fb7d and b385c70.

📒 Files selected for processing (1)
  • test/messages/language/ar_msg_test.dart

📝 Walkthrough

Walkthrough

Adds a new convertToArabicNumbers() utility, switches four Arabic time-ago message builders to use it instead of the Urdu converter, and updates tests to expect Arabic‑Indic digits; only numeric rendering changed, Arabic text and control flow unchanged.

Changes

Cohort / File(s) Summary
Numeral Conversion Utility
lib/src/utils/utility.dart
Added public function convertToArabicNumbers(int input) that maps ASCII digits 0–9 to Arabic‑Indic digits (٠–٩).
Arabic Message Localization
lib/src/messages/languages/ar_msg.dart
Replaced convertToUrduNumbers(...) with convertToArabicNumbers(...) in four time‑ago builders: secsAgo, minsAgo, hoursAgo, daysAgo.
Tests Updated
test/messages/language/ar_msg_test.dart
Updated expected strings to use Arabic‑Indic digits (٠–٩) in relative time and date assertions.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 I hopped through digits, quick and bright,
Swapped 0–9 for ٠–٩ by moonlight,
Arabic ticks now count just right,
A tiny nibble, neat and light.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: fixing Arabic localization to use Arabic numbers instead of Urdu numbers, which aligns with the substantial modifications across message builders and utility functions.
Description check ✅ Passed The description covers the main changes (fixing numeral usage, adding convertToArabicNumbers function, updating message methods) and includes verification details; however, it lacks updates for README, examples, and package version, which are listed as unchecked in the template.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Tip

You can disable sequence diagrams in the walkthrough.

Disable the reviews.sequence_diagrams setting to disable sequence diagrams in the walkthrough.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
lib/src/utils/utility.dart (1)

32-49: Consider extracting a shared helper to reduce duplication.

Both convertToUrduNumbers and convertToArabicNumbers share identical logic, differing only in the target digit array. A shared helper could reduce duplication if more numeral systems are added in the future.

♻️ Optional refactor
/// Generic digit conversion helper
String _convertToDigits(int input, List<String> targetDigits) {
  const english = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
  var result = input.toString();
  for (var i = 0; i < english.length; i++) {
    result = result.replaceAll(english[i], targetDigits[i]);
  }
  return result;
}

String convertToUrduNumbers(int input) =>
    _convertToDigits(input, ['۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹']);

String convertToArabicNumbers(int input) =>
    _convertToDigits(input, ['٠', '١', '٢', '٣', '٤', '٥', '٦', '٧', '٨', '٩']);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/src/utils/utility.dart` around lines 32 - 49, Both convertToArabicNumbers
and convertToUrduNumbers duplicate the same digit-replacement logic; extract a
shared helper (e.g., _convertToDigits) that takes the input int and a
targetDigits List<String>, move the english digits array and replacement loop
into that helper, and update convertToArabicNumbers and convertToUrduNumbers to
call _convertToDigits with their respective target digit arrays to remove
duplication and centralize the conversion logic.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@lib/src/utils/utility.dart`:
- Around line 42-48: The comments in the digit-replacement loop and return
statement incorrectly reference "Urdu"; update those comments to say "Arabic" so
they accurately describe the function that replaces English digits with Arabic
digits (references: the loop using english and arabic arrays and the return
statement returning result).

---

Nitpick comments:
In `@lib/src/utils/utility.dart`:
- Around line 32-49: Both convertToArabicNumbers and convertToUrduNumbers
duplicate the same digit-replacement logic; extract a shared helper (e.g.,
_convertToDigits) that takes the input int and a targetDigits List<String>, move
the english digits array and replacement loop into that helper, and update
convertToArabicNumbers and convertToUrduNumbers to call _convertToDigits with
their respective target digit arrays to remove duplication and centralize the
conversion logic.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d89ef9c4-5e63-495c-aef7-ab46833a56d9

📥 Commits

Reviewing files that changed from the base of the PR and between fc6275f and 676b0a5.

📒 Files selected for processing (2)
  • lib/src/messages/languages/ar_msg.dart
  • lib/src/utils/utility.dart

Comment thread lib/src/utils/utility.dart Outdated
Updated the convertToArabicNumbers function to correctly replace English digits with Arabic counterparts.
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
lib/src/utils/utility.dart (1)

27-49: Extract the shared digit-conversion loop.

convertToArabicNumbers() is now a near copy of convertToUrduNumbers(). Pulling the common logic into a private helper would reduce drift and make future numeral-localization fixes cheaper.

♻️ Proposed refactor
+String _convertDigits(int input, List<String> localizedDigits) {
+  const english = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
+
+  var result = input.toString();
+  for (var i = 0; i < english.length; i++) {
+    result = result.replaceAll(english[i], localizedDigits[i]);
+  }
+
+  return result;
+}
+
 String convertToUrduNumbers(int input) {
-  // List of English digits
-  const english = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
-
-  // List of corresponding Urdu digits
   const urdu = ['۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹'];
-
-  // Convert the input number to a string
-  var result = input.toString();
-
-  // Replace each English digit with its Urdu counterpart
-  for (var i = 0; i < english.length; i++) {
-    result = result.replaceAll(english[i], urdu[i]);
-  }
-
-  // Return the result with Urdu digits
-  return result;
+  return _convertDigits(input, urdu);
 }
 
 String convertToArabicNumbers(int input) {
-  // List of English digits
-  const english = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
-
-  // List of corresponding Arabic digits
   const arabic = ['٠', '١', '٢', '٣', '٤', '٥', '٦', '٧', '٨', '٩'];
-
-  // Convert the input number to a string
-  var result = input.toString();
-
-  // Replace each English digit with its Arabic counterpart
-  for (var i = 0; i < english.length; i++) {
-    result = result.replaceAll(english[i], arabic[i]);
-  }
-
-  // Return the result with Arabic digits
-  return result;
+  return _convertDigits(input, arabic);
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/src/utils/utility.dart` around lines 27 - 49, The digit-replacement loop
in convertToArabicNumbers is duplicated in convertToUrduNumbers; extract that
shared logic into a private helper (e.g., _convertDigits or _replaceDigits) that
accepts the input string/number and the two digit lists/maps (english and
target) and returns the replaced string, then update convertToArabicNumbers and
convertToUrduNumbers to convert input to string and delegate to this helper;
ensure the helper is used by both functions and preserve current behavior and
return types.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@lib/src/utils/utility.dart`:
- Around line 27-49: The digit-replacement loop in convertToArabicNumbers is
duplicated in convertToUrduNumbers; extract that shared logic into a private
helper (e.g., _convertDigits or _replaceDigits) that accepts the input
string/number and the two digit lists/maps (english and target) and returns the
replaced string, then update convertToArabicNumbers and convertToUrduNumbers to
convert input to string and delegate to this helper; ensure the helper is used
by both functions and preserve current behavior and return types.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3e7d39aa-e35f-4082-bf91-17aa3f252deb

📥 Commits

Reviewing files that changed from the base of the PR and between 676b0a5 and b85fb7d.

📒 Files selected for processing (1)
  • lib/src/utils/utility.dart

Copy link
Copy Markdown
Owner

@nixrajput nixrajput left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check and fix failing test cases correctly

@nixrajput nixrajput changed the title fix:fix using Urdu numbers instead of Arabic numbers in Arabic localization fix: using Urdu numbers instead of Arabic numbers in Arabic localization Mar 9, 2026
@Monder232 Monder232 changed the title fix: using Urdu numbers instead of Arabic numbers in Arabic localization fix: using Arabic numbers instead of Urdu numbers in Arabic localization Mar 18, 2026
@Monder232 Monder232 requested a review from nixrajput March 18, 2026 12:28
@nixrajput nixrajput merged commit 5e9e0df into nixrajput:master Mar 18, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants