Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add localized subtitle support #218

Merged
merged 1 commit into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions payload/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ type alert struct {
Subtitle string `json:"subtitle,omitempty"`
TitleLocArgs []string `json:"title-loc-args,omitempty"`
TitleLocKey string `json:"title-loc-key,omitempty"`
SubtitleLocArgs []string `json:"subtitle-loc-args,omitempty"`
SubtitleLocKey string `json:"subtitle-loc-key,omitempty"`
SummaryArg string `json:"summary-arg,omitempty"`
SummaryArgCount int `json:"summary-arg-count,omitempty"`
}
Expand Down Expand Up @@ -193,6 +195,28 @@ func (p *Payload) AlertSubtitle(subtitle string) *Payload {
return p
}

// AlertSubtitleLocKey sets the aps alert subtitle localization key on the payload.
// This is the key to a subtitle string in the Localizable.strings file for the
// current localization. See Localized Formatted Strings in Apple documentation
// for more information.
//
// {"aps":{"alert":{"subtitle-loc-key":key}}}
func (p *Payload) AlertSubtitleLocKey(key string) *Payload {
p.aps().alert().SubtitleLocKey = key
return p
}

// AlertSubtitleLocArgs sets the aps alert subtitle localization args on the payload.
// These are the variable string values to appear in place of the format
// specifiers in subtitle-loc-key. See Localized Formatted Strings in Apple
// documentation for more information.
//
// {"aps":{"alert":{"title-loc-args":args}}}
func (p *Payload) AlertSubtitleLocArgs(args []string) *Payload {
p.aps().alert().SubtitleLocArgs = args
return p
}

// AlertBody sets the aps alert body on the payload.
// This is the text of the alert message.
//
Expand Down
12 changes: 12 additions & 0 deletions payload/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,18 @@ func TestAlertSubtitle(t *testing.T) {
assert.Equal(t, `{"aps":{"alert":{"subtitle":"hello"}}}`, string(b))
}

func TestAlertSubtitleLocKey(t *testing.T) {
payload := NewPayload().AlertSubtitleLocKey("Notification.Key.TestSubtitle")
b, _ := json.Marshal(payload)
assert.Equal(t, `{"aps":{"alert":{"subtitle-loc-key":"Notification.Key.TestSubtitle"}}}`, string(b))
}

func TestAlertSubtitleLocArgs(t *testing.T) {
payload := NewPayload().AlertSubtitleLocArgs([]string{"one", "two"})
b, _ := json.Marshal(payload)
assert.Equal(t, `{"aps":{"alert":{"subtitle-loc-args":["one","two"]}}}`, string(b))
}

func TestAlertBody(t *testing.T) {
payload := NewPayload().AlertBody("body")
b, _ := json.Marshal(payload)
Expand Down