Localization-0.10.0

    Localization-0.10.0


    Article summary


    title: Localization

    # Localization Module

    Version 0.10.0

    Overview

    Methods for accessessing location and language preferences

    OpenRPC

    Firebolt APIs are maintained in the rdkcentral/firebolt-core-sdk GitHub repository.

    You can see this API in the localization.json OpenRPC JSON-Schema document.

    Table of Contents

    Usage

    To use the Localization module, you can import it into your project from the Firebolt SDK:

    import { Localization } from '@firebolt-js/sdk'
    

    Methods

    additionalInfo

    Get any platform-specific localization information, in an Map<string, string>

    function additionalInfo(): Promise<object>
    

    Promise resolution:

    TypeDescription
    objectthe additional info

    Examples

    Default Example

    JavaScript:

    import { Localization } from '@firebolt-js/sdk'
    
    Localization.additionalInfo()
        .then(info => {
            console.log(info)
        })
    

    Value of info:

    {}
    
    JSON-RPC:

    Request:

    {
      "jsonrpc": "2.0",
      "id": 1,
      "method": "localization.additionalInfo",
      "params": {}
    }
    

    Response:

    {
      "jsonrpc": "2.0",
      "id": 1,
      "result": {}
    }
    

    countryCode

    Get the ISO 3166 code for the counrty device is located in

    To get the value of countryCode call the method like this:

    function countryCode(): Promise<CountryCode>
    

    Promise resolution:

    TypeDescription
    CountryCodethe device country code

    Examples

    Default Example

    JavaScript:

    import { Localization } from '@firebolt-js/sdk'
    
    Localization.countryCode()
        .then(code => {
            console.log(code)
        })
    

    Value of code:

    "US"
    
    JSON-RPC:

    Request:

    {
      "jsonrpc": "2.0",
      "id": 1,
      "method": "localization.countryCode",
      "params": {}
    }
    

    Response:

    {
      "jsonrpc": "2.0",
      "id": 1,
      "result": "US"
    }
    

    To set the value of countryCode call the method like this:

    function countryCode(): Promise<ListenResponse | CountryCode>
    

    Parameters:

    ParamTypeRequiredSummary

    Promise resolution:

    TypeSummary
    voidPromise resolves with no value when the operation is complete.

    Examples

    Default Example

    JavaScript:

    import { Localization } from '@firebolt-js/sdk'
    
    Localization.countryCode(true)
    
    JSON-RPC:

    Request:

    {
      "jsonrpc": "2.0",
      "id": 1,
      "method": "localization.countryCode",
      "params": {}
    }
    

    Response:

    {
      "jsonrpc": "2.0",
      "id": 1,
      "result": "US"
    }
    

    To subscribe to notifications when the value changes, call the method like this:

    function countryCode (subscriber: () => void): Promise<listenerId>
    

    Parameters:

    ParamTypeRequiredSummary
    ``
    subscriberfunctionYesCallback to execute when the value changes.

    Promise resolution:

    TypeSummary
    listenerIdThe id of the listener that can be used with Localization.clear(listenerId) to unsubscribe

    Callback parameters:

    ParamTypeRequiredSummary
    ```

    Examples

    JavaScript:

    import { Localization } from '@firebolt-js/sdk'
    
    Localization.countryCode((value) => {
      // property value was changed
      console.log(value)
    }).then(listenerId => {
      // you can clear this listener w/ Localization.clear(listenerId)
    })
    

    value of value:

    JSON-RPC:

    Request:

    Response:

    {
      "jsonrpc": "2.0",
      "id": "1",
      "result": {
        "listening": "true"
      }
    }
    

    language

    Get the ISO 639 1/2 code for the preferred language

    To get the value of language call the method like this:

    function language(): Promise<Language>
    

    Promise resolution:

    TypeDescription
    Languagethe device language

    Examples

    Default Example

    JavaScript:

    import { Localization } from '@firebolt-js/sdk'
    
    Localization.language()
        .then(lang => {
            console.log(lang)
        })
    

    Value of lang:

    "en"
    
    JSON-RPC:

    Request:

    {
      "jsonrpc": "2.0",
      "id": 1,
      "method": "localization.language",
      "params": {}
    }
    

    Response:

    {
      "jsonrpc": "2.0",
      "id": 1,
      "result": "en"
    }
    

    To set the value of language call the method like this:

    function language(): Promise<ListenResponse | Language>
    

    Parameters:

    ParamTypeRequiredSummary

    Promise resolution:

    TypeSummary
    voidPromise resolves with no value when the operation is complete.

    Examples

    Default Example

    JavaScript:

    import { Localization } from '@firebolt-js/sdk'
    
    Localization.language(true)
    
    JSON-RPC:

    Request:

    {
      "jsonrpc": "2.0",
      "id": 1,
      "method": "localization.language",
      "params": {}
    }
    

    Response:

    {
      "jsonrpc": "2.0",
      "id": 1,
      "result": "en"
    }
    

    To subscribe to notifications when the value changes, call the method like this:

    function language (subscriber: () => void): Promise<listenerId>
    

    Parameters:

    ParamTypeRequiredSummary
    ``
    subscriberfunctionYesCallback to execute when the value changes.

    Promise resolution:

    TypeSummary
    listenerIdThe id of the listener that can be used with Localization.clear(listenerId) to unsubscribe

    Callback parameters:

    ParamTypeRequiredSummary
    ```

    Examples

    JavaScript:

    import { Localization } from '@firebolt-js/sdk'
    
    Localization.language((value) => {
      // property value was changed
      console.log(value)
    }).then(listenerId => {
      // you can clear this listener w/ Localization.clear(listenerId)
    })
    

    value of value:

    JSON-RPC:

    Request:

    Response:

    {
      "jsonrpc": "2.0",
      "id": "1",
      "result": {
        "listening": "true"
      }
    }
    

    latlon

    Get the approximate latitude and longitude coordinates of the device location

    function latlon(): Promise<[number, number]>
    

    Promise resolution:

    TypeDescription
    [number, number]lat/long tuple

    Examples

    Default Example

    JavaScript:

    import { Localization } from '@firebolt-js/sdk'
    
    Localization.latlon()
        .then(latlong => {
            console.log(latlong)
        })
    

    Value of latlong:

    [
      39.9549,
      75.1699
    ]
    
    JSON-RPC:

    Request:

    {
      "jsonrpc": "2.0",
      "id": 1,
      "method": "localization.latlon",
      "params": {}
    }
    

    Response:

    {
      "jsonrpc": "2.0",
      "id": 1,
      "result": [
        39.9549,
        75.1699
      ]
    }
    

    listen

    Listen for events from this module.

    To listen to a specific event pass the event name as the first parameter:

    Localization.listen(event: string, (data: any) => void): Promise<number>
    

    Parameters:

    ParamTypeRequiredSummary
    eventstringYesThe event to listen for, see Events.
    callbackfunctionYesA function that will be invoked when the event occurs.

    Promise resolution:

    TypeDescription
    numberListener ID to clear the callback method and stop receiving the event, e.g. Localization.clear(id)

    Callback parameters:

    ParamTypeRequiredSummary
    dataanyYesThe event data, which depends on which event is firing, see Events.

    To listen to all events from this module pass only a callback, without specifying an event name:

    Localization.listen((event: string, data: any) => void): Promise<number>
    

    Parameters:

    ParamTypeRequiredSummary
    callbackfunctionYesA function that will be invoked when the event occurs. The event data depends on which event is firing, see Events.

    Callback parameters:

    ParamTypeRequiredSummary
    eventstringYesThe event that has occured listen for, see Events.
    dataanyYesThe event data, which depends on which event is firing, see Events.

    Promise resolution:

    TypeDescription
    numberListener ID to clear the callback method and stop receiving the event, e.g. Localization.clear(id)

    See Listening for events for more information and examples.


    locale

    Get the full BCP 47 code, including script, region, variant, etc., for the preferred langauage/locale

    To get the value of locale call the method like this:

    function locale(): Promise<Locale>
    

    Promise resolution:

    TypeDescription
    Localethe device locale

    Examples

    Default Example

    JavaScript:

    import { Localization } from '@firebolt-js/sdk'
    
    Localization.locale()
        .then(locale => {
            console.log(locale)
        })
    

    Value of locale:

    "en-US"
    
    JSON-RPC:

    Request:

    {
      "jsonrpc": "2.0",
      "id": 1,
      "method": "localization.locale",
      "params": {}
    }
    

    Response:

    {
      "jsonrpc": "2.0",
      "id": 1,
      "result": "en-US"
    }
    

    To set the value of locale call the method like this:

    function locale(): Promise<ListenResponse | Locale>
    

    Parameters:

    ParamTypeRequiredSummary

    Promise resolution:

    TypeSummary
    voidPromise resolves with no value when the operation is complete.

    Examples

    Default Example

    JavaScript:

    import { Localization } from '@firebolt-js/sdk'
    
    Localization.locale(true)
    
    JSON-RPC:

    Request:

    {
      "jsonrpc": "2.0",
      "id": 1,
      "method": "localization.locale",
      "params": {}
    }
    

    Response:

    {
      "jsonrpc": "2.0",
      "id": 1,
      "result": "en-US"
    }
    

    To subscribe to notifications when the value changes, call the method like this:

    function locale (subscriber: () => void): Promise<listenerId>
    

    Parameters:

    ParamTypeRequiredSummary
    ``
    subscriberfunctionYesCallback to execute when the value changes.

    Promise resolution:

    TypeSummary
    listenerIdThe id of the listener that can be used with Localization.clear(listenerId) to unsubscribe

    Callback parameters:

    ParamTypeRequiredSummary
    ```

    Examples

    JavaScript:

    import { Localization } from '@firebolt-js/sdk'
    
    Localization.locale((value) => {
      // property value was changed
      console.log(value)
    }).then(listenerId => {
      // you can clear this listener w/ Localization.clear(listenerId)
    })
    

    value of value:

    JSON-RPC:

    Request:

    Response:

    {
      "jsonrpc": "2.0",
      "id": "1",
      "result": {
        "listening": "true"
      }
    }
    

    locality

    Get the locality/city the device is located in

    function locality(): Promise<Locality>
    

    Promise resolution:

    TypeDescription
    Localitythe device city

    Examples

    Default Example

    JavaScript:

    import { Localization } from '@firebolt-js/sdk'
    
    Localization.locality()
        .then(locality => {
            console.log(locality)
        })
    

    Value of locality:

    "Philadelphia"
    
    JSON-RPC:

    Request:

    {
      "jsonrpc": "2.0",
      "id": 1,
      "method": "localization.locality",
      "params": {}
    }
    

    Response:

    {
      "jsonrpc": "2.0",
      "id": 1,
      "result": "Philadelphia"
    }
    

    once

    Listen for only one occurance of an event from this module. The callback will be cleared after one event.

    To listen to a specific event pass the event name as the first parameter:

    Localization.once(event: string, (data: any) => void): Promise<number>
    

    Parameters:

    ParamTypeRequiredSummary
    eventstringYesThe event to listen for, see Events.
    callbackfunctionYesA function that will be invoked when the event occurs.

    Promise resolution:

    TypeDescription
    numberListener ID to clear the callback method and stop receiving the event, e.g. Localization.clear(id)

    Callback parameters:

    ParamTypeRequiredSummary
    dataanyYesThe event data, which depends on which event is firing, see Events.

    To listen to all events from this module pass only a callback, without specifying an event name:

    Localization.once((event: string, data: any) => void): Promise<number>
    

    Parameters:

    ParamTypeRequiredSummary
    callbackfunctionYesA function that will be invoked when the event occurs. The event data depends on which event is firing, see Events.

    Callback parameters:

    ParamTypeRequiredSummary
    eventstringYesThe event that has occured listen for, see Events.
    dataanyYesThe event data, which depends on which event is firing, see Events.

    Promise resolution:

    TypeDescription
    numberListener ID to clear the callback method and stop receiving the event, e.g. Localization.clear(id)

    See Listening for events for more information and examples.


    postalCode

    Get the postal code the device is located in

    To get the value of postalCode call the method like this:

    function postalCode(): Promise<string>
    

    Promise resolution:

    TypeDescription
    stringthe device postal code

    Examples

    Default Example

    JavaScript:

    import { Localization } from '@firebolt-js/sdk'
    
    Localization.postalCode()
        .then(postalCode => {
            console.log(postalCode)
        })
    

    Value of postalCode:

    "19103"
    
    JSON-RPC:

    Request:

    {
      "jsonrpc": "2.0",
      "id": 1,
      "method": "localization.postalCode",
      "params": {}
    }
    

    Response:

    {
      "jsonrpc": "2.0",
      "id": 1,
      "result": "19103"
    }
    

    To set the value of postalCode call the method like this:

    function postalCode(): Promise<ListenResponse | string>
    

    Parameters:

    ParamTypeRequiredSummary

    Promise resolution:

    TypeSummary
    voidPromise resolves with no value when the operation is complete.

    Examples

    Default Example

    JavaScript:

    import { Localization } from '@firebolt-js/sdk'
    
    Localization.postalCode(true)
    
    JSON-RPC:

    Request:

    {
      "jsonrpc": "2.0",
      "id": 1,
      "method": "localization.postalCode",
      "params": {}
    }
    

    Response:

    {
      "jsonrpc": "2.0",
      "id": 1,
      "result": "19103"
    }
    

    To subscribe to notifications when the value changes, call the method like this:

    function postalCode (subscriber: () => void): Promise<listenerId>
    

    Parameters:

    ParamTypeRequiredSummary
    ``
    subscriberfunctionYesCallback to execute when the value changes.

    Promise resolution:

    TypeSummary
    listenerIdThe id of the listener that can be used with Localization.clear(listenerId) to unsubscribe

    Callback parameters:

    ParamTypeRequiredSummary
    ```

    Examples

    JavaScript:

    import { Localization } from '@firebolt-js/sdk'
    
    Localization.postalCode((value) => {
      // property value was changed
      console.log(value)
    }).then(listenerId => {
      // you can clear this listener w/ Localization.clear(listenerId)
    })
    

    value of value:

    JSON-RPC:

    Request:

    Response:

    {
      "jsonrpc": "2.0",
      "id": "1",
      "result": {
        "listening": "true"
      }
    }
    

    Events

    Additional events

    The following events are documented as part of a related set of method APIs.

    For more information, follow the links under the "Documentation" column.

    JavaScriptRPCPayloadDocumentation
    stalCodepostalCodeListenResponsepostalCode
    untryCodecountryCodeListenResponsecountryCode
    nguagelanguageListenResponselanguage
    calelocaleListenResponselocale

    Schemas

    LatLon

    type LatLon = [number, number]
    


    Was this article helpful?

    What's Next