Localization

    Localization


    Article summary

    LocalizationModule 0.5.3

    Usage

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

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

    Overview

    Methods for accessessing location and language preferences

    Events

    Methods

    locality

    Get the locality/city the device is located in

    function locality(): Promise<string>
    

    Promise Resolution

    TypeDescription
    stringthe 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"
    }
    

    postalCode

    Get the postal code the device is located in

    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"
    }
    

    countryCode

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

    function countryCode(): Promise<string>
    

    Promise Resolution

    TypeDescription
    stringthe 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"
    }
    

    language

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

    function language(): Promise<string>
    

    Promise Resolution

    TypeDescription
    stringthe 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"
    }
    

    locale

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

    function locale(): Promise<string>
    

    Promise Resolution

    TypeDescription
    stringthe 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"
    }
    

    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
      ]
    }
    

    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": {}
    }
    

    Schemas

    LatLon

    type LatLon = [number, number]
    


    Was this article helpful?

    What's Next