文件
ParlzPackageManger/src/i18n.h
T
JGZYES 5a7d325f25 i18n: .pjson language-pack system + PMM output standard
- docs/STANDARD.md: unified banner (PMM <ver> (<arch>)), command wording,
  help layout, CHANGELOG and .pjson key-naming conventions.
- src/i18n.c/.h: pmm_tr / pmm_tr_fmt / pmm_lang_load(_active) / set_locale with
  LANG|LC_ALL auto-detect, loading a flattened key->value .pjson from
  ~/.pmm/lang/<locale>.pjson.
- pmm setting lang -l | <locale>: list installed packs; download <locale>.pjson
  from the registry mirror into ~/.pmm/lang/, persist language=<locale> in
  pmm.conf and reload. PmmConfig gains a language field (read from json/ini/conf).
- Banner + version now standardised: PMM 0.3.5 (amd64) (no OS name / brackets).
- web/mirror/lang/{zh-CN,en-US}.pjson built-in packs; web/translate.php lists
  packs (keys + download) and explains community contribution; nav now has a
  翻译 item.
- Makefile/build.bat/release.yml include src/i18n.c.

Verified on WSL: compiles; version/help banner -> 'PMM 0.3.5 (amd64)';
pmm setting lang -l lists the packs dir.
2026-09-04 21:49:02 +08:00

37 行
1.4 KiB
C

/* i18n.h - .pjson language-pack (translation) support
*
* PMM loads a flattened key->value JSON file (".pjson") for the current locale
* and resolves user-facing strings through pmm_tr()/pmm_tr_fmt(). Keys follow
* docs/STANDARD.md ("区域.语义", e.g. "msg.installed"). Falls back to the key
* itself when a translation is absent.
*/
#ifndef PMM_I18N_H
#define PMM_I18N_H
#include <stddef.h>
/* Set the active locale (e.g. "zh-CN"). If non-NULL/empty it overrides the
* locale auto-detected from LANG/LC_ALL. Copies the value. */
void pmm_lang_set_locale(const char *locale);
/* Current locale name (static buffer, e.g. "zh-CN"). */
const char *pmm_lang_locale(void);
/* Load a .pjson file (flattened key->value object) into the active translation
* table. Returns 0 on success. On failure the previous table stays. */
int pmm_lang_load(const char *path);
/* Load the active locale's pack from ~/.pmm/lang/<locale>.pjson, if present.
* Returns 0 if a pack was loaded, 1 if not found (no translation available). */
int pmm_lang_load_active(void);
/* Translate a key to the current locale's text; returns key if unknown/missing.
* The returned pointer is valid until the next pmm_lang_load*(). */
const char *pmm_tr(const char *key);
/* Translate + format: pmm_tr_fmt("msg.err.not-found", name) -> formatted text.
* Uses pmm_tr() then printf-style %s/%d replacement. */
const char *pmm_tr_fmt(const char *key, ...);
#endif