as

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

react-native-localize

react-native-localize

@amazon-devices/react-native-localize是一个库,用于在适用于Vega的React Native (RNK) 应用中使用Localize React Native。该库提供本地化和国际化支持,让您可以根据不同的语言、地区和文化调整应用。

安装

要使用该程序包,请在应用的package.json文件中添加JavaScript库依赖项,如下所示。

已复制到剪贴板。

    "dependencies": {
         ...
         "@amazon-devices/react-native-localize": "~2.0.0"
    }

示例

以下是如何使用@amazon-devices/react-native-localize的示例。

已复制到剪贴板。

import { getCurrencies, getLocales } from "@amazon-devices/react-native-localize";

console.log(getLocales());
console.log(getCurrencies());

API参考

getLocales()

按顺序返回用户的首选区域设置。

方法类型

已复制到剪贴板。

type getLocales = () => Array<{
  languageCode: string;
  scriptCode?: string;
  countryCode: string;
  languageTag: string;
  isRTL: boolean;
}>;

示例

已复制到剪贴板。

import { getLocales } from "@amazon-devices/react-native-localize";

console.log(getLocales());
/* -> [
  { countryCode: "GB", languageTag: "en-GB", languageCode: "en", isRTL: false },
  { countryCode: "US", languageTag: "en-US", languageCode: "en", isRTL: false },
  { countryCode: "FR", languageTag: "fr-FR", languageCode: "fr", isRTL: false },
] */

getNumberFormatSettings()

返回数字格式化设置。

方法类型

已复制到剪贴板。

type getNumberFormatSettings = () => {
  decimalSeparator: string;
  groupingSeparator: string;
};

示例

已复制到剪贴板。

import { getNumberFormatSettings } from "@amazon-devices/react-native-localize";

console.log(getNumberFormatSettings());
/* -> {
  decimalSeparator: ".",
  groupingSeparator: ",",
} */

getCurrencies()

按顺序返回用户的首选货币代码。

方法类型

已复制到剪贴板。

type getCurrencies = () => string[];

示例

已复制到剪贴板。

import { getCurrencies } from "@amazon-devices/react-native-localize";

console.log(getCurrencies());
// -> ["EUR", "GBP", "USD"]

getCountry()

根据用户的设备区域设置而不是位置返回用户当前的国家/地区代码。

方法类型

已复制到剪贴板。

type getCountry = () => string;

示例

已复制到剪贴板。

import { getCountry } from "@amazon-devices/react-native-localize";

console.log(getCountry());
// -> "FR"

拉丁美洲地区

使用拉丁美洲区域设置的设备将返回“UN”而不是“419”,因为“419”不是标准的国家/地区代码。


getCalendar()

返回用户的首选日历格式。

方法类型

已复制到剪贴板。

type getCalendar = () =>
  | "gregorian"
  | "buddhist"
  | "coptic"
  | "ethiopic"
  | "ethiopic-amete-alem"
  | "hebrew"
  | "indian"
  | "islamic"
  | "islamic-umm-al-qura"
  | "islamic-civil"
  | "islamic-tabular"
  | "iso8601"
  | "japanese"
  | "persian";

示例

已复制到剪贴板。

import { getCalendar } from "@amazon-devices/react-native-localize";

console.log(getCalendar());
// -> "gregorian"

getTemperatureUnit()

返回用户的首选温度单位。

方法类型

已复制到剪贴板。

type getTemperatureUnit = () => "celsius" | "fahrenheit";

示例

已复制到剪贴板。

import { getTemperatureUnit } from "@amazon-devices/react-native-localize";

console.log(getTemperatureUnit());
// -> "celsius"

getTimeZone()

根据用户的设备设置而不是位置返回用户的首选时区。

方法类型

已复制到剪贴板。

type getTimeZone = () => string;

示例

已复制到剪贴板。

import { getTimeZone } from "@amazon-devices/react-native-localize";

console.log(getTimeZone());
// -> "Asia/Yerevan"

uses24HourClock()

如果用户偏好24小时的时钟格式,则返回true;如果用户偏好12小时的时钟格式,则返回false

方法类型

已复制到剪贴板。

type uses24HourClock = () => boolean;

示例

已复制到剪贴板。

import { uses24HourClock } from "@amazon-devices/react-native-localize";

console.log(uses24HourClock());
// -> true

usesMetricSystem()

如果用户偏好公制度量系统,则返回true;如果用户偏好英制度量系统,则返回false

方法类型

已复制到剪贴板。

type usesMetricSystem = () => boolean;

示例

已复制到剪贴板。

import { usesMetricSystem } from "@amazon-devices/react-native-localize";

console.log(usesMetricSystem());
// -> true

usesAutoDateAndTime()

告知设备是否启用自动日期和时间设置。

方法类型

已复制到剪贴板。

type usesAutoDateAndTime = () => boolean | undefined;

示例

已复制到剪贴板。

import { usesAutoDateAndTime } from "@amazon-devices/react-native-localize";

console.log(usesAutoDateAndTime());
// -> false/true

usesAutoTimeZone()

告知设备是否启用自动时区设置。

方法类型

已复制到剪贴板。

type usesAutoTimeZone = () => boolean | undefined;

示例

已复制到剪贴板。

import { usesAutoTimeZone } from "@amazon-devices/react-native-localize";

console.log(usesAutoTimeZone());
// -> false

支持的版本

程序包名称 亚马逊NPM库版本 Vega OS内部版本号 Vega SDK版本 发行说明
@amazon-devices/react-native-localize 2.0.1+3.0.4 OS 1.1 (201010438050) 0.20  

Last updated: 2025年9月30日