-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #294 from jama5262/JIFFY-293-make-locales-settings…
…-configurable [JIFFY-293] Make locale settings configurable in Jiffy
- Loading branch information
Showing
47 changed files
with
3,259 additions
and
3,633 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
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
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,51 @@ | ||
import 'package:intl/intl.dart'; | ||
|
||
import '../locale/ordinals.dart'; | ||
import '../utils/jiffy_exception.dart'; | ||
|
||
Map<String, Ordinals> _builtInOrdinals = { | ||
'en': Ordinals(first: 'st', second: 'nd', third: 'rd', nth: 'th'), | ||
'es': Ordinals(first: 'º', second: 'º', third: 'º', nth: 'º'), | ||
'fr': Ordinals(first: 'er', second: '', third: '', nth: ''), | ||
'zh': Ordinals(first: '日', second: '日', third: '日', nth: '日'), | ||
'de': Ordinals(first: '.', second: '.', third: '.', nth: '.'), | ||
'it': Ordinals(first: 'º', second: 'º', third: 'º', nth: 'º'), | ||
'ar': Ordinals(first: '', second: '', third: '', nth: ''), | ||
'az': Ordinals(first: '', second: '', third: '', nth: ''), | ||
'id': Ordinals(first: '', second: '', third: '', nth: ''), | ||
'ja': Ordinals(first: '日', second: '日', third: '日', nth: '日'), | ||
'ko': Ordinals(first: '일', second: '일', third: '일', nth: '일'), | ||
'ru': Ordinals(first: '', second: '', third: '', nth: ''), | ||
'uk': Ordinals(first: '', second: '', third: '', nth: ''), | ||
'hi': Ordinals(first: '', second: '', third: '', nth: ''), | ||
'hu': Ordinals(first: '.', second: '.', third: '.', nth: '.'), | ||
'pt': Ordinals(first: 'º', second: 'º', third: 'º', nth: 'º'), | ||
'pl': Ordinals(first: '.', second: '.', third: '.', nth: '.'), | ||
'tr': Ordinals(first: '', second: '', third: '', nth: ''), | ||
'sv': Ordinals(first: '', second: '', third: '', nth: ''), | ||
'nb': Ordinals(first: '.', second: '.', third: '.', nth: '.'), | ||
'fa': Ordinals(first: 'م', second: 'م', third: 'م', nth: 'م'), | ||
'bn': Ordinals(first: '', second: '', third: '', nth: ''), | ||
'nl': Ordinals(first: '.', second: '.', third: '.', nth: '.'), | ||
'th': Ordinals(first: '', second: '', third: '', nth: ''), | ||
'sk': Ordinals(first: '.', second: '.', third: '.', nth: '.'), | ||
'cs': Ordinals(first: '.', second: '.', third: '.', nth: '.'), | ||
}; | ||
|
||
Ordinals? _defaultOrdinals; | ||
|
||
set defaultOrdinals(Ordinals? ordinals) { | ||
_defaultOrdinals = ordinals; | ||
} | ||
|
||
Ordinals getOrdinals(String locale) { | ||
if (_defaultOrdinals != null) { | ||
return _defaultOrdinals!; | ||
} else { | ||
final ordinals = _builtInOrdinals[Intl.shortLocale(locale)]; | ||
if (ordinals == null) { | ||
throw JiffyException("Locale `$locale` is not supported for ordinals."); | ||
} | ||
return ordinals; | ||
} | ||
} |
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,63 @@ | ||
import 'package:intl/intl.dart'; | ||
|
||
import '../locale/relative_date_time.dart'; | ||
import '../utils/jiffy_exception.dart'; | ||
|
||
Map<String, RelativeDateTime> _relativeDateTime = { | ||
'en': EnRelativeDateTime(), | ||
'es': EsRelativeDateTime(), | ||
'fr': FrRelativeDateTime(), | ||
'zh': ZhRelativeDateTime(), | ||
'zh_CN': ZhCnRelativeDateTime(), | ||
'de': DeRelativeDateTime(), | ||
'it': ItRelativeDateTime(), | ||
'ar': ArRelativeDateTime(true), | ||
'ar_LY': ArRelativeDateTime(false), | ||
'ar_DZ': ArSaMaDzKwTnRelativeDateTime(false), | ||
'ar_KW': ArSaMaDzKwTnRelativeDateTime(false), | ||
'ar_SA': ArSaMaDzKwTnRelativeDateTime(true), | ||
'ar_MA': ArSaMaDzKwTnRelativeDateTime(false), | ||
'ar_TN': ArSaMaDzKwTnRelativeDateTime(false), | ||
'az': AzRelativeDateTime(), | ||
'id': IdRelativeDateTime(), | ||
'ja': JaRelativeDateTime(), | ||
'ko': KoRelativeDateTime(), | ||
'ru': RuRelativeDateTime(), | ||
'uk': UkRelativeDateTime(), | ||
'hi': HiRelativeDateTime(), | ||
'hu': HuRelativeDateTime(), | ||
'pt': PtRelativeDateTime(), | ||
'pl': PlRelativeDateTime(), | ||
'tr': TrRelativeDateTime(), | ||
'sv': SvRelativeDateTime(), | ||
'nb': NbRelativeDateTime(), | ||
'fa': FaRelativeDateTime(), | ||
'bn': BnRelativeDateTime(), | ||
'nl': NlRelativeDateTime(), | ||
'th': ThRelativeDateTime(), | ||
'sk': SkRelativeDateTime(), | ||
'cs': CsRelativeDateTime(), | ||
}; | ||
|
||
RelativeDateTime? _defaultRelativeDateTime; | ||
|
||
set defaultRelativeDateTime(RelativeDateTime? relativeDateTime) { | ||
_defaultRelativeDateTime = relativeDateTime; | ||
} | ||
|
||
RelativeDateTime getRelativeDateTime(String locale) { | ||
if (_defaultRelativeDateTime != null) { | ||
return _defaultRelativeDateTime!; | ||
} else { | ||
final canonicalizedLocale = Intl.canonicalizedLocale(locale); | ||
final rdt1 = _relativeDateTime[canonicalizedLocale]; | ||
if (rdt1 != null) return rdt1; | ||
|
||
final shortLocale = Intl.shortLocale(locale); | ||
final rdt2 = _relativeDateTime[shortLocale]; | ||
if (rdt2 != null) return rdt2; | ||
|
||
throw JiffyException( | ||
"Locale `$locale` is not supported for relative date formatting."); | ||
} | ||
} |
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,31 @@ | ||
import 'package:intl/date_symbol_data_local.dart' as date_intl; | ||
import 'package:jiffy/src/utils/jiffy_exception.dart'; | ||
|
||
import '../enums/start_of_week.dart'; | ||
|
||
StartOfWeek? _defaultStartOfWeek; | ||
|
||
set defaultStartOfWeek(StartOfWeek? startOfWeek) { | ||
_defaultStartOfWeek = startOfWeek; | ||
} | ||
|
||
StartOfWeek getStartOfWeek(String locale) { | ||
if (_defaultStartOfWeek != null) { | ||
return _defaultStartOfWeek!; | ||
} else { | ||
final supportedLocale = date_intl.dateTimeSymbolMap()[locale]; | ||
|
||
if (supportedLocale == null) { | ||
throw JiffyException("The specified locale '$locale' is not supported."); | ||
} | ||
|
||
return switch (supportedLocale.FIRSTDAYOFWEEK) { | ||
0 => StartOfWeek.monday, | ||
5 => StartOfWeek.saturday, | ||
6 => StartOfWeek.sunday, | ||
_ => throw JiffyException( | ||
"Start of week with index ${supportedLocale.FIRSTDAYOFWEEK} " | ||
"not supported"), | ||
}; | ||
} | ||
} |
Oops, something went wrong.