Need help upgrading to Ionic Framework 4.0? Get assistance with our Enterprise Migration Services EXPLORE NOW

Globalization

Improve this doc

This plugin obtains information and performs operations specific to the user's locale, language, and timezone.

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

Installation

  1. Install the Cordova and Ionic Native plugins:
    $ ionic cordova plugin add cordova-plugin-globalization
    $ npm install --save @ionic-native/globalization@4
    
  2. Add this plugin to your app's module

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, timezone: string, utc_offset: number, dst_offset: number }> 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 }>

GlobalizationOptions

Param Type Details
formatLength string
selector string

API

Native

General