Skip to content

Commit a34add8

Browse files
committed
docs: readme for i18n card builder [ci skip]
1 parent 3ea6168 commit a34add8

File tree

6 files changed

+80
-28
lines changed

6 files changed

+80
-28
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# CHANGELOG
22

3+
## v1.10.0
4+
5+
- feat(im): support card with i18n (#59)
6+
37
## v1.9.0
48

59
- feat(im): support column set (#57)

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2018-2022 go-lark
3+
Copyright (c) 2018-2023 go-lark
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,10 @@ Here is a collection of ready-to-run examples for each part of `go-lark`:
140140

141141
- [examples/auth](https://github.com/go-lark/examples/tree/main/auth)
142142
- [examples/basic-message](https://github.com/go-lark/examples/tree/main/basic-message)
143-
- [examples/image-message](https://github.com/go-lark/examples/tree/main/image-message)
144143
- [examples/rich-text-message](https://github.com/go-lark/examples/tree/main/rich-text-message)
145-
- [examples/share-chat](https://github.com/go-lark/examples/tree/main/share-chat)
146144
- [examples/interactive-message](https://github.com/go-lark/examples/tree/main/interactive-message)
145+
- [examples/image-message](https://github.com/go-lark/examples/tree/main/image-message)
146+
- [examples/share-chat](https://github.com/go-lark/examples/tree/main/share-chat)
147147
- [examples/group](https://github.com/go-lark/examples/tree/main/group)
148148

149149
### Message Buffer
@@ -380,4 +380,4 @@ func CopyFile(bot *lark.Bot, fileToken, dstFolderToken, dstName string) (*CopyFi
380380

381381
## License
382382

383-
Copyright (c) David Zhang, 2018-2022. Licensed under MIT License.
383+
Copyright (c) David Zhang, 2018-2023. Licensed under MIT License.

README_zhCN.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,10 @@ resp, err := bot.GetTenantAccessTokenInternal(true)
131131

132132
- [鉴权](https://github.com/go-lark/examples/tree/main/auth)
133133
- [基本消息](https://github.com/go-lark/examples/tree/main/basic-message)
134-
- [图片消息](https://github.com/go-lark/examples/tree/main/image-message)
135134
- [富文本消息](https://github.com/go-lark/examples/tree/main/rich-text-message)
136-
- [分享群卡片](https://github.com/go-lark/examples/tree/main/share-chat)
137135
- [交互卡片](https://github.com/go-lark/examples/tree/main/interactive-message)
136+
- [图片消息](https://github.com/go-lark/examples/tree/main/image-message)
137+
- [分享群卡片](https://github.com/go-lark/examples/tree/main/share-chat)
138138
- [群操作](https://github.com/go-lark/examples/tree/main/group)
139139

140140
### Message Buffer
@@ -145,9 +145,14 @@ MsgBuffer 支持多种类型的消息:
145145

146146
- `MsgText`:文本
147147
- `MsgPost`:富文本
148-
- `MsgImage`:图片
149-
- `MsgShareCard`:群名片
150148
- `MsgInteractive`:交互式卡片
149+
- `MsgShareUser`: 用户名片
150+
- `MsgShareCard`:群名片
151+
- `MsgImage`:图片
152+
- `MsgFile`: 文件
153+
- `MsgAudio`: 音频
154+
- `MsgMedia`: 媒体
155+
- `MsgSticker`: 表情
151156

152157
MsgBuffer 主要有两类函数,Bind 函数和内容函数。
153158

@@ -362,4 +367,4 @@ func CopyFile(bot *lark.Bot, fileToken, dstFolderToken, dstName string) (*CopyFi
362367

363368
## 协议
364369

365-
Copyright (c) David Zhang, 2018-2022. Licensed under MIT License.
370+
Copyright (c) David Zhang, 2018-2023. Licensed under MIT License.

card/README.md

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
Interactive card is rich in formats. However, it takes much efforts to build one. Thus, we provide a declarative card builder to make it easier.
44

5+
We map every element of card (`div`, `text`, `button`, etc.) to declarative calls as shown in the demo.
6+
7+
All inner elements (e.g. `fields` of `div` blocks) are considered as arguments,
8+
while all element properties (e.g. `forward` property of `card` blocks) are considered as chained calls.
9+
510
## Getting Started
611

712
```go
@@ -38,17 +43,33 @@ which will render as following:
3843
}
3944
```
4045

41-
We map every element of card (`div`, `text`, `button`, etc.) to declarative calls as shown in the demo.
42-
43-
All inner elements (e.g. `fields` of `div` blocks) are considered as arguments,
44-
while all element properties (e.g. `forward` property of `card` blocks) are considered as chained calls.
46+
Example: [examples/interactive-message](https://github.com/go-lark/examples/tree/main/interactive-message)
4547

46-
Refer to [msg_card_builder_test.go](./msg_card_builder_test.go) for details.
48+
## I18N
4749

48-
## Limits
50+
Card with I18N support is also supported. We introduce a `I18N` struct to build localizable parts (e.g. title and contents):
4951

50-
- i18n cards are currently NOT YET SUPPORTED. Use raw json if necessary.
51-
- `CardBuilder` contains ONLY a group of card-builder-related functions and contains NO card content. Thus, you can use the same `CardBuilder` whenever building a card instead of making a new one before build.
52+
```go
53+
b := lark.NewCardBuilder()
54+
c := b.I18N.Card(
55+
b.I18N.WithLocale(
56+
LocaleEnUS,
57+
b.Div(
58+
b.Field(b.Text("English Content")),
59+
),
60+
),
61+
b.I18N.WithLocale(
62+
LocaleZhCN,
63+
b.Div(
64+
b.Field(b.Text("中文内容")),
65+
),
66+
),
67+
).
68+
Title(
69+
b.I18N.LocalizedText(LocaleEnUS, "English Title"),
70+
b.I18N.LocalizedText(LocaleZhCN, "中文标题"),
71+
)
72+
```
5273

5374
## Sending Message
5475

card/README_zhCN.md

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1-
# 声明式卡片构造工具
1+
# 卡片构造工具
2+
3+
交互卡片是飞书消息中比较受欢迎的交互形式,但构造起来比较复杂,因此我们提供了专门的卡片构造工具。
4+
5+
卡片构造工具采用声明式 API 设计,我们把每一个元素(`div``text``button` 等)都映射成声明的形式。
6+
7+
我们约定使用「参数」来表示**元素内部**的子元素(例如 `div` 中的 `fields`),用「链式调用」来设置**元素本身**的属性(例如卡片中的 `forward`)。
28

39
## 使用方式
410

511
```go
6-
b := NewCardBuilder()
12+
b := lark.NewCardBuilder()
713
c := b.Card(
814
b.Markdown("some text"),
915
).
@@ -36,23 +42,39 @@ fmt.Println(c.String())
3642
}
3743
```
3844

39-
我们把每一个元素(`div``text``button` 等)都映射成这样的声明形式。
45+
参考实例:[交互卡片](https://github.com/go-lark/examples/tree/main/interactive-message)
4046

41-
我们约定使用「参数」来表示**元素内部**的子元素(例如 `div` 中的 `fields`),用「链式调用」来设置**元素本身**的属性(例如卡片中的 `forward`)。
42-
43-
详细请参见[msg_card_builder_test.go](./msg_card_builder_test.go)
47+
## 国际化支持
4448

45-
## 限制
49+
我们也支持构造多语言的卡片,在标题和内容等特定部分,需要引用 `I18N` 结构中的方法构造:
4650

47-
- 暂不支持 i18n 卡片,如有相关需求请暂时使用 json
48-
- `CardBuilder` 只作为卡片构造相关方法的集合,不具备承载卡片的功能,所以你可以在任意地方使用同一个 `CardBuilder` ,无需每次使用前新建。
51+
```go
52+
b := lark.NewCardBuilder()
53+
c := b.I18N.Card(
54+
b.I18N.WithLocale(
55+
LocaleEnUS,
56+
b.Div(
57+
b.Field(b.Text("English Content")),
58+
),
59+
),
60+
b.I18N.WithLocale(
61+
LocaleZhCN,
62+
b.Div(
63+
b.Field(b.Text("中文内容")),
64+
),
65+
),
66+
).
67+
Title(
68+
b.I18N.LocalizedText(LocaleEnUS, "English Title"),
69+
b.I18N.LocalizedText(LocaleZhCN, "中文标题"),
70+
)
71+
```
4972

50-
## 使用 go-lark 发送
73+
## 发送
5174

5275
```go
5376
b := lark.NewCardBuilder()
5477
c := b.Card(...Elements)
55-
// 使用 c.String() 或者 c.MarshalJSON() 将卡片内容渲染为 string 或 []byte
5678
msg := lark.NewMsgBuffer(lark.MsgInteractive)
5779
om := msg.BindEmail("[email protected]").Card(c.String()).Build()
5880
bot.PostMessage(om)

0 commit comments

Comments
 (0)