Browse Source

grab text from the english localization

Some apps are missing the main fields if they are localized. Grab it
from "en" or "en-US" for now.
pull/32/head
Daniel Martí 8 years ago
parent
commit
7b1b9e3c27
  1. 18
      index.go
  2. 21
      index_test.go

18
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]

21
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"))
}
}

Loading…
Cancel
Save