Skip to content

Generate i10n key types based on file #125

@northword

Description

@northword

ref: #62

用户在 TypeScript 里可能想要获取特定的 Fluent 消息列表,例如下面的结构中,用户可能不需要 preferences.ftl 中的键,因为他们仅在首选项窗格出现,不会在脚本里引用。

$ tree addon
addon
|-- bootstrap.js
|-- content
|   |-- icons
|   |   |-- favicon.png
|   |   `-- [email protected]
|   `-- preferences.xhtml
|-- locale
|   |-- en-US
|   |   |-- addon.ftl
|   |   |-- rules.ftl
|   |   `-- preferences.ftl
|   `-- zh-CN
|       |-- addon.ftl
|   |   |-- rules.ftl
|       `-- preferences.ftl
|-- manifest.json
`-- prefs.js

7 directories, 13 files

如果我们生成 fluent message dts 为如下格式就可以解决这个问题。

// Generated by zotero-plugin-scaffold
/* prettier-ignore */
/* eslint-disable */
// @ts-nocheck
export type FluentMessageId =
  | _FluentMessageId_addon
  | _FluentMessageId_preferences
  | _FluentMessageId_rules

// locale/**/addon.ftl
export type _FluentMessageId_addon =
  | 'NoPreprintJournalArticle-warning'
  | 'abbr-conferencePaper'
  | 'abbr-custom-data-desc'
  | 'abbr-custom-data-label'
  | 'abbr-infer'
  | 'abbr-journal'
  | 'abbr-usefull'
  | 'abbr-usefull-en'
  | 'abbr-usefull-zh'
  | 'bold'

// locale/**/preferences.ftl
export type _FluentMessageId_preferences =
  | 'cancel'
  | 'checkWebpage-warning'
  | 'choose-custom-abbr-data-button'
  | 'choose-custom-abbr-data-input'
  | 'confirm'

// locale/**/rules.ftl
export type _FluentMessageId_rules =
  | 'cancel'
  | 'checkWebpage-warning'
  | 'choose-custom-abbr-data-button'
  | 'choose-custom-abbr-data-input'
  | 'confirm'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions