Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vtex/angular-locale
https://github.com/vtex/angular-locale
srv-oms-ui xp-post-purchase
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/vtex/angular-locale
- Owner: vtex
- Created: 2015-08-10T17:35:33.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2015-09-29T17:24:35.000Z (over 9 years ago)
- Last Synced: 2024-11-19T22:13:40.521Z (about 1 month ago)
- Topics: srv-oms-ui, xp-post-purchase
- Language: CoffeeScript
- Size: 141 KB
- Stars: 2
- Watchers: 186
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Angular Locale
Currency and Locale manager for AngularJS## Usage
#### Reference script
```html```
#### Inject `vtex.ngLocale`
```coffeescript
angular.module 'yourApp', ['vtex.ngLocale']
```### Events
#### localeSelected.vtex
- `LocaleService` automatically **listens** to this and expects `lang` arguments.
- `lang` follows 'xx-XX' format, e.g.: 'en-US'.
- Therefore both `tmhDynamicLocale` and `$translate` (in this order) are called and updated with new i18n data.#### localeUpdated.vtex
- `LocaleService` **triggers** this once it has set `$translate` to use new language and i18n is updated.
Obs: `setCurrency` is called everytime language/locale gets updated, since it will reset `$locale.NUMBER_FORMATS` each time.#### currencyUpdated.vtex
- `LocaleService` **triggers** this once it has set `$locale` according to current currency configuration.### API `LocaleService`
#### setLanguage language
- string `eventName`, Object `data` with any information you want to be registered within the event#### setCurrency currencyConfiguration
- currencyConfiguration `Object` for United States Dollar:```coffeescript
currencySymbol: '$ '
decimalSeparator: ','
groupSeparator: '.'
ngPatterns:
gSize: 3
lgSize: 3
macFrac: 0
maxFrac: 2
minFrac: 2
minInt: 1
negPre: "- \u00a4"
negSuf: ""
posPre: "\u00a4"
posSuf: ""
```This gets mapped into Angular's `$locale`:
```coffeescript
$locale.NUMBER_FORMATS.CURRENCY_SYM = currencyConfiguration.currencySymbol
$locale.NUMBER_FORMATS.DECIMAL_SEP = currencyConfiguration.decimalSeparator
$locale.NUMBER_FORMATS.GROUP_SEP = currencyConfiguration.groupSeparator
$locale.NUMBER_FORMATS.PATTERNS[1] = currencyConfiguration.ngPatterns
```*Obs:* ngPatterns/NUMBER_FORMATS.PATTERNS[1] has a default value, no worries :)
## Development
Inside `src` you can find this module source code, written in **CoffeeScript**. To build the `.js` and uglify it, install npm dev-dependencies and run grunt:(sudo) npm i
grunt