Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/src/messages/languages/ar_msg.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ArabicMessages extends Messages {

/// Message for when the elapsed time is less than a minute.
@override
String secsAgo(int seconds) => '${convertToUrduNumbers(seconds)} ثوان';
String secsAgo(int seconds) => '${convertToArabicNumbers(seconds)} ثوان';

/// Message for when the elapsed time is about a minute.
@override
Expand All @@ -31,7 +31,7 @@ class ArabicMessages extends Messages {
if (minutes == 2) {
return 'دقيقتين';
}
return '${convertToUrduNumbers(minutes)} دقائق';
return '${convertToArabicNumbers(minutes)} دقائق';
}

/// Message for when the elapsed time is about an hour.
Expand All @@ -44,7 +44,7 @@ class ArabicMessages extends Messages {
if (hours == 2) {
return 'ساعتين';
}
return '${convertToUrduNumbers(hours)} ساعات';
return '${convertToArabicNumbers(hours)} ساعات';
}

/// Message for when the elapsed time is about a day.
Expand All @@ -57,7 +57,7 @@ class ArabicMessages extends Messages {
if (days == 2) {
return 'يومين';
}
return '${convertToUrduNumbers(days)} أيام';
return '${convertToArabicNumbers(days)} أيام';
}

/// Word separator to be used when joining the parts of the message.
Expand Down
24 changes: 24 additions & 0 deletions lib/src/utils/utility.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,30 @@ String convertToUrduNumbers(int input) {
return result;
}

/// Utility function [convertToArabicNumbers] to convert an English number
/// into its Arabic numeral equivalent.
/// The function takes an integer [input] and replaces its English digits
/// (0-9) with corresponding Arabic digits.
/// Example: 123 -> '١٢٣'
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 Urdu counterpart
for (var i = 0; i < english.length; i++) {
result = result.replaceAll(english[i], arabic[i]);
}

// Return the result with Urdu digits
return result;
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
}

/// Helper method [formatMessage] to format a time message by combining the
/// [prefix], [msg] (main message), and [suffix]. The method concatenates the
/// non-empty parts of the message using the [Messages.wordSeparator()] to join them.
Expand Down