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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"devDependencies": {
"typescript": "^1.8.7"
"typescript": "^1.8.9"
}
}
37 changes: 36 additions & 1 deletion src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,43 @@ Welcome to the `nativescript-intl` plugin for NativeScript framework

# Prerequisites

- installed [NativeScript](https://github.com/NativeScript/NativeScript)
- installed [NativeScript-CLI](https://github.com/NativeScript/nativescript-cli)

# Install `nativescript-intl` plugin.

Navigate to project folder and run `NativeScript-CLI` command `tns plugin add nativescript-intl`.
Navigate to project folder and run `NativeScript-CLI` command `tns plugin add nativescript-intl`.

This plugin provides similar to [Intl.js](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Intl) API for date, time and number formatting on a mobile device (Android and iOS).

## How to use

```JavaScript
var intl = require("nativescript-intl");
var dateFormat = new intl.DateTimeFormat('en-US', {'year': 'numeric', 'month': 'short', 'day': 'numeric'}).format(new Date(2016, 2, 23));
var numberFormat = new intl.NumberFormat('en-US', {'style': 'currency', 'currency': 'USD', 'currencyDisplay': 'symbol'}).format(123456.789);

console.log("dateFormat: " + dateFormat);
console.log("numberFormat: " + numberFormat);
// prints Mar 23, 2016
// $123456.79
```

Since localization formatting is not exactly same on Android, iOS and [Intl.js](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Intl) there is another option to use this API.

## Custom pattern

```JavaScript
var intl = require("nativescript-intl");
var dateFormat = new intl.DateTimeFormat(null, null, 'y MMMM d, EEEE HH:mm:ss').format(new Date(2016, 2, 23, 12, 35, 40));
var numberFormat = new intl.NumberFormat('en-US', {'style': 'currency', 'currency': 'USD', 'currencyDisplay': 'symbol'}, '#,##0.00 ¤').format(123456.789);

console.log("dateFormat: " + dateFormat);
console.log("numberFormat: " + numberFormat);
// prints 2016 March 23, Wednesday 2016 12:35:40
// 123,456.79 $
```

> Omitting locale will use the current locale setting on device.

> Keep in mind that ICU versions differ accross device OS versions, so this plugin could produce different results on a different API level (Android) and OS version (iOS).
8 changes: 4 additions & 4 deletions src/package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"name": "nativescript-intl",
"version": "0.0.1",
"version": "0.0.3",
"description": "Provides API for using Native date, time and number formatting with an API similar to Intl.js",
"main": "nativescript-intl.js",
"nativescript": {
"platforms": {
"android": "1.6.2",
"ios": "1.6.0"
"android": "2.1.0",
"ios": "2.1.0"
}
},
"keywords": [
"NativeScript", "localization", "globalization", "formatting"
"NativeScript", "localization", "globalization", "formatting", "currency", "nativescript-angular"
],
"author": "Nedyalko Nikolov <nedyalko.nikolov@telerik.com>"
}
34 changes: 17 additions & 17 deletions tests/app/tests/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ var mediumDateTimeResultsAndroid = [
"22 mar 2016 09:40:39", //22 mar 2016, 09:40:39
"22 de mar de 2016 09:40:39", //22/03/2016, 09:40:39
"22 mar. 2016 09:40:39", //22 mar. 2016, 09:40:39
"22 марта 2016 г. 09:40:39", //22 марта 2016 г., 9:40:39
"22 мар. 2016 г. 09:40:39", //22 мар. 2016 г., 9:40:39
"22. мар 2016. 09.40.39",
"22. mar 2016 09:40:39", //22. 3. 2016, 9:40:39
"22. mar. 2016 09:40:39", //22. mar. 2016 09.40.39
Expand Down Expand Up @@ -275,7 +275,7 @@ var mediumDateResultsAndroid = [
"22 mar 2016",
"22 de mar de 2016", //22/03/2016
"22 mar. 2016",
"22 марта 2016 г.",
"22 мар. 2016 г.",
"22. мар 2016.",
"22. mar 2016", //22. 3. 2016
"22. mar. 2016",
Expand Down Expand Up @@ -867,7 +867,7 @@ var currencyCodes = [
"UAH",
"GBP",
"USD",
"NOK"
"NOK"
];

var currencyCodesResultsAndroid = [
Expand All @@ -886,7 +886,7 @@ var currencyCodesResultsAndroid = [
"123456,79 EUR",
"123456,79 HUF",
"123456,79 EUR",
"EUR123456,79",
"123456,79 EUR",
"123456,79 MDL",
"EUR 123456,79",
"123456,79 PLN",
Expand Down Expand Up @@ -943,7 +943,7 @@ var currencyCodesResultsIOS = [
];

var currencyCodesGroupingResultsAndroid = [
"EUR 123.456,79",
"EUR 123 456,79",
"123.456,79 EUR", //EUR 123.456,79"
"123.456,79 EUR", //123 456,79 EUR
"123 456,79 BGN",
Expand All @@ -958,7 +958,7 @@ var currencyCodesGroupingResultsAndroid = [
"123.456,79 EUR",
"123 456,79 HUF",
"123.456,79 EUR",
"EUR123456,79", //EUR123 456,79
"123456,79 EUR",
"123.456,79 MDL",
"EUR 123.456,79",
"123 456,79 PLN",
Expand Down Expand Up @@ -1028,15 +1028,15 @@ var currencyCodesSymbolResultsAndroid = [
"123456,79 €",
"123456,79 €",
"123456,79 €",
"123456,79 HUF",
"123456,79 Ft",
"123456,79 €",
"123456,79 €",
"€123456,79",
"123456,79 L", //123456,79 MDL
"€ 123456,79",
"123456,79 zł",
"123456,79 €",
"123456,79 RON",
"123456,79 руб.",
"123456,79 ₽", // 123456,79 RUB
"123457 RSD",
"123456,79 €",
"123457 SLL", //123456,79 €
Expand Down Expand Up @@ -1087,7 +1087,7 @@ var currencyCodesSymbolResultsIOS = [
];

var percentResults = [
"12.345.679 %",
"12 345 679 %",
"12.345.679%",
"12.345.679 %", //12 345 679 %
"12 345 679%",
Expand All @@ -1114,7 +1114,7 @@ var percentResults = [
"12.345.679%",
"12.345.679 %",
"12 345 679 %",
"12'345'679 %",
"12'345'679%",
"%12.345.679",
"12 345 679%",
"12,345,679%",
Expand All @@ -1123,7 +1123,7 @@ var percentResults = [
];

var decimalResults = [
"123.456,79",
"123 456,79",
"123.456,79",
"123.456,79", //123 456,79
"123 456,79",
Expand Down Expand Up @@ -1159,7 +1159,7 @@ var decimalResults = [
];

var customNumberPatternResultsAndroid = [
"123.456,79 €",
"123 456,79 €",
"123.456,79 €",
"123.456,79 €",
"123 456,79 лв.",
Expand All @@ -1172,18 +1172,18 @@ var customNumberPatternResultsAndroid = [
"123 456,79 €",
"123.456,79 €",
"123.456,79 €",
"123 456,79 HUF",
"123 456,79 Ft",
"123.456,79 €",
"123 456,79 €",
"123.456,79 L",
"123.456,79 €",
"123 456,79 zł",
"123 456,79 €",
"123.456,79 RON",
"123 456,79 руб.",
"123.456,79 RSD",
"123 456,79 ",
"123.457 RSD",
"123 456,79 €",
"123.456,79 SLL",
"123.457 SLL",
"123.456,79 €",
"123 456,79 kr",
"123'456.79 CHF",
Expand Down
Loading