npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@byteluck-fe/locale-message-backend

v1.0.4

Published

后端国际化工具包,用于初始化加载语言包到内存,并通过 key 获取对应语言的国际化文本。

Readme

locale-message 后端国际化

后端国际化工具包,用于初始化加载语言包到内存,并通过 key 获取对应语言的国际化文本。

包目录结构与 front 前端国际化包保持一致,主要入口仍是 src/index.ts,构建入口仍是 vite.config.ts。区别只在运行逻辑:后端包从平台接口拉取所有激活语言的语言包,缓存到 Node.js 进程内存中。

使用方式

import {
	getLocaleText,
	initSetBackendI18nMessages,
} from '@byteluck/locale-message-backend'

await initSetBackendI18nMessages({
	project: 'FDE',
	baseUrl: 'https://example.com',
	getCurrentLocale: () => {
		// 从当前项目的运行时上下文中读取当前语言,例如 fde-workbench 的 responseLocale。
		return runContextStore.get()?.responseLocale
	},
})

const text = getLocaleText('FDE.common.saveSuccessful')

初始化方法

initSetBackendI18nMessages 会先请求语言列表接口:

POST /apps/api/v1/sp/ai/language/lisAllLangBo
Content-Type: application/json

{}

接口响应中的语言数组位于 data 字段。初始化方法会过滤掉 is_active: false 的语言,再按激活语言逐个请求语言包接口:

/apps/api/v1/sp/ai/language/langInfo?langCode=语言编码&project=项目简称

接口返回的语言包会缓存在后端进程内存中。

baseUrl 也可以通过环境变量 LOCALE_MESSAGE_BASE_URL 提供。

当前语言建议通过初始化参数 getCurrentLocale 注入:

await initSetBackendI18nMessages({
	project: 'FDE',
	baseUrl: 'https://example.com',
	getCurrentLocale: () => resolveWorkbenchResponseLocale(runContextStore.get()?.responseLocale),
})

getLocaleText 每次执行时都会调用 getCurrentLocale,再从内存中读取对应语言的文案。

如果没有传 getCurrentLocale,可以通过初始化参数 locale 或环境变量 LOCALE_MESSAGE_LOCALE 指定固定语言;都不传时默认使用 zh-CN。

获取文本

getLocaleText 的参数顺序是:

getLocaleText(key, replaceObj?, failBack?)

当 getCurrentLocale 返回的语言在平台不存在、值为空、值有误,或者当前语言下没有对应 key 时,会自动使用 zh-CN 中文文案兜底。

其他导出

后端包也导出了和前端包一致的基础枚举与内存消息更新方法:

import {
	LocaleEnum,
	updateLocalMessage,
} from '@byteluck/locale-message-backend'

updateLocalMessage(messages, locale?) 可用于手动把语言包内容合并进内存缓存;不传 locale 时会写入当前语言。