windingwind/zotero-plugin-template

getString("addon-static-example", { branch: "branch-example" })

zzlb0224 opened this issue · 1 comments

getString("addon-static-example", { branch: "branch-example" }) 获取分支配置时返回的时array,这里建立增加对数组的判断,提升兼容性。

image
image

function _getString(
  localeString: string,
  options: { branch?: string | undefined; args?: Record<string, unknown> } = {},
): string {
  const localStringWithPrefix = `${config.addonRef}-${localeString}`;
  const { branch, args } = options;
  const pattern = addon.data.locale?.current.formatMessagesSync([
    { id: localStringWithPrefix, args },
  ])[0];
  if (!pattern) {
    return localStringWithPrefix;
  }
  if (branch && pattern.attributes) {
    for (const attr of pattern.attributes) {
      if (attr.name === branch) {
        return attr.value
      }
    }
    return pattern.attributes[branch] || localStringWithPrefix;
  } else {
    return pattern.value || localStringWithPrefix;
  }
}

🚀 This ticket has been resolved in v3.0.0. See Release v3.0.0 for release notes.