Description

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.

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
/*
@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;
}
interface LocalizationSystem {
    language: string;
    getDateAndTimeFormatted(date): string;
    getDateFormatted(date): string;
    getDateShortFormatted(date): string;
    getDayOfWeek(date): string;
    getFormattedDistanceFromMeters(meters): string;
    getFormattedNumber(number): string;
    getFormattedSeconds(seconds): string;
    getFormattedTemperatureFromCelsius(temperature): string;
    getFormattedTemperatureFromFahrenheit(temperature): string;
    getLanguage(): string;
    getMonth(date): string;
    getTimeFormatted(date): string;
    getTypeName(): string;
    isOfType(type): boolean;
    isSame(other): boolean;
    localize(key): string;
}

Hierarchy (view full)

Properties

language: string

Exposes User Data

Description

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

Methods

  • Parameters

    • date: Date

    Returns string

    Description

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

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

  • Parameters

    • date: Date

    Returns string

    Description

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

    Example: "Jan 1, 2019"

  • Parameters

    • date: Date

    Returns string

    Description

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

    Example: "1/1/19"

  • Parameters

    • date: Date

    Returns string

    Description

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

    Example: "Tuesday"

  • Parameters

    • meters: number

    Returns string

    Description

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

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

  • Parameters

    • number: number

    Returns string

    Description

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

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

  • Parameters

    • seconds: number

    Returns string

    Description

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

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

  • Parameters

    • temperature: number

    Returns string

    Description

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

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

  • Parameters

    • temperature: number

    Returns string

    Description

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

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

  • Returns string

    Exposes User Data

    Description

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

    Example: "en" (for English)

  • Parameters

    • date: Date

    Returns string

    Description

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

    Example: "January"

  • Parameters

    • date: Date

    Returns string

    Description

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

    Example: "12:34 AM"

  • Returns string

    Description

    Returns the name of this object's type.

  • Parameters

    • type: string

    Returns boolean

    Description

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

  • Parameters

    Returns boolean

    Description

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

  • Parameters

    • key: string

    Returns string

    Exposes User Data

    Description

    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.

Generated using TypeDoc