diff --git a/index.go b/index.go index 5b194c6..9d22ed6 100644 --- a/index.go +++ b/index.go @@ -52,9 +52,16 @@ type App struct { SugVersName string `json:"suggestedVersionName"` SugVersCode int `json:"suggestedVersionCode,string"` + Localized map[string]Localization `json:"localized"` + Apks []*Apk `json:"-"` } +type Localization struct { + Summary string `json:"summary"` + Description string `json:"description"` +} + type IconDensity uint const ( @@ -261,6 +268,17 @@ func LoadIndexJSON(r io.Reader) (*Index, error) { for i := range index.Apps { app := &index.Apps[i] + english, enOK := app.Localized["en"] + if !enOK { + english, enOK = app.Localized["en-US"] + } + if app.Summary == "" && enOK { + app.Summary = english.Summary + } + if app.Description == "" && enOK { + app.Description = english.Description + } + app.Summary = strings.TrimSpace(app.Summary) sort.Sort(ApkList(index.Packages[app.PackageName])) for i := range index.Packages[app.PackageName] { apk := &index.Packages[app.PackageName][i] diff --git a/index_test.go b/index_test.go index 7e28138..c1bbf70 100644 --- a/index_test.go +++ b/index_test.go @@ -9,6 +9,8 @@ import ( "strings" "testing" "time" + + "github.com/kr/pretty" ) func TestTextDesc(t *testing.T) { @@ -76,6 +78,14 @@ func TestLoadIndexJSON(t *testing.T) { "added": 1443734950000, "suggestedVersionName": "1.0", "suggestedVersionCode": "1" + }, + { + "packageName": "localized.app", + "localized": { + "en": { + "summary": "summary in english\n" + } + } } ], "packages": { @@ -108,6 +118,13 @@ func TestLoadIndexJSON(t *testing.T) { SugVersCode: 1, Apks: []*Apk{nil}, }, + { + PackageName: "localized.app", + Summary: "summary in english", + Localized: map[string]Localization{ + "en": {Summary: "summary in english\n"}, + }, + }, }, Packages: map[string][]Apk{"foo.bar": { { @@ -134,7 +151,7 @@ func TestLoadIndexJSON(t *testing.T) { } } if !reflect.DeepEqual(got, want) { - t.Fatalf("Unexpected index.\nGot:\n%#v\nWant:\n%#v\n", - got, want) + t.Fatalf("Unexpected index.\n%s", + strings.Join(pretty.Diff(want, got), "\n")) } }