本地化
这是什么 / 何时用
本地化静态数据:当前用户 Locale,以及国家、大洲、货币、语言、时区等清单。客户端与服务端都可用(客户端受用户 Session 约束)。
使用骨架
locale.get() 取当前用户 Locale;listCountries / listContinents / listCountriesEU / listCountriesPhones / listCurrencies / listLanguages / listCodes 取静态数据。
关键参数与返回
- 列表返回
List模型(total+entries);静态数据随实例版本更新,不做客户端缓存假设。
各语言调用示例
客户端与服务端均可用;Web 页签走用户 Session,受数据面权限约束。
- Node.js(Server)
- Web(用户 Session)
- Java
- Python
- Go
- REST(curl)
import { Locale } from 'agentbase-node-sdk';
const locale = new Locale(client);
await locale.get(); // 当前用户 Locale
await locale.listCountries(); // 静态清单:listContinents / listCountriesEU / listCountriesPhones / listCurrencies / listLanguages / listCodes
// 列表统一返回 total + entriesimport { Locale } from 'agentbase-web-sdk';
const locale = new Locale(client);
await locale.get();
await locale.listCountries();locale.get(); // 当前用户 Locale
locale.listCountries(); // 静态清单:listContinents / listCountriesEU / listCountriesPhones / listCurrencies / listLanguages / listCodes
// 列表统一返回 total + entriesfrom agentbase.services.locale import Locale
locale = Locale(client)
locale.get()
locale.list_countries()locale := agentbase.NewLocale(cl) // facade 构造器;cl 为已装载 API Key 的 Client
loc, _ := locale.Get() // 当前用户 Locale
_ = loc
countries, _ := locale.ListCountries() // 静态清单:ListContinents / ListCountriesEU / ListCountriesPhones / ListCurrencies / ListLanguages / ListCodes
_ = countries // 列表统一返回 total + entriescurl -sS "$APPBASE_ENDPOINT/v1/locale" \
-H "X-Appwrite-Project: $APPBASE_PROJECT_ID" -H "X-Appwrite-Key: $APPBASE_API_KEY"
# 静态清单:GET /v1/locale/countries、/countries/eu、/countries/phones、/continents、/currencies、/languages、/codesSDK 类别差异
- Server SDK / Console SDK / 客户端 SDK:均可用。
事实源
skills/ob-agentbase/references/server-sdks/nodejs.md(模块表)- appbase v2.7.0(tag v2.7.0)
- agentbase-sdks v2.7.0 specs(
packages/sdks/server-nodejs/src/services/locale.ts方法面)