Options
All
  • Public
  • Public/Protected
  • All
Menu

TranslationService is the Service responsible for translation. Current implmenetation supports SalesForce Custom Labels and Dictionaries.

Hierarchy

Index

Constructors

constructor

Properties

Private config

The config used to initialize this SDK.

Private dictionary

dictionary: __type

Private labelStorage

labelStorage: Map<string, string> = new Map<string, string>()

The label storage. This will used when there is no Local storage

Private locale

locale: string

Static Private instance

instance: Translation

Accessors

namespace

  • get namespace(): string
  • set namespace(customNamespace: string): void
  • getter method for namespace. Provides the salesforce org namespace

    Returns string

  • setter method for namespace. Set custom namespace

    Parameters

    • customNamespace: string

    Returns void

Methods

clearLabelStorage

  • clearLabelStorage(): boolean
  • Clear the label storage. This will remove all labels in storage.

    Returns boolean

    true on successfully clearing the label storage.

createFetchTranslationsInput

  • Create an input object of the FetchTranslationInput.

    Returns FetchTranslationsInput

    • input object that contains the labels needs to be fetched.

Private fetchAnonymousUserTranslation

  • fetchAnonymousUserTranslation(input: any): Promise<void>
  • Parameters

    • input: any

    Returns Promise<void>

fetchTranslations

  • This function fetch the translations for a given set of label(s) with the language provided.

    Parameters

    Returns Promise<any>

    • promise that will get all the translated labels and keep them in labelStorage.

Private getAuthorisationType

  • getAuthorisationType(): string
  • Returns string

Private getLabelsFromLocalStorage

  • getLabelsFromLocalStorage(): any
  • Returns any

getLabelsInCache

  • getLabelsInCache(): object
  • Return the labels in cache as a JSON Object with label key as the key and the custom label as the value.

    Returns object

    JSON objec to label keys and translated labels as values.

Private getLabelsNotInCache

  • Check the input.textToTranslate contains labels that are already in labelStorage. If already exists in labelStorage, remove it from input.textToTranslate.

    Parameters

    Returns Promise<FetchTranslationsInput>

    • Promise with updated input.textToTranslate.

Private getQueryStringParameters

  • getQueryStringParameters(path: any, input: any): any
  • Parameters

    • path: any
    • input: any

    Returns any

Private getTranslationDictionary

  • Parameters

    Returns Promise<any>

Private handleLocalStorage

  • handleLocalStorage(localStorageVal: any, data: any): number
  • Parameters

    • localStorageVal: any
    • data: any

    Returns number

labelStorageCount

  • labelStorageCount(): number
  • Returns the number of labels in labelStorage.

    Returns number

    • count of labels cached in labelStorage.

Private manipulateAndStoreLabelData

  • manipulateAndStoreLabelData(data: any): Promise<number>
  • Parameters

    • data: any

    Returns Promise<number>

Private setDataToLocalStorage

  • setDataToLocalStorage(data: any): number
  • Parameters

    • data: any

    Returns number

Private storeDataInCache

  • storeDataInCache(data: any): Promise<number>
  • Parameters

    • data: any

    Returns Promise<number>

Private storeLabelsInCache

  • storeLabelsInCache(labelsData: object): number
  • Store translated labels in cache.

    Parameters

    • labelsData: object

    Returns number

    number of labels stored.

translate

  • translate(label: string): string
  • Get the corresponding translated string for a given label. fetch() must be called first before calling this function. This function translates only strings exist in local Storage/this.labelStorage. Otherwise, it will return the provided label.

    Parameters

    • label: string

    Returns string

    • translatedLabel that is translated if exists. Otherwise, return the provided label.

version

  • version(): string
  • Returns the version number of SDK.

    Returns string

    Returns SDK version number as string

Static extend

  • extend(extendObj: object): void
  • Adds all the enumerable string keyed function properties of a source object to the sdk prototype. .extend should only be used to add new methods and it won't override the existing methods.

    Note: If the property already exists, it will be not be added.

    Custom functions which are being extended should have proper namespaces to avoid issues during upgrades. When Vlocity releases new changes it won't impact if unique namespaces are used.

    Example: myCompanyOrFeatureMethodName

    example

    How to extend an sdk?

    VlocitySDK.datasource.extend({ myCompanySayHello(){
         console.log("Hello World");
      }, sayTime() {
         console.log(new Date().myCompanyGetTime());
      }});
    
    const dataSource = VlocitySDK.datasource.getInstance({'create':true});
    console.log(daSource.myCompanySayHello())

    Parameters

    • extendObj: object

      The object of functions

    Returns void

Static getInstance

  • Get a singleton instance of this Translation.

    Parameters

    Returns Translation

    an instance of this SDK.

Static override

  • override(overrideObj: object): void
  • Adds all the enumerable string keyed function properties of a source object to the sdk prototype.

    .override method should only be used to override the existing methods and should only be used in rare cases. Overriding the existing or default methods may cause unintended consequences and may also impact during upgrades.

    Please be cautious while using this

    example

    How to override methods in an sdk?

    VlocitySDK.datasource.override({ soql(){
         console.log("This code overrides the default soql function");
         // code goes here...
      }, sosl() {
         console.log("This code overrides the default soql function");
         // code goes here...
      }});
    
    const dataSource = VlocitySDK.datasource.getInstance({'create':true});
    console.log(dataSource.soql()); // prints "This code overrides the default soql function"

    Parameters

    • overrideObj: object

      The object of functions

    Returns void

Generated using TypeDoc