LocalizationSystem
ClassHelps convert data types to localized string representations.
- Available on all platforms
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
Properties
Methods
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
| Parameter | Type |
|---|---|
date | Date |
Returns
string
getDateFormatted()
getDateFormatted(
date):string
Returns a localized string for the date of the passed in Date object.
Example: "Jan 1, 2019"
Parameters
| Parameter | Type |
|---|---|
date | Date |
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
| Parameter | Type |
|---|---|
date | Date |
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
| Parameter | Type |
|---|---|
date | Date |
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
| Parameter | Type |
|---|---|
meters | number |
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
| Parameter | Type |
|---|---|
number | number |
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
| Parameter | Type |
|---|---|
seconds | number |
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
| Parameter | Type |
|---|---|
temperature | number |
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
| Parameter | Type |
|---|---|
temperature | number |
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
| Parameter | Type |
|---|---|
date | Date |
Returns
string
getTimeFormatted()
getTimeFormatted(
date):string
Returns a localized string for the time of the passed in Date object.
Example: "12:34 AM"
Parameters
| Parameter | Type |
|---|---|
date | Date |
Returns
string
getTypeName()
staticgetTypeName():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
getTypeName()
getTypeName():
string
Returns the name of this object's type.
Returns
string
Inherited from
isOfType()
isOfType(
type):boolean
Returns true if the object matches or derives from the passed in type.
Parameters
| Parameter | Type |
|---|---|
type | string |
Returns
boolean
Inherited from
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
| Parameter | Type |
|---|---|
other | ScriptObject |
Returns
boolean
Inherited from
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
| Parameter | Type |
|---|---|
key | string |
Returns
string
Since
Lens Scripting Version 155