Skip to content

Commit

Permalink
Upgrade to Angular 2.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
robisim74 committed Nov 15, 2016
1 parent 4188456 commit 7fc48fd
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 31 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ It allows, in addition to translation, to localize numbers and dates of your app

Get the changelog by [releases](https://github.com/robisim74/angular2localization/releases).

**Angular version: ^2.1.0**
**Angular version: ^2.2.0**

## Angular 2 i18n solutions
| _Feature_ | [Angular 2](https://angular.io/docs/ts/latest/cookbook/i18n.html) _Native_ | [ng2-translate](https://github.com/ocombe/ng2-translate) _External library_ | [angular2localization](https://github.com/robisim74/angular2localization/blob/master/doc/spec.md) _External library_ |
Expand Down
31 changes: 28 additions & 3 deletions doc/spec.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Angular 2 Localization library specification
Library version: 1.1.1
Library version: 1.2.0

## Table of contents
* [1 The library structure](#1)
Expand All @@ -22,7 +22,8 @@ Library version: 1.1.1
* [3.2.2 Asynchronous loading of json files](#3.2.2)
* [3.2.3 Asynchronous loading through a Web API](#3.2.3)
* [3.2.4 Special characters](#3.2.4)
* [3.2.5 Changing language](#3.2.5)
* [3.2.5 Handling missing keys](#3.2.5)
* [3.2.6 Changing language](#3.2.6)
* [3.3 Third scenario: you need to translate messages, dates and numbers](#3.3)
* [3.3.1 Changing locale and currency](#3.3.1)
* [3.3.2 Option: using locale as language](#3.3.2)
Expand Down Expand Up @@ -378,7 +379,28 @@ Because strings must be written within quotes, use the `\` escape character to i
"\"What's happened to me?\" he thought."
```

#### <a name="3.2.5"/>3.2.5 Changing language
#### <a name="3.2.5"/>3.2.5 Handling missing keys
By default, if a key is not present in the `json`, the same key is returned.

When you initialize the `LocalizationService`, you can set a friendly value to use for these keys:
```TypeScript
localization.translationProvider('./resources/locale-');
localization.setMissingValue("No key");
```
Alternatively, you can set a key to use for the missing keys, so that even this is translated:
```TypeScript
localization.translationProvider('./resources/locale-');
localization.setMissingKey("MISSING");
```
and in the `json`:
```
{
"MISSING": "No key",
...
}
```

#### <a name="3.2.6"/>3.2.6 Changing language
To change language at runtime, call the following method:
```TypeScript
this.locale.setCurrentLanguage(language);
Expand Down Expand Up @@ -678,6 +700,7 @@ Method | Function
------ | --------
`addLanguage(language: string): void;` | Adds a new language
`addLanguages(languages: Array<string>): void;` | Adds languages
`getAvailableLanguages(): Array<string>;` | Gets all available languages
`useLocalStorage(): void;` | Sets Local Storage as default
`definePreferredLanguage(defaultLanguage: string, expiry?: number): void;` | Defines the preferred language. Selects the current language of the browser/user if it has been added, else the default language
`definePreferredLocale(defaultLanguage: string, defaultCountry: string, expiry?: number, script?: string, numberingSystem?: string, calendar?: string): void;` | Defines preferred languange and country, regardless of the browser language
Expand Down Expand Up @@ -711,6 +734,8 @@ Method | Function
`translateAsync(key: string, args?: any, lang?: string): Observable<string>;` | Translates a key
`useLocaleAsLanguage(): void;` | Sets the use of locale as language for the service
`updateTranslation(language?: string): void;` | Gets language code and loads the translation data for the asynchronous loading
`setMissingValue(value: string): void;` | Sets the value to use for missing keys
`setMissingKey(key: string): void;` | Sets the key to use for missing keys
`compare(key1: string, key2: string, extension?: string, options?: any): number;` | Compares two keys by the value of translation & the current language code
`sort(list: Array<any>, keyName: any, order?: string, extension?: string, options?: any): Array<any>;` | Sorts an array of objects or an array of arrays by the current language code
`sortAsync(list: Array<any>, keyName: any, order?: string, extension?: string, options?: any): Observable<Array<any>>;` | Sorts an array of objects or an array of arrays by the current language code
Expand Down
46 changes: 23 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular2localization",
"version": "1.1.1",
"version": "1.2.0",
"description": "An Angular 2 library to translate messages, dates and numbers",
"main": "bundles/angular2localization.umd.js",
"module": "angular2localization.js",
Expand Down Expand Up @@ -31,24 +31,24 @@
},
"homepage": "https://github.com/robisim74/angular2localization",
"peerDependencies": {
"@angular/common": "^2.1.0",
"@angular/core": "^2.1.0",
"@angular/forms": "^2.1.0",
"@angular/http": "^2.1.0"
"@angular/common": "^2.2.0",
"@angular/core": "^2.2.0",
"@angular/forms": "^2.2.0",
"@angular/http": "^2.2.0"
},
"devDependencies": {
"@angular/common": "2.1.0",
"@angular/compiler": "2.1.0",
"@angular/compiler-cli": "2.1.0",
"@angular/core": "2.1.0",
"@angular/forms": "2.1.0",
"@angular/http": "2.1.0",
"@angular/platform-browser": "2.1.0",
"@angular/platform-browser-dynamic": "2.1.0",
"@angular/platform-server": "2.1.0",
"@types/jasmine": "2.5.35",
"@types/node": "6.0.45",
"codelyzer": "1.0.0-beta.2",
"@angular/common": "2.2.0",
"@angular/compiler": "2.2.0",
"@angular/compiler-cli": "2.2.0",
"@angular/core": "2.2.0",
"@angular/forms": "2.2.0",
"@angular/http": "2.2.0",
"@angular/platform-browser": "2.2.0",
"@angular/platform-browser-dynamic": "2.2.0",
"@angular/platform-server": "2.2.0",
"@types/jasmine": "2.5.38",
"@types/node": "6.0.47",
"codelyzer": "1.0.0-beta.3",
"core-js": "2.4.1",
"jasmine-core": "2.5.2",
"karma": "1.3.0",
Expand All @@ -61,13 +61,13 @@
"reflect-metadata": "0.1.8",
"rollup": "0.36.3",
"rxjs": "5.0.0-beta.12",
"ts-helpers": "1.1.1",
"ts-loader": "0.9.1",
"ts-helpers": "1.1.2",
"ts-loader": "1.2.1",
"tslint": "3.15.1",
"typescript": "2.0.3",
"webpack": "2.1.0-beta.25",
"zone.js": "0.6.25",
"shelljs": "0.7.4",
"typescript": "2.0.9",
"webpack": "2.1.0-beta.26",
"zone.js": "0.6.26",
"shelljs": "0.7.5",
"chalk": "1.1.3",
"uglify-js": "2.7.4"
}
Expand Down
18 changes: 15 additions & 3 deletions src/directives/locale-number-validator.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,31 @@ export function validateLocaleNumber(locale: LocaleService, digits: string, MIN_

if (parsedValue < MIN_VALUE) {

return { minValue: false };
return {
minValue: {
valid: false
}
};

} else if (parsedValue > MAX_VALUE) {

return { maxValue: false };
return {
maxValue: {
valid: false
}
};

}

return null; // The number is valid.

} else {

return { format: false };
return {
format: {
valid: false
}
};

}

Expand Down
2 changes: 1 addition & 1 deletion src/services/locale.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ import { Injectable, EventEmitter, Output } from '@angular/core';
}

/**
* Gets all available languages
* Gets all available languages.
*
* @return An array with two-letter or three-letter codes for all available languages
*/
Expand Down

0 comments on commit 7fc48fd

Please sign in to comment.