Skip to content

Commit

Permalink
Merge pull request #5279 from sdassow/macos-language-integration
Browse files Browse the repository at this point in the history
Add languages to metadata and use for language integration in macOS
  • Loading branch information
sdassow authored Nov 21, 2024
2 parents b529a32 + 6b01710 commit 6bfd026
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 3 deletions.
11 changes: 10 additions & 1 deletion cmd/fyne/internal/commands/package-darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ type darwinData struct {
Version string
Build int
Category string
Languages []string
}

func darwinLangs(langs []string) []string {
r := make([]string, len(langs))
for n, lang := range langs {
r[n] = strings.Replace(lang, "-", "_", 1)
}
return r
}

func (p *Packager) packageDarwin() (err error) {
Expand All @@ -40,7 +49,7 @@ func (p *Packager) packageDarwin() (err error) {
}()

tplData := darwinData{Name: p.Name, ExeName: exeName, AppID: p.AppID, Version: p.AppVersion, Build: p.AppBuild,
Category: strings.ToLower(p.category)}
Category: strings.ToLower(p.category), Languages: darwinLangs(p.langs)}
if err := templates.InfoPlistDarwin.Execute(infoFile, tplData); err != nil {
return fmt.Errorf("failed to write plist template: %w", err)
}
Expand Down
15 changes: 15 additions & 0 deletions cmd/fyne/internal/commands/package-darwin_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package commands

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestDarwinLangs(t *testing.T) {
langs := darwinLangs([]string{"en-GB", "de-CH"})

assert.Equal(t, 2, len(langs))
assert.Equal(t, "en_GB", langs[0])
assert.Equal(t, "de_CH", langs[1])
}
2 changes: 2 additions & 0 deletions cmd/fyne/internal/commands/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ type Packager struct {
certificate, profile string // optional flags for releasing
tags, category string
tempDir string
langs []string

customMetadata keyValueFlag
linuxAndBSDMetadata *metadata.LinuxAndBSD
Expand Down Expand Up @@ -344,6 +345,7 @@ func (p *Packager) validate() (err error) {

p.appData.mergeMetadata(data)
p.sourceMetadata = data.Source
p.langs = data.Languages

p.linuxAndBSDMetadata = data.LinuxAndBSD
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/fyne/internal/templates/bundled.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion cmd/fyne/internal/templates/data/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,17 @@
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
{{- if .Languages}}
<key>CFBundleLocalizations</key>
<array>
{{- range .Languages}}
<string>{{.}}</string>
{{- end}}
</array>
{{- end}}
<key>LSApplicationCategoryType</key>
<string>public.app-category.{{.Category}}</string>
<key>LSMinimumSystemVersion</key>
<string>10.11</string>
</dict>
</plist>
</plist>
1 change: 1 addition & 0 deletions internal/metadata/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type FyneApp struct {
Release map[string]string `toml:",omitempty"`
Source *AppSource `toml:",omitempty"`
LinuxAndBSD *LinuxAndBSD `toml:",omitempty"`
Languages []string `toml:",omitempty"`
}

// AppDetails describes the build information, this group may be OS or arch specific
Expand Down

0 comments on commit 6bfd026

Please sign in to comment.