2017-03-20 16:38:14 -04:00
import { Injectable } from '@angular/core' ;
2017-12-28 07:28:44 -05:00
import { Cordova , IonicNativePlugin , Plugin } from '@ionic-native/core' ;
2016-03-13 04:08:39 -04:00
2018-03-17 01:11:55 +01:00
export interface GlobalizationOptions {
formatLength : string ;
selector : string ;
}
2016-03-13 04:08:39 -04:00
/**
* @name Globalization
* @description
2017-12-29 03:27:53 +01:00
* This plugin obtains information and performs operations specific to the user's locale, language, and timezone.
*
* @deprecated
* With the [ECMA Internationalization API](https://www.ecma-international.org/ecma-402/1.0/) now supported on iOS, Android and Windows devices, this plugin is not required any more.
* Migrating from this plugin to the [ECMA Internationalization API](https://www.ecma-international.org/ecma-402/1.0/) is explained in this [Cordova blog post](https://cordova.apache.org/news/2017/11/20/migrate-from-cordova-globalization-plugin.html).
*
2016-03-13 04:08:39 -04:00
* @usage
2016-07-20 17:17:09 +02:00
* ```typescript
2018-10-10 16:13:45 -05:00
* import { Globalization } from '@ionic-native/globalization/ngx';
2017-03-20 16:38:14 -04:00
*
* constructor(private globalization: Globalization) { }
*
*
* ...
*
*
* this.globalization.getPreferredLanguage()
* .then(res => console.log(res))
* .catch(e => console.log(e));
2016-03-24 13:00:18 -04:00
*
*
* ```
2018-03-17 01:11:55 +01:00
* @interfaces
* GlobalizationOptions
2016-03-13 04:08:39 -04:00
*/
@Plugin ( {
2016-10-27 12:48:50 -05:00
pluginName : 'Globalization' ,
2016-07-17 19:44:19 +02:00
plugin : 'cordova-plugin-globalization' ,
pluginRef : 'navigator.globalization' ,
2017-01-07 04:47:15 -05:00
repo : 'https://github.com/apache/cordova-plugin-globalization' ,
2017-12-28 13:09:04 +01:00
platforms : [ 'Amazon Fire OS' , 'Android' , 'Browser' , 'iOS' , 'Windows' ]
2016-03-13 04:08:39 -04:00
} )
2017-03-20 16:38:14 -04:00
@Injectable ( )
2017-04-27 00:36:12 -04:00
export class Globalization extends IonicNativePlugin {
2016-03-13 04:08:39 -04:00
/**
* Returns the BCP-47 compliant language identifier tag to the successCallback with a properties object as a parameter. That object should have a value property with a String value.
2016-11-29 16:40:50 -06:00
* @returns {Promise<{value: string}>}
2016-03-13 04:08:39 -04:00
*/
@Cordova ( )
2017-12-28 07:28:44 -05:00
getPreferredLanguage ( ) : Promise < { value : string } > {
return ;
}
2016-03-13 04:08:39 -04:00
/**
* Returns the BCP 47 compliant locale identifier string to the successCallback with a properties object as a parameter.
2016-11-29 16:40:50 -06:00
* @returns {Promise<{value: string}>}
2016-03-13 04:08:39 -04:00
*/
@Cordova ( )
2017-12-28 07:28:44 -05:00
getLocaleName ( ) : Promise < { value : string } > {
return ;
}
2016-03-13 04:08:39 -04:00
/**
* Converts date to string
2016-07-08 15:19:13 -04:00
* @param {Date} date Date you wish to convert
* @param options Options for the converted date. Length, selector.
2016-11-29 16:40:50 -06:00
* @returns {Promise<{value: string}>} Returns a promise when the date has been converted.
2016-03-13 04:08:39 -04:00
*/
@Cordova ( {
2016-07-08 01:06:34 +02:00
successIndex : 1 ,
2016-07-18 00:08:21 -04:00
errorIndex : 2
2016-03-13 04:08:39 -04:00
} )
2018-03-17 01:11:55 +01:00
dateToString (
date : Date ,
options : GlobalizationOptions
) : Promise < { value : string } > {
2017-12-28 07:28:44 -05:00
return ;
}
2016-03-13 04:08:39 -04:00
/**
2016-07-08 15:19:13 -04:00
* Parses a date formatted as a string, according to the client's user preferences and calendar using the time zone of the client, and returns the corresponding date object.
* @param {string} dateString Date as a string to be converted
* @param options Options for the converted date. Length, selector.
2016-11-29 16:40:50 -06:00
* @returns {Promise<{ year: number, month: number, day: number, hour: number, minute: number, second: number, millisecond: number }>} Returns a promise when the date has been converted.
2016-03-13 04:08:39 -04:00
*/
@Cordova ( {
2016-07-08 01:06:34 +02:00
successIndex : 1 ,
errorIndex : 2
2016-03-13 04:08:39 -04:00
} )
2018-03-17 01:11:55 +01:00
stringToDate (
dateString : string ,
options : GlobalizationOptions
) : Promise < {
year : number ;
month : number ;
day : number ;
hour : number ;
minute : number ;
second : number ;
millisecond : number ;
} > {
2017-12-28 07:28:44 -05:00
return ;
}
2016-03-13 04:08:39 -04:00
/**
2016-07-08 15:19:13 -04:00
* Returns a pattern string to format and parse dates according to the client's user preferences.
* @param options Object with the format length and selector
2018-03-17 11:27:16 +01:00
* @returns {Promise<{ pattern: string, timezone: string, utc_offset: number, dst_offset: number }>} Returns a promise.
2016-03-13 04:08:39 -04:00
*/
@Cordova ( {
2016-07-08 01:06:34 +02:00
callbackOrder : 'reverse'
2016-03-13 04:08:39 -04:00
} )
2018-03-17 01:11:55 +01:00
getDatePattern (
options : GlobalizationOptions
) : Promise < {
pattern : string ;
timezone : string ;
iana_timezone : string ;
2018-03-17 11:27:16 +01:00
utc_offset : number ;
2018-03-17 01:11:55 +01:00
dst_offset : number ;
} > {
2017-12-28 07:28:44 -05:00
return ;
}
2016-03-13 04:08:39 -04:00
/**
2016-07-08 15:19:13 -04:00
* Returns an array of the names of the months or days of the week, depending on the client's user preferences and calendar.
* @param options Object with type (narrow or wide) and item (month or days).
2018-09-17 16:05:37 +02:00
* @returns {Promise<{value: string[]}>} Returns a promise.
2016-03-13 04:08:39 -04:00
*/
@Cordova ( {
2016-07-08 01:06:34 +02:00
callbackOrder : 'reverse'
2016-03-13 04:08:39 -04:00
} )
2018-03-17 01:11:55 +01:00
getDateNames ( options : {
type : string ;
item : string ;
2018-09-17 16:05:37 +02:00
} ) : Promise < { value : string [ ] } > {
2017-12-28 07:28:44 -05:00
return ;
}
2016-03-13 04:08:39 -04:00
/**
2016-07-08 15:19:13 -04:00
* Indicates whether daylight savings time is in effect for a given date using the client's time zone and calendar.
* @param {data} date Date to process
2016-11-29 16:40:50 -06:00
* @returns {Promise<{dst: string}>} reutrns a promise with the value
2016-03-13 04:08:39 -04:00
*/
@Cordova ( )
2017-12-28 07:28:44 -05:00
isDayLightSavingsTime ( date : Date ) : Promise < { dst : string } > {
return ;
}
2016-03-13 04:08:39 -04:00
/**
2016-07-08 15:19:13 -04:00
* Returns the first day of the week according to the client's user preferences and calendar.
2016-11-29 16:40:50 -06:00
* @returns {Promise<{value: string}>} returns a promise with the value
2016-03-13 04:08:39 -04:00
*/
@Cordova ( )
2017-12-28 07:28:44 -05:00
getFirstDayOfWeek ( ) : Promise < { value : string } > {
return ;
}
2016-03-13 04:08:39 -04:00
/**
2016-07-08 15:19:13 -04:00
* Returns a number formatted as a string according to the client's user preferences.
2016-12-01 18:47:27 -05:00
* @param numberToConvert {Number} The number to convert
2016-11-29 14:28:26 -05:00
* @param options {Object} Object with property `type` that can be set to: decimal, percent, or currency.
2016-03-13 04:08:39 -04:00
*/
@Cordova ( {
2016-07-08 01:06:34 +02:00
successIndex : 1 ,
errorIndex : 2
2016-03-13 04:08:39 -04:00
} )
2018-03-17 01:11:55 +01:00
numberToString (
numberToConvert : number ,
options : { type : string }
) : Promise < { value : string } > {
2017-12-28 07:28:44 -05:00
return ;
}
2016-03-13 04:08:39 -04:00
/**
*
2016-07-08 15:19:13 -04:00
* @param {string} stringToConvert String you want to conver to a number
* @param options The type of number you want to return. Can be decimal, percent, or currency.
2016-11-29 16:40:50 -06:00
* @returns {Promise<{ value: number | string }>} Returns a promise with the value.
2016-03-13 04:08:39 -04:00
*/
@Cordova ( {
2016-07-08 01:06:34 +02:00
successIndex : 1 ,
errorIndex : 2
2016-03-13 04:08:39 -04:00
} )
2018-03-17 01:11:55 +01:00
stringToNumber (
stringToConvert : string ,
options : { type : string }
) : Promise < { value : number | string } > {
2017-12-28 07:28:44 -05:00
return ;
}
2016-03-13 04:08:39 -04:00
/**
2016-07-08 15:19:13 -04:00
* Returns a pattern string to format and parse numbers according to the client's user preferences.
* @param options Can be decimal, percent, or currency.
2016-11-29 16:40:50 -06:00
* @returns {Promise<{ pattern: string, symbol: string, fraction: number, rounding: number, positive: string, negative: string, decimal: string, grouping: string }>}
2016-03-13 04:08:39 -04:00
*/
@Cordova ( {
2016-07-08 01:06:34 +02:00
callbackOrder : 'reverse'
2016-03-13 04:08:39 -04:00
} )
2018-03-17 01:11:55 +01:00
getNumberPattern ( options : {
type : string ;
} ) : Promise < {
pattern : string ;
symbol : string ;
fraction : number ;
rounding : number ;
positive : string ;
negative : string ;
decimal : string ;
grouping : string ;
} > {
2017-12-28 07:28:44 -05:00
return ;
}
2016-03-13 04:08:39 -04:00
/**
2016-07-08 15:19:13 -04:00
* Returns a pattern string to format and parse currency values according to the client's user preferences and ISO 4217 currency code.
* @param {string} currencyCode Currency Code.A
2016-11-29 16:40:50 -06:00
* @returns {Promise<{ pattern: string, code: string, fraction: number, rounding: number, decimal: number, grouping: string }>}
2016-03-13 04:08:39 -04:00
*/
@Cordova ( )
2018-03-17 01:11:55 +01:00
getCurrencyPattern (
currencyCode : string
) : Promise < {
pattern : string ;
code : string ;
fraction : number ;
rounding : number ;
decimal : number ;
grouping : string ;
} > {
2017-12-28 07:28:44 -05:00
return ;
}
2016-06-15 18:17:02 -04:00
}