as

Settings
Sign out
Notifications
Alexa
亚马逊应用商店
AWS
文档
Support
Contact Us
My Cases
新手入门
设计和开发
应用发布
参考
支持

ProductNameFormat

ProductNameFormat

ProductNameFormat API提供使用产品名称替换来格式化字符串的方法。在格式字符串资源中,参数模式$(pn)用作产品名称的占位符。

格式化方法可以使用多个产品名称类型。以下是不同类型亚马逊Echo Show 5产品名称的示例,

类型 名称
Generic Device
Short Echo Show
Medium Echo Show 5
Long Echo Show 5 (3rd Gen)
Full Amazon Echo Show 5
Generational Amazon Echo Show 5 (3rd Gen)

Default(默认)类型也可用,并映射到Medium类型。

示例

import { ProductNameFormat, ProductNameType } from '@amazon-devices/keplerscript-kepleri18n-lib';
...
    // 从字符串资源中检索模式。为了简化示例,在此对其进行了硬编码。
    const pattern: string = "此$(pn)已启用wifi。";
    const message: string | null = ProductNameFormat.format(pattern, ProductNameType.MEDIUM);
    if (message === null) {
        // 错误
        return;
    }
    // 对于上面的亚马逊Echo Show 5产品名称示例,消息为“This Echo Show 5 is wifi enabled”(这款Echo Show 5已启用wifi)。

构造函数

new ProductNameFormat()

new ProductNameFormat(): ProductNameFormat

返回值

ProductNameFormat

方法

format()

static format(pattern, productNameType, args?): null | string

使用产品名称替换针对默认区域设置来格式化指定模式。或者,该模式也可以是带有命名参数的MessageFormatClassic模式。该模式应包含一个或多个“$ (pn)”子字符串作为产品名称的占位符。

此外,此方法支持“pngender”,用于选择产品名称的性别信息。要使用它,只需指定“pngender”来代替IMessageFormatClassic select-format参数,然后根据可能的性别(其他、阴性、阳性、中性、女性、男性)编写select-format子句。例如,

参数

pattern

string

要格式化的模式。

productNameType

ProductNameType = ProductNameType.DEFAULT

要使用的产品名称的类型。

args

Map<string, string | number | Date>

参数名称与其值的可选映射。

返回值

null | string

格式化消息,成功时使用指定的产品名称替换“$ (pn)”,失败时为null。

示例

{pngender, select,
    feminine {$(pn) displays a notification on her screen.}
    masculine {$(pn) displays a notification on his screen.}
    other {$(pn) displays a notification on its screen.}}

如果当前产品性别为女性且产品名称为“Echo Show”,则此方法将返回“Echo Show displays a notification on her screen”(Echo Show在她的屏幕上显示通知)。

[!重要] 不要使用“pngender”这个名称作为命名参数,因为它是由ProductNameFormat提供的保留密钥。如果在参数映射中传递了“pngender”命名参数,则此方法将失败。


formatPositional()

static formatPositional(pattern, productNameType, …args): null | string

使用产品名称替换针对默认区域设置来格式化指定模式。或者,该模式也可以是带有编号参数的MessageFormatClassic模式。该模式应包含一个或多个“$ (pn)”子字符串作为产品名称的占位符。

有关对于“pngender”产品名称性别信息选择的支持,请参阅format() 方法。

参数

pattern

string

要格式化的模式。

productNameType

ProductNameType = ProductNameType.DEFAULT

要使用的产品名称的类型。

args

…(string | number | Date)[]

可选的参数值数组

返回值

null | string

格式化消息,成功时使用指定的产品名称替换“$ (pn)”,失败时为null。


getMajorVersion()

static getMajorVersion(): number

获取主版本号。

返回值

number

主版本号。


getMinorVersion()

static getMinorVersion(): number

获取次版本号。

返回值

number

次版本号。


getPatchVersion()

static getPatchVersion(): number

获取补丁版本号。

返回值

number

补丁版本号。


Last updated: 2025年9月29日