Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 1.7.0
* Implement the `ILibScriptInfo` class for ScriptInfomation
* Add new methods to `ILibLocaleInfo`:
`getLanguageName()`, `getRegionName()`, `getClock()`, `getLocale()`, `getUnits()`, `getCalendar()`, `getTimeZone()`, `getPrimaryGroupingDigits()`, `getSecondaryGroupingDigits()`, `getPercentageSymbol()`, `getExponential()`, `getNativeExponential()`, `getNativePercentageSymbol()`, `getNegativeNumberFormat()`, `getDigitsStyle()`, `getDigits()`, `getNativeDigits()`, `getRoundingMode()`, `getScript()`, `getDefaultScript()`, `getAllScripts()`, `getMeridiemsStyle()`, `getPaperSize()`, `getDelimiterQuotationStart()`, `getDelimiterQuotationEnd()`
* Implement `ILibLocale`
* Implement `ILibCaseMapper`

## 1.6.0
* Implement the `ILibNumFmt` class to enable NumberFormatting
* Add new methods for NumberFormatting to `ILibLocaleInfo`:
Expand Down
72 changes: 72 additions & 0 deletions Docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,36 @@ ILibDurationFmt(ILibDurationFmtOptions options)


# LocaleInfo
## ILibLocale
### Properties
|name|description|
|------|---|
|_Object?_ language|The ISO 639 2-letter code for the language, or a full locale spec in BCP-47 format, or another `ILibLocale` instance to copy from.|
|_String?_ script|The ISO 15924 code of the script for this locale, if any.|
|_String?_ variant|The name of the variant of this locale, if any.|
|_String?_ region|The ISO 3166 2-letter code for the region.|

### Constructors
```dart
ILibLocale([Object? language, String? region, String? variant, String? script])
```

### Methods
|name|description|
|------|---|
|_String_ getLanguage()|Return the ISO 639 language code of the locale.|
|_String?_ getLanguageAlpha3()|Return the ISO 639-3 language code of the locale.|
|_String?_ getScript()|Return the ISO 15924 script code of the locale.|
|_String?_ getRegion()|Return the ISO 3166 region code of the locale.|
|_String?_ getRegionAlpha3()|Return the ISO 3166-3 region code of the locale.|
|_String?_ getVariant()|Return the variant code of the locale.|
|_String_ getSpec()|Return the full locale specifier as a string.|
|_String_ getLangSpec()|Return the language and script specifier of the locale.|
|_bool_ equals(ILibLocale other)|Check if another locale is exactly equal to this one.|
|_bool_ isPseudo()|Check if the locale is a pseudo-locale. Pseudo-locales are used for testing localization.|
|_bool_ isValid()|Check if the locale uses valid ISO codes for its components. Validates language, script, and region codes.|


## ILibLocaleInfo
### Properties
|name|description|
Expand Down Expand Up @@ -198,3 +228,45 @@ ILibNumFmt(ILibNumFmtOptions options)
|_String_ getRoundingMode()| Returns the rounding mode set up in the constructor. |
|_String_ getStyle()| Returns the style used to construct this number formatter object. |
|_bool_ getUseNative()| Returns true if this formatter uses native digits to format the number. |

# ScriptInfo
## ILibScriptInfo
### Properties
|name|description|
|------|---|
|_String?_ script|The ISO 15924 4-letter identifier for the script.|

### Constructors
```dart
ILibScriptInfo(String script)
```

### Methods
|name|description|
|------|---|
|_String?_ getCode()|Return the 4-letter ISO 15924 identifier associated with this script.|
|_int?_ getCodeNumber()|Get the ISO 15924 code number associated with this script.|
|_String?_ getName()|Get the name of this script in English.|
|_String?_ getLongCode()|Get the long identifier associated with this script.|
|_String_ getScriptDirection()|Return the usual direction that text in this script is written in. Possible values: "rtl", "ltr", "ttb".|
|_bool_ getNeedsIME()|Return true if this script typically requires an input method engine to enter its characters.|
|_bool_ getCasing()|Return true if this script uses lower- and upper-case characters.|

# CaseMapper
## ILibCaseMapper
### Properties
|name|description|
|------|---|
|_String?_ locale|The locale to use for case mapping. Defaults to the system locale if not provided.|
|_String?_ direction|Indicates whether the mapper is set to convert to uppercase (`true`) or lowercase (`false`).|

### Constructors
```dart
ILibCaseMapper({String? locale, String? direction})
```

### Methods
|name|description|
|------|---|
|_ILibLocale_ getLocale()|Returns the locale used by this mapper.|
|_String?_ map(String? string)|Maps a string to uppercase or lowercase in a locale-sensitive manner.|
65 changes: 56 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ locInfo.getCurrencyFormats().common;
// {s}{n}
locInfo.getCurrency();
// 'KRW'

final ILibLocale locale = locInfo.getLocale();
locale.getLanguage();
// 'ko'
```

### Number Formatting
Expand All @@ -153,6 +157,29 @@ fmt.format(-1234567.89);
// '-$1,234,567.89'
```

## ScriptInfo
```dart
final ILibLocaleInfo locInfo = ILibLocaleInfo('en-US');
final ILibScriptInfo scInfo = ILibScriptInfo(locInfo.getScript());
scInfo.getCode();
//'Latn'
scInfo.getName();
// 'Latin'
scInfo.getScriptDirection();
// 'ltr'
```

## CaseMapper
``` dart
final ILibCaseMapper mapper = ILibCaseMapper(locale: 'tr-TR');
mapper.map('ıi');
// 'Iİ'
final ILibCaseMapper mapper = ILibCaseMapper(
locale: 'tr-TR', direction: 'tolower');
mapper.map('Iİ');
// 'ıi'
```

## CLASS

### FlutterILib
Expand All @@ -166,31 +193,51 @@ _flutterIlibPlugin.evaluateILib(jscode1);
// 'ethiopic'
```
To give a more efficient way, we provide some classes that can be easily used in a Flutter app.
Currently, We have a `ILibDateFmt` , `ILibLocaleInfo` and `ILibDurationFmt` classes.
We have a plan to provide more classes and methods.
Currently, we have the following classes:
- `ILibCaseMapper`
- `ILibDateFmt`
- `ILibDateOptions`
- `ILibDurationFmt`
- `ILibLocale`
- `ILibLocaleInfo`
- `ILibNumFmt`
- `ILibScriptInfo`

### ILibDate
- Class: [ILibDateOptions](./Docs.md/#ilibdateoptions)
We have a plan to provide more classes and methods.

### ILibDateFmt
- Class: [ILibDateFmtOptions](./Docs.md/#ilibdatefmtoptions)
- Class: [ILibDateFmtOptions](./Docs.md/#ilibdatefmtoptions)
- Class: [ILibDateFmt](./Docs.md#ilibdatefmt)
- Methods: `format()`, `getClock()`, `getTemplate()`, `getMeridiemsRange()`

### ILibLocaleInfo
- Class: [ILibLocaleInfo](./Docs.md/#iliblocaleinfo)
- Methods: `getFirstDayOfWeek()`, `getWeekEndStart()`, `getWeekEndStart()`, `getDecimalSeparator()`, `getGroupingSeparator()`, `getPercentageFormat()`, `getNegativePercentageFormat()`,`getCurrency()`, `getCurrencyFormats()`

### ILibDurationFmt
- Class: [ILibDurationFmtOptions](./Docs.md/#ilibdurationfmtoptions)
- Class: [ILibDurationFmt](./Docs.md/#ilibdurationfmt)
- Methods: `format()`, `getLocale()`, `getStyle()`, `getLength()`

### ILibDateOptions
- Class: [ILibDateOptions](./Docs.md/#ilibdateoptions)

### ILibLocale
- Class: [ILibLocale](./Docs.md/#iliblocale)

### ILibLocaleInfo
- Class: [ILibLocaleInfo](./Docs.md/#iliblocaleinfo)
- Methods: `getLanguageName()`, `getRegionName()`, `getClock()`, `getLocale()`, `getUnits()`, `getCalendar()`, `getFirstDayOfWeek()`, `getWeekEndStart()`, `getWeekEndEnd()`, `getTimeZone()`, `getDecimalSeparator()`, `getNativeDecimalSeparator()`, `getGroupingSeparator()`, `getNativeGroupingSeparator()`, `getPrimaryGroupingDigits()`, `getSecondaryGroupingDigits()`, `getPercentageFormat()`, `getNegativePercentageFormat()`, `getPercentageSymbol()`, `getExponential()`, `getNativeExponential()`, `getNativePercentageSymbol()`, `getNegativeNumberFormat()`, `getCurrencyFormats()`, `getCurrency()`, `getDigitsStyle()`, `getDigits()`, `getNativeDigits()`, `getRoundingMode()`, `getScript()`, `getDefaultScript()`, `getAllScripts()`, `getMeridiemsStyle()`, `getPaperSize()`, `getDelimiterQuotationStart()`, `getDelimiterQuotationEnd()`

### ILibNumFmt
- Clasee: [ILibNumFmtOptions](./Docs.md/#ilibnumfmtoptions)
- Class: [ILibNumFmt](./Docs.md/#ilibnumfmt)
- Methods: `format()`, `constrain()`, `getLocale()`, `getStyle()`, `getType()`, `isGroupingUsed()`, `getMaxFractionDigits()`, `getMinFractionDigits()`, `getSignificantDigits()`, `getCurrency()`, `getRoundingMode()`, `getUseNative()`

### ILibScriptInfo
- Class: [ILibScriptInfo](./Docs.md/#ilibscriptinfo)
- Methods: `getCode()`, `getCodeNumber()`, `getName()`, `getLongCode()`, `getScriptDirection()`, `getNeedsIME()`, `getCasing()`

### ILibCaseMapper
- Class: [ILibCaseMapper](./Docs.md/#ilibcasemapper)
- Methods: `getLocale()`, `map()`

## Supported Locales
The results of the following locales are checked by unit tests.
They have the same result as the original iLib methods.
Expand Down
10 changes: 10 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ class _MyAppState extends State<MyApp> {
_customTextBox('iLib Version', _iLibVersion, main: false),
_customTextBox('CLDR Version', _iLibCLDRVersion, main: false),
_customTextBox('Current Time', _currentTime),
_customTextBox('Upper Case', getUpperLowerCase('el-GR', 'groß'), main: false),
_customTextBox('Lower Case', getUpperLowerCase('tr-TR', 'Iİ', direction: 'tolower'), main: false),
],
),
),
Expand Down Expand Up @@ -229,4 +231,12 @@ class _MyAppState extends State<MyApp> {
final int clock = ILibDateFmt(fmtOptions).getClock();
return '$clock';
}

String getUpperLowerCase(String curlo, String str, {String direction = 'toupper'}) {
final ILibCaseMapper caseMapper =
ILibCaseMapper(locale: curlo, direction: direction);
String? result = caseMapper.map(str)?? '';
String? result2 = '$str\t($curlo)\t($direction)\t-->\t$result';
return result2;
}
}
3 changes: 3 additions & 0 deletions lib/flutter_ilib.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ import 'ilib_init.dart';
import 'internal/logger/log_adapter.dart';
import 'internal/logger/logger_selector.dart';

export 'ilib_casemapper.dart';
export 'ilib_date.dart';
export 'ilib_datefmt.dart';
export 'ilib_durationfmt.dart';
export 'ilib_init.dart';
export 'ilib_locale.dart';
export 'ilib_localeinfo.dart';
export 'ilib_numfmt.dart';
export 'ilib_scriptinfo.dart';

class FlutterILib extends ChangeNotifier {
FlutterILib._internal() {
Expand Down
111 changes: 111 additions & 0 deletions lib/ilib_casemapper.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import 'flutter_ilib.dart';

/// A class that maps a string to upper or lower case in a locale-sensitive manner.
class ILibCaseMapper {
/// [locale] locale to use when loading the mapper
/// [direction] "toupper" for upper-casing, or "tolower" for lower-casing.
/// Default if not specified is "toupper".
ILibCaseMapper({String? locale, String? direction})
: up = direction == null || direction == 'toupper',
locale = locale != null ? ILibLocale(locale) : ILibLocale() {
if (up) {
mapData = <String, String>{
'ß': 'SS', // German
'ΐ': 'Ι', // Greek
'ά': 'Α',
'έ': 'Ε',
'ή': 'Η',
'ί': 'Ι',
'ΰ': 'Υ',
'ϊ': 'Ι',
'ϋ': 'Υ',
'ό': 'Ο',
'ύ': 'Υ',
'ώ': 'Ω',
'Ӏ': 'Ӏ', // Russian and slavic languages
'ӏ': 'Ӏ'
};
} else {
mapData = <String, String>{
'Ӏ': 'Ӏ' // Russian and slavic languages
};
}

const Set<String> specialLanguages = <String>{
'az',
'tr',
'crh',
'kk',
'krc',
'tt'
};
if (specialLanguages.contains(this.locale.getLanguage())) {
_setUpMap('iı', 'İI');
}
}
bool up;
ILibLocale locale;
Map<String, String> mapData = <String, String>{};

String _handleGreekSigma(String string, int i) {
if (i < string.length) {
final String nextChar = string[i];
final int code = nextChar.codeUnitAt(0);
// If the next char is not a Greek letter, this is the end of the word,
// so use the final form of sigma. Otherwise, use the mid-word form.
final bool isNotGreek =
(code < 0x0388 && code != 0x0386) || code > 0x03CE;
return (isNotGreek ? 'ς' : 'σ') + nextChar.toLowerCase();
} else {
// No next char means this is the end of the word,
// so use the final form of sigma.
return 'ς';
}
}

String? _charMapper(String? string) {
if (string == null || string.isEmpty) {
return string;
}

final StringBuffer buffer = StringBuffer();
int i = 0;
final int len = string.length;

while (i < len) {
final String c = string[i];
i++;

if (!up && c == 'Σ') {
buffer.write(_handleGreekSigma(string, i));
if (i < len) {
i++;
}
} else {
buffer.write(mapData[c] ?? (up ? c.toUpperCase() : c.toLowerCase()));
}
}

return buffer.toString();
}

void _setUpMap(String lower, String upper) {
for (int i = 0; i < lower.length; i++) {
if (up) {
mapData[lower[i]] = upper[i];
} else {
mapData[upper[i]] = lower[i];
}
}
}

/// Return the locale that this mapper was constructed with.
ILibLocale getLocale() {
return locale;
}

/// Map a string to lower case in a locale-sensitive manner.
String? map(String? string) {
return _charMapper(string);
}
}
2 changes: 1 addition & 1 deletion lib/ilib_date.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ class ILibDateOptions {
String toJsonString() {
int? y = year;
int? m = month;
int? w = week;
int? d = day;
int? h = hour;
int? min = minute;
int? sec = second;
int? milsec = millisecond;
String result = '';
String completeOption = '';
final int? w = week;

if (dateTime != null) {
y = dateTime!.year;
Expand Down
2 changes: 1 addition & 1 deletion lib/ilib_datefmt.dart
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class ILibDateFmt {
List<MeridiemsInfo> getMeridiemsRange() {
String result = '';
final String formatOptions = toJsonString();
final List<MeridiemsInfo> meridems = [];
final List<MeridiemsInfo> meridems = <MeridiemsInfo>[];
final String jscode1 =
'JSON.stringify(new DateFmt($formatOptions).getMeridiemsRange())';
result = ILibJS.instance.evaluate(jscode1).stringResult;
Expand Down
Loading