Skip to content

useTimeAgo 需要一个国际化的选项支持中文! #2142

@zjssos

Description

@zjssos

Clear and concise description of the problem

我使用useTimeAgo时需要将展示的文本替换成中文。

Suggested solution

  • 其实通过options的message是可以实现的,所以我这个issue不知道合不合理?
  • 下面是配置(是否考虑加到文档中做个示例?):
 messages: {
        justNow: '刚刚',
        past: (n) => (n.match(/\d/) ? `${n}以前` : n),
        future: (n) => (n.match(/\d/) ? `未来 ${n}` : n),
        month: (n, past) => (n === 1 ? (past ? '上个月' : '下个月') : `${n}个月${n > 1 ? '' : ''}`),
        year: (n, past) => (n === 1 ? (past ? '去年' : '明年') : `${n}年${n > 1 ? '' : ''}`),
        day: (n, past) => (n === 1 ? (past ? '昨天' : '明天') : `${n}天${n > 1 ? '' : ''}`),
        week: (n, past) => (n === 1 ? (past ? '上一周' : '下一周') : `${n}周${n > 1 ? '' : ''}`),
        hour: (n) => `${n}小时${n > 1 ? '' : ''}`,
        minute: (n) => `${n}分钟${n > 1 ? '' : ''}`,
        second: (n) => `${n}秒${n > 1 ? '' : ''}`,
      }

Alternative

No response

Additional context

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions