@softeq/angular-mls-ri
v1.0.0-beta.1
Published
Reference implementation of @softeq/mls contract
Maintainers
Readme
@softeq/angular-mls-ri
Reference implementation of @softeq/mls contract.
@softeq/angular-mls-ri is based on
@ngx-translate/coreto provide translations- embedded Angular capabilities for number & date formatting
- and implements the simplest parsing of number & date values.
Setup
To work with this library it should be properly initialized.
- First of all you have to initialize
TranslateModulefrom@ngx-translate/corelibrary.@NgModule({ imports: [ TranslateModule.forRoot({ ... }), ], ... }) - Define number and date formats used to format/parse dates and numbers.
If you store your translations (used by
@ngx-translatelibrary) in thejsonfile its content may look like
All formats should be defined under{ "$localization": { "numberFormat": { "decimalSeparator": ".", "groupSeparator": ",", "grouping": true }, "dateFormat": { "shortDate": "M/d/yyyy", "dayMonth": "MMM d", "monthYear": "M/yyyy", "dateA11y": "MMMM/d/yyyy", "monthYearA11y": "MMMM/yy", "shortMonthYear": "MMM yy", "shortTime": "h:mm a", "shortDatetime": "M/d/yyyy h:mm a", "mediumDateAndWeekday": "MMM d yyyy, EE" } }, ... }$localizationfield. The main idea is to make localization structure available when it is retrieved byTranslateServiceusing$localizationkey
Localization structure MUST define number & date formats under the corresponding fields as in the example above. Read here below about structure of these fieldsthis.translate.instant('$localization'); // should retrieve localization structure - Add
SofteqMlsRiModulemodule intoimportssection of rootNgModule@NgModule({ imports: [ TranslateModule.forRoot({ ... }), SofteqMlsRiModule.forRoot(), ], ... })
Number Format
Number format should consist of the following fields
decimalSeparatoris a decimal separatorgroupingwhether to use groupinggroupSeparatoris a character used to separate groups
Date Format
Date format defines set of named formats, like M/d/yyyy or MMM d.
- formatting of dates works according to the rules used by
DatePipe - parsing of dates currently supports only digit-only formats, like
M/d/yyyyorh:mm a.
Restrictions
- Date and number formats are retrieved using
TranslateService#instantcall. This means that translations should be loaded beforeMlsProvideris used first time. You should care about this yourself.
