khmer_intl 0.1.1
khmer_intl: ^0.1.1 copied to clipboard
Khmer (km) internationalization helpers for Flutter/Dart: Khmer digits, date, currency and locale utilities.
khmer_intl #
Khmer (km) internationalization helpers for Dart and Flutter.
khmer_intl gives you Khmer-friendly formatting utilities for digits, numbers, currency, dates, relative time, plural selection, and an approximate lunar date model.
Preview #
[Preview 1] [Preview 2]
Features #
- Latin digit -> Khmer digit conversion (
123->១២៣) - Khmer digit -> Latin digit conversion
- Number formatting and KHR currency formatting (
៛) - Compact number formatting (e.g.
1.3លាន) - Compact currency formatting (e.g.
៛ 1.2M,៛ ១.២លាន) - Percent formatting
- Khmer date formatting with month/weekday names
- Buddhist Era year option (
AD + 543) - Date preset constructors (
shortDate,mediumDate,fullDate,fullDateTime,dateTime,time) - Khmer relative time (e.g.
២ ម៉ោងមុន) - Simple plural helper
- Structured plural helper with templates (
KhmerPlural.of) - Approximate Khmer lunar date model
- Number-to-Khmer words conversion (
1250->មួយពាន់ពីររយហាសិប) - Extension methods for
int,num,String, andDateTime
Installation #
dependencies:
khmer_intl: ^0.1.1
Then run:
dart pub get
or (Flutter):
flutter pub get
Quick Start #
import 'package:khmer_intl/khmer_intl.dart';
Digits #
toKhmerDigits('1234567890');
// ១២៣៤៥៦៧៨៩០
'123'.toKhmerDigits();
// ១២៣
'១២៣'.toLatinDigits();
// 123
Number and Currency #
2500.toKhmerCurrency(useKhmerDigits: true);
// ៛២,៥០០
1250000.toKhmerCompact(useKhmerDigits: true);
// ១.៣លាន
0.275.toKhmerPercent(useKhmerDigits: true, fractionDigits: 1);
// ២៧.៥%
KhmerNumberFormat.compactCurrency().format(1200000);
// ៛ 1.2M
KhmerNumberFormat.compactCurrency(
khmerStyle: true,
useKhmerDigits: true,
).format(1200000);
// ៛ ១.២លាន
Date Formatting #
final date = DateTime(2026, 4, 14);
KhmerDateFormat('EEE dd MMMM yyyy', buddhistEra: true, useKhmerDigits: true)
.format(date);
// អង្គារ ១៤ ខែមេសា ២៥៦៩
KhmerDateFormat.fullDate(buddhistEra: true, useKhmerDigits: true).format(date);
KhmerDateFormat.fullDateTime(useKhmerDigits: true).format(DateTime.now());
KhmerDateFormat.dateTime(useKhmerDigits: true).format(DateTime.now());
KhmerDateFormat.time(useKhmerDigits: true).format(DateTime.now());
Relative Time #
final now = DateTime.now();
final past = now.subtract(const Duration(hours: 2));
past.toKhmerRelativeTime(reference: now, useKhmerDigits: true);
// ២ ម៉ោងមុន
KhmerRelativeTime.format(now, reference: now);
// ឥឡូវនេះ
KhmerRelativeTime.format(now.subtract(const Duration(days: 1)), reference: now);
// ម្សិលមិញ
KhmerRelativeTime.format(now.subtract(const Duration(days: 5)), reference: now);
// មុន 5 ថ្ងៃ
Plural Helper #
khmerPlural(
2,
one: 'មានទំនិញ 1 មុខ',
other: 'មានទំនិញ 2 មុខ',
);
KhmerPlural.of(
count: 2,
one: '{count} ឯកតា',
other: '{count} ឯកតា',
);
// 2 ឯកតា
Number to Khmer Words #
numberToKhmerWords(1250);
// មួយពាន់ពីររយហាសិប
1250.toKhmerWords();
// មួយពាន់ពីររយហាសិប
Lunar Date (Approximate) #
final lunar = KhmerLunarDate.fromGregorian(DateTime.now());
print(lunar);
Core APIs #
Top-level functions #
toKhmerDigits(String input)toLatinDigits(String input)khmerPlural(num count, {required String one, required String other})
Formatters #
KhmerNumberFormat.decimal(...)KhmerNumberFormat.currencyKHR(...)KhmerNumberFormat.compact(...)KhmerNumberFormat.percent(...)KhmerCompactNumberFormat(...)KhmerPercentFormat(...)KhmerDateFormat(pattern, ...)KhmerDateFormat.shortDate(...)KhmerDateFormat.mediumDate(...)KhmerDateFormat.fullDate(...)KhmerDateFormat.fullDateTime(...)KhmerDateFormat.dateTime(...)KhmerDateFormat.time(...)KhmerRelativeTime.format(...)
Extensions #
int.toKhmerDigits()String.toKhmerDigits()String.toLatinDigits()num.toKhmerCurrency(...)num.toKhmerCompact(...)num.toKhmerPercent(...)DateTime.toKhmerDate(...)DateTime.toKhmerRelativeTime(...)
Flutter LocalizationsDelegate #
A working Khmer LocalizationsDelegate example is included in:
example/lib/khmer_localizations.dartexample/lib/main.dart
localizationsDelegates: const [
KhmerLocalizations.delegate,
]
Notes #
- Khmer lunar support is currently approximate (starter implementation).
- Compact/percent styles are designed to be practical and lightweight.
Testing #
dart test
License #
MIT
Sponsor Me #
If you find my projects helpful and want to support my work, you can sponsor me! 💖