refactor(i18n): address code review feedback on string legos, hardcoded locales, and fragile checks

This commit is contained in:
yiling
2026-07-06 10:52:55 +08:00
parent 45f3255796
commit 01a9c7cde6
20 changed files with 274 additions and 81 deletions
+29
View File
@@ -0,0 +1,29 @@
/* eslint-disable */
import { getLocale, experimentalStaticLocale } from '../runtime.js';
/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */
/** @typedef {{}} Date_Format_LongInputs */
const en_date_format_long = /** @type {(inputs: Date_Format_LongInputs) => LocalizedString} */ () => {
return /** @type {LocalizedString} */ (`MMMM d, yyyy`)
};
const zh_date_format_long = /** @type {(inputs: Date_Format_LongInputs) => LocalizedString} */ () => {
return /** @type {LocalizedString} */ (`yyyy年M月d日`)
};
/**
* | output |
* | --- |
* | "MMMM d, yyyy" |
*
* @param {Date_Format_LongInputs} inputs
* @param {{ locale?: "en" | "zh" }} options
* @returns {LocalizedString}
*/
export const date_format_long = /** @type {((inputs?: Date_Format_LongInputs, options?: { locale?: "en" | "zh" }) => LocalizedString) & import('../runtime.js').MessageMetadata<Date_Format_LongInputs, { locale?: "en" | "zh" }, {}>} */ ((inputs = {}, options = {}) => {
const locale = experimentalStaticLocale ?? options.locale ?? getLocale()
if (locale === "en") return en_date_format_long(inputs)
return zh_date_format_long(inputs)
});