Tutorial

Working with data

Table of contents
  1. Localized string

Localized String

LocalizedString in cplaceJS is returned as json-like object. In cplaceJS code it can either be used as javascript object or as java map.

var ls = page.get('cf.cplace.localizedString'); 
// ls is an object containing key-value pair of language to value. 
// Example:
/*
{
  en: 'English value',
  de: 'German value'
}
*/

cplace.log(ls.en); // prints - English value
// values can be accessed in multiple ways
ls.de 
ls['de']
ls.get('de')
// all of the above statements return value stored for German language.

If the value is not set for LocalizedString attribute then null is returned. If the attribute is multi valued then a list/array of localized strings are returned. If multi-valued attributes do not have any value set then an empty list is returned.

var lsList = page.get('cf.cplace.localizedStrings'); 
// lsList is an array containing json representation of localized string.
// Example:
/*
[
    {
      en: 'First English value',
      de: 'First German value'
    },
    {
      en: 'Second English value',
      de: 'Second German value'
    }
]
*/

cplace.log(lsList[0].en); // prints - First English value
// values of array can also be accessed in multiple ways

lsList[0]
lsList.get(0)
// both of the statements will return object at 0th index.