2019-06-03 09:32:43 +00:00
|
|
|
package arn
|
|
|
|
|
2019-06-04 03:16:27 +00:00
|
|
|
// MediaTitle represents a title for any kind of media.
|
|
|
|
type MediaTitle struct {
|
2019-06-03 09:32:43 +00:00
|
|
|
Canonical string `json:"canonical" editable:"true"`
|
|
|
|
Romaji string `json:"romaji" editable:"true"`
|
|
|
|
English string `json:"english" editable:"true"`
|
|
|
|
Japanese string `json:"japanese" editable:"true"`
|
|
|
|
Hiragana string `json:"hiragana" editable:"true"`
|
|
|
|
Synonyms []string `json:"synonyms" editable:"true"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// ByUser returns the preferred title for the given user.
|
2019-06-04 03:16:27 +00:00
|
|
|
func (title *MediaTitle) ByUser(user *User) string {
|
2019-06-03 09:32:43 +00:00
|
|
|
if user == nil {
|
|
|
|
return title.Canonical
|
|
|
|
}
|
|
|
|
|
|
|
|
switch user.Settings().TitleLanguage {
|
|
|
|
case "canonical":
|
|
|
|
return title.Canonical
|
|
|
|
case "romaji":
|
|
|
|
if title.Romaji == "" {
|
|
|
|
return title.Canonical
|
|
|
|
}
|
|
|
|
|
|
|
|
return title.Romaji
|
|
|
|
case "english":
|
|
|
|
if title.English == "" {
|
|
|
|
return title.Canonical
|
|
|
|
}
|
|
|
|
|
|
|
|
return title.English
|
|
|
|
case "japanese":
|
|
|
|
if title.Japanese == "" {
|
|
|
|
return title.Canonical
|
|
|
|
}
|
|
|
|
|
|
|
|
return title.Japanese
|
|
|
|
default:
|
|
|
|
panic("Invalid title language")
|
|
|
|
}
|
|
|
|
}
|