Globalization

Improve this doc

$ ionic plugin add cordova-plugin-globalization
$ npm install --save @ionic-native/globalization

Repo: https://github.com/apache/cordova-plugin-globalization

Supported platforms

Usage

import { Globalization } from '@ionic-native/globalization';

constructor(private globalization: Globalization) { }


...


this.globalization.getPreferredLanguage()
  .then(res => console.log(res))
  .catch(e => console.log(e));

Instance Members

getPreferredLanguage()

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.

Returns: Promise<{value: string}>

getLocaleName()

Returns the BCP 47 compliant locale identifier string to the successCallback with a properties object as a parameter.

Returns: Promise<{value: string}>

dateToString(date, options)

Converts date to string

Param Type Details
date Date

Date you wish to convert

options

Options for the converted date. Length, selector.

Returns: Promise<{value: string}> Returns a promise when the date has been converted.

stringToDate(dateString, options)

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 Type Details
dateString string

Date as a string to be converted

options

Options for the converted date. Length, selector.

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.

getDatePattern(options)

Returns a pattern string to format and parse dates according to the client’s user preferences.

Param Type Details
options

Object with the format length and selector

Returns: Promise<{pattern: string}> Returns a promise.

getDateNames(options)

Returns an array of the names of the months or days of the week, depending on the client’s user preferences and calendar.

Param Type Details
options

Object with type (narrow or wide) and item (month or days).

Returns: Promise<{value: Array<string>}> Returns a promise.

isDayLightSavingsTime(date)

Indicates whether daylight savings time is in effect for a given date using the client’s time zone and calendar.

Param Type Details
date data

Date to process

Returns: Promise<{dst: string}> reutrns a promise with the value

getFirstDayOfWeek()

Returns the first day of the week according to the client’s user preferences and calendar.

Returns: Promise<{value: string}> returns a promise with the value

numberToString(numberToConvert, options)

Returns a number formatted as a string according to the client’s user preferences.

Param Type Details
numberToConvert Number

The number to convert

options Object

Object with property type that can be set to: decimal, percent, or currency.

stringToNumber(stringToConvert, options)

Param Type Details
stringToConvert string

String you want to conver to a number

options

The type of number you want to return. Can be decimal, percent, or currency.

Returns: Promise<{ value: number | string }> Returns a promise with the value.

getNumberPattern(options)

Returns a pattern string to format and parse numbers according to the client’s user preferences.

Param Type Details
options

Can be decimal, percent, or currency.

Returns: Promise<{ pattern: string, symbol: string, fraction: number, rounding: number, positive: string, negative: string, decimal: string, grouping: string }>

getCurrencyPattern(currencyCode)

Returns a pattern string to format and parse currency values according to the client’s user preferences and ISO 4217 currency code.

Param Type Details
currencyCode string

Currency Code.A

Returns: Promise<{ pattern: string, code: string, fraction: number, rounding: number, decimal: number, grouping: string }>

API

Native

General