Skip to content

Commit

Permalink
Create golangci-lint.yml (#313)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicksnyder committed Dec 5, 2023
1 parent b4fe018 commit 6f270f3
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 55 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: golangci-lint
on:
push:
branches:
- main
pull_request:

permissions:
contents: read

jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: '1.21'
cache: false
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.55
working-directory: v2
46 changes: 25 additions & 21 deletions v2/goi18n/main.go
Original file line number Diff line number Diff line change
@@ -1,34 +1,38 @@
// Command goi18n manages message files used by the i18n package.
//
// go get -u github.com/nicksnyder/go-i18n/v2/goi18n
// goi18n -help
// go get -u github.com/nicksnyder/go-i18n/v2/goi18n
// goi18n -help
//
// Use `goi18n extract` to create a message file that contains the messages defined in your Go source files.
// # en.toml
// [PersonCats]
// description = "The number of cats a person has"
// one = "{{.Name}} has {{.Count}} cat."
// other = "{{.Name}} has {{.Count}} cats."
//
// # en.toml
// [PersonCats]
// description = "The number of cats a person has"
// one = "{{.Name}} has {{.Count}} cat."
// other = "{{.Name}} has {{.Count}} cats."
//
// Use `goi18n merge` to create message files for translation.
// # translate.es.toml
// [PersonCats]
// description = "The number of cats a person has"
// hash = "sha1-f937a0e05e19bfe6cd70937c980eaf1f9832f091"
// one = "{{.Name}} has {{.Count}} cat."
// other = "{{.Name}} has {{.Count}} cats."
//
// # translate.es.toml
// [PersonCats]
// description = "The number of cats a person has"
// hash = "sha1-f937a0e05e19bfe6cd70937c980eaf1f9832f091"
// one = "{{.Name}} has {{.Count}} cat."
// other = "{{.Name}} has {{.Count}} cats."
//
// Use `goi18n merge` to merge translated message files with your existing message files.
// # active.es.toml
// [PersonCats]
// description = "The number of cats a person has"
// hash = "sha1-f937a0e05e19bfe6cd70937c980eaf1f9832f091"
// one = "{{.Name}} tiene {{.Count}} gato."
// other = "{{.Name}} tiene {{.Count}} gatos."
//
// # active.es.toml
// [PersonCats]
// description = "The number of cats a person has"
// hash = "sha1-f937a0e05e19bfe6cd70937c980eaf1f9832f091"
// one = "{{.Name}} tiene {{.Count}} gato."
// other = "{{.Name}} tiene {{.Count}} gatos."
//
// Load the active messages into your bundle.
// bundle.RegisterUnmarshalFunc("toml", toml.Unmarshal)
// bundle.MustLoadMessageFile("active.es.toml")
//
// bundle.RegisterUnmarshalFunc("toml", toml.Unmarshal)
// bundle.MustLoadMessageFile("active.es.toml")
package main

import (
Expand Down
2 changes: 0 additions & 2 deletions v2/i18n/bundlefs.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// +build go1.16

package i18n

import (
Expand Down
30 changes: 17 additions & 13 deletions v2/i18n/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,27 @@
// according to a set of locale preferences.
//
// Create a Bundle to use for the lifetime of your application.
// bundle := i18n.NewBundle(language.English)
//
// bundle := i18n.NewBundle(language.English)
//
// Load translations into your bundle during initialization.
// bundle.LoadMessageFile("en-US.yaml")
//
// bundle.LoadMessageFile("en-US.yaml")
//
// Create a Localizer to use for a set of language preferences.
// func(w http.ResponseWriter, r *http.Request) {
// lang := r.FormValue("lang")
// accept := r.Header.Get("Accept-Language")
// localizer := i18n.NewLocalizer(bundle, lang, accept)
// }
//
// func(w http.ResponseWriter, r *http.Request) {
// lang := r.FormValue("lang")
// accept := r.Header.Get("Accept-Language")
// localizer := i18n.NewLocalizer(bundle, lang, accept)
// }
//
// Use the Localizer to lookup messages.
// localizer.MustLocalize(&i18n.LocalizeConfig{
// DefaultMessage: &i18n.Message{
// ID: "HelloWorld",
// Other: "Hello World!",
// },
// })
//
// localizer.MustLocalize(&i18n.LocalizeConfig{
// DefaultMessage: &i18n.Message{
// ID: "HelloWorld",
// Other: "Hello World!",
// },
// })
package i18n
9 changes: 0 additions & 9 deletions v2/i18n/localizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,6 @@ func (e *MessageNotFoundErr) Error() string {
return fmt.Sprintf("message %q not found in language %q", e.MessageID, e.Tag)
}

type pluralizeErr struct {
messageID string
tag language.Tag
}

func (e *pluralizeErr) Error() string {
return fmt.Sprintf("unable to pluralize %q because there no plural rule for %q", e.messageID, e.tag)
}

type messageIDMismatchErr struct {
messageID string
defaultMessageID string
Expand Down
6 changes: 0 additions & 6 deletions v2/internal/plural/codegen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,6 @@ func infof(format string, args ...interface{}) {

var verbose bool

func verbosef(format string, args ...interface{}) {
if verbose {
infof(format, args...)
}
}

func fatalf(format string, args ...interface{}) {
infof("fatal: "+format+"\n", args...)
os.Exit(1)
Expand Down
10 changes: 7 additions & 3 deletions v2/internal/plural/codegen/xml.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import (
"regexp"
"strconv"
"strings"

"golang.org/x/text/cases"
"golang.org/x/text/language"
)

// SupplementalData is the top level struct of plural.xml
Expand All @@ -22,7 +25,7 @@ type PluralGroup struct {

// Name returns a unique name for this plural group.
func (pg *PluralGroup) Name() string {
n := strings.Title(pg.Locales)
n := cases.Title(language.AmericanEnglish).String(pg.Locales)
return strings.Replace(n, " ", "", -1)
}

Expand All @@ -39,7 +42,7 @@ type PluralRule struct {

// CountTitle returns the title case of the PluralRule's count.
func (pr *PluralRule) CountTitle() string {
return strings.Title(pr.Count)
return cases.Title(language.AmericanEnglish).String(pr.Count)
}

// Condition returns the condition where the PluralRule applies.
Expand Down Expand Up @@ -100,7 +103,8 @@ func (pr *PluralRule) GoCondition() string {
if parts == nil {
continue
}
lvar, lmod, op, rhs := strings.Title(parts[1]), parts[2], parts[3], strings.TrimSpace(parts[4])
lvar := cases.Title(language.AmericanEnglish).String(parts[1])
lmod, op, rhs := parts[2], parts[3], strings.TrimSpace(parts[4])
if op == "=" {
op = "=="
}
Expand Down
2 changes: 1 addition & 1 deletion v2/internal/plural/rule_gen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ func TestPt(t *testing.T) {
}
}

func TestCaItPt_PTVec(t *testing.T) {
func TestCaItPt_ptVec(t *testing.T) {
var tests []pluralFormTest

tests = appendIntegerTests(tests, One, []string{"1"})
Expand Down

0 comments on commit 6f270f3

Please sign in to comment.