Skip to main content

LocalizationSystem

Class

Helps convert data types to localized string representations.

  • Available on all platforms
Platform details: Snapchat, SPECS, Camera Kit Web, Camera Kit Mobile fully supported.

Platform details

  • Snapchat — Fully supported.

  • SPECS — Fully supported.

  • Camera Kit Web — Fully supported.

  • Camera Kit Mobile — Fully supported.

Helps convert data types to localized string representations. Accessible through global.localizationSystem.

Note that formatted or localized strings may appear differently to users depending on their region. The example results given here are representative of a user in the United States, but may appear differently for users in other regions.

Index

Example

// get today date and time
var currentDate = new Date();
print("Today is: " + global.localizationSystem.getDayOfWeek(currentDate));
print("The current time is: " + global.localizationSystem.getTimeFormatted(currentDate));
// get tomorrow's date
var tomorrow = new Date();
tomorrow.setDate(currentDate.getDate()+1);
print("Tomorrow's date is: " + global.localizationSystem.getDateFormatted(tomorrow));
// show image based on locale
// FIXME: Wrap the following block in a comment block
@typedef LanguageTexturePair
@property {string} language
@property {Asset.Texture} texture

//@input Asset.Texture defaultTex

//@input Component.Image image
//@input LanguageTexturePair[] pairs

var lang = global.localizationSystem.getLanguage();
var lMap = {}

for (var i = 0; i < script.pairs.length; i++) {
lMap[script.pairs[i].language] = script.pairs[i].texture;
}
if (lMap[lang] != undefined) {
script.image.mainMaterial.mainPass.baseTex = lMap[lang];
} else {
script.image.mainMaterial.mainPass.baseTex = script.defaultTex;
}

Extends

Properties

language

language: string

Exposes user data

Use this property to set the language. Intended for debugging.

Methods

getDateAndTimeFormatted()

getDateAndTimeFormatted(date): string

Returns a localized string for the date and time of the passed in Date object.

Example: "Jan 1, 2019 at 12:34 AM"

Parameters

ParameterType
dateDate

Returns

string


getDateFormatted()

getDateFormatted(date): string

Returns a localized string for the date of the passed in Date object.

Example: "Jan 1, 2019"

Parameters

ParameterType
dateDate

Returns

string


getDateShortFormatted()

getDateShortFormatted(date): string

Returns a short, localized string for the date of the passed in Date object.

Example: "1/1/19"

Parameters

ParameterType
dateDate

Returns

string


getDayOfWeek()

getDayOfWeek(date): string

Returns a localized string for the day of the week of the passed in Date object.

Example: "Tuesday"

Parameters

ParameterType
dateDate

Returns

string


getFormattedDistanceFromMeters()

getFormattedDistanceFromMeters(meters): string

Returns a localized, formatted string representation of the distance in meters passed in.

Example: "39.4 in" (from 1 passed in)

Parameters

ParameterType
metersnumber

Returns

string


getFormattedNumber()

getFormattedNumber(number): string

Returns a localized, formatted string representation of the number passed in.

Example: "1,234" (from 1234 passed in)

Parameters

ParameterType
numbernumber

Returns

string


getFormattedSeconds()

getFormattedSeconds(seconds): string

Returns a localized, formatted string representing the number of seconds passed in.

Example: "2:06" (from 126 passed in)

Parameters

ParameterType
secondsnumber

Returns

string


getFormattedTemperatureFromCelsius()

getFormattedTemperatureFromCelsius(temperature): string

Returns a localized, formatted string representation of the celsius temperature passed in.

Example: "32°F" (from 0 passed in)

Parameters

ParameterType
temperaturenumber

Returns

string


getFormattedTemperatureFromFahrenheit()

getFormattedTemperatureFromFahrenheit(temperature): string

Returns a localized, formatted string representation of the fahrenheit temperature passed in.

Example: "32°F" (from 32 passed in)

Parameters

ParameterType
temperaturenumber

Returns

string


getLanguage()

getLanguage(): string

Exposes user data

Returns the language code of the language being used on the device.

Example: "en" (for English)

Returns

string


getMonth()

getMonth(date): string

Returns a localized string for the month of the passed in Date object.

Example: "January"

Parameters

ParameterType
dateDate

Returns

string


getTimeFormatted()

getTimeFormatted(date): string

Returns a localized string for the time of the passed in Date object.

Example: "12:34 AM"

Parameters

ParameterType
dateDate

Returns

string


getTypeName()

static getTypeName(): TypeName<LocalizationSystem>

Returns the fully-qualified JavaScript type name for this class (for example, "Component.Camera"). This is a static accessor (no instance required) and returns the same value as the instance getTypeName().

Returns

TypeName<LocalizationSystem>

Overrides

ScriptObject.getTypeName


getTypeName()

getTypeName(): string

Returns the name of this object's type.

Returns

string

Inherited from

ScriptObject.getTypeName


isOfType()

isOfType(type): boolean

Returns true if the object matches or derives from the passed in type.

Parameters

ParameterType
typestring

Returns

boolean

Inherited from

ScriptObject.isOfType


isSame()

isSame(other): boolean

Returns true if this object is the same as other. Useful for checking if two references point to the same thing.

Parameters

ParameterType
otherScriptObject

Returns

boolean

Inherited from

ScriptObject.isSame


localize()

localize(key): string

Exposes user data

The method takes a localization key and returns the localized string according to device language. Useful for localizing strings before formatting them and assigning them to Text.

Parameters

ParameterType
keystring

Returns

string

Since

Lens Scripting Version 155