Skip to content

Commit

Permalink
ref(locale): define i18n translatable content (#115)
Browse files Browse the repository at this point in the history
  • Loading branch information
plastikfan committed Aug 29, 2024
1 parent e955c90 commit 57ce4b6
Show file tree
Hide file tree
Showing 57 changed files with 1,332 additions and 340 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/ci-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,27 @@ jobs:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v3
- uses: actions/setup-go@v4
with:
go-version: 1.22
go-version: 1.23
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.56.2
version: v1.60.3
args: --verbose

test:
strategy:
matrix:
go-version: [1.22]
go-version: [1.23]
platform: [ubuntu-latest, macos-latest]

runs-on: ${{ matrix.platform }}

steps:
- name: Install Go
uses: actions/setup-go@v3
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Setup
uses: actions/setup-go@v3
with:
go-version: '>=1.22'
go-version: '>=1.23'
cache: true
- name: Generate Changelog Only
uses: goreleaser/goreleaser-action@v4
Expand Down
6 changes: 3 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ linters-settings:
- performance
- style
govet:
check-shadowing: true
shadow: true
disable:
- fieldalignment # too strict

Expand All @@ -28,22 +28,22 @@ linters:
# it can be re-enabled.
# https://github.com/OpenPeeDeeP/depguard#example-configs
# - depguard
- copyloopvar
- dogsled
# - dupl
- errcheck
- exportloopref
- exhaustive
- goconst
- gocritic
- gofmt
- goimports
- gomnd
- gocyclo
- gosec
- gosimple
- govet
- ineffassign
- misspell
- mnd
- nolintlint
- nakedret
- prealloc
Expand Down
9 changes: 9 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"Clonable",
"cmds",
"Cobrass",
"copyloopvar",
"coverpkg",
"coverprofile",
"cubiest",
Expand All @@ -36,6 +37,7 @@
"fortytw",
"fsys",
"Fugazi",
"Ginko",
"goconst",
"gocritic",
"gocyclo",
Expand All @@ -50,6 +52,7 @@
"goveralls",
"govet",
"graffico",
"gverrt",
"hiber",
"icase",
"ineffassign",
Expand All @@ -67,6 +70,7 @@
"Mutables",
"nakedret",
"navi",
"nicksnyder",
"nolint",
"nolintlint",
"onsi",
Expand All @@ -84,17 +88,21 @@
"samber",
"shogo",
"sidewalk",
"snivilisation",
"snivilised",
"sortables",
"Sprintf",
"staticcheck",
"struct",
"structcheck",
"stylecheck",
"tapable",
"tapcore",
"Taskfile",
"tcore",
"testcache",
"thelper",
"toplevel",
"tparallel",
"trimprefix",
"Turan",
Expand All @@ -103,6 +111,7 @@
"unlambda",
"unparam",
"varcheck",
"verr",
"watchv",
"watchvc",
"watchvi",
Expand Down
54 changes: 54 additions & 0 deletions .vscode/snippets/README-SNIPPETS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# 🐷 Snippets

For further help with snippets see:

- [How To Create A VSCode Snippet (webdevsimplified)](https://blog.webdevsimplified.com/2022-03/vscode-snippet/)

## i18n Field

Creates a simple text field. The field is a key value pair, where the key is static text subject to translation.

- prefix: f18
- $1: the name of the field
- $2: the name of the source package from which to import the field
- example: locale.PatternFieldTemplData

## i18n Field and Variable i18n Error

Creates a variable i18n error (an error with state). This snippet uses a copy of `Simple i18n Field` to implement the variable part; ie the native variable error contains within it a field that implements the variable.

- prefix: v18e
- $1: the core name of the error (do not include Err or Error in name)
...

## Ginko Variable Native Error

Creates Ginkgo unit tests corresponding to `Variable Native Error`.

- prefix: gverrt
- $1: the core name of the error (do not include Err or Error in name)
- $2: the name of the source package from which to import the error
- example: core.errors_test

Creates the following test case:

- check content of variable error
- affirmative case; check that an error matches the target error being defined
- negative case; check that a different error does not match the target error being defined

## Simple i18n Error

Creates a simple i18n error message (ie a message without any variables)

- prefix: s18e
- $1: the core name of the error (do not include Err or Error in name)
- $2: the `TemplData` prefix, eg ___traverse___ to create `traverseTemplData`
- example: locale.FilterIsNilErrorTemplData

## Variable Native Error

Creates a native error (un-translated error, not meant for the end user). Note that by default it creates a single variable `value` of type string in the New function. This needs to be changed to be the state required for this message, or indeed, further state can be defined.

- prefix: verr
- $1: the core name of the error (do not include Err or Error in name)
- example: core.NewInvalidNotificationMuteRequestedError
176 changes: 176 additions & 0 deletions .vscode/snippets/go.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
{
"Simple i18n Field": {
"description": "Creates a i18n key/value pair text field",
"scope": "go",
"prefix": "kv18",
"body": [
"// 🍀 $1",
"",
"// $1TemplData",
"type $1FieldTemplData struct {",
" $2TemplData",
" $1 string",
"}",
"",
"// Message",
"func (td $1FieldTemplData) Message() *i18n.Message {",
" return &i18n.Message{",
" ID: \"$1.field\",",
" Description: \"$1\",",
" Other: \"$1: {{.$1}}\",",
" }",
"}",
"$0"
]
},

"Simple Field with Variable i18n Error": {
"scope": "go",
"prefix": "fav18e",
"body": [
"// 🍀 $1",
"",
"// $1TemplData",
"type $1FieldTemplData struct {",
" $2TemplData",
" $1 string",
"}",
"",
"// Message",
"func (td $1FieldTemplData) Message() *i18n.Message {",
" return &i18n.Message{",
" ID: \"$1.field\",",
" Description: \"$1\",",
" Other: \"$1: {{.$1}}\",",
" }",
"}",
"",
"// ❌ $3 error",
"",
"// New$3Error creates an untranslated error to",
"// indicate tbd...",
"func New$3Error(value string) error {",
" return errors.Wrap(",
" err$3,",
" fmt.Sprintf(\"value: %v\", value),",
" )",
"}",
"",
"// Is$3Error uses errors.Is to check",
"// if the err's error tree contains the core error:",
"// $3Error",
"func Is$3Error(err error) bool {",
" return errors.Is(err, err$3)",
"}",
"",
"var err$3 = errors.New(",
" \"tbd...\",",
")",
"",
"$0"
]
},

"Variable Native Error": {
"scope": "go",
"prefix": "verr",
"body": [
"// ❌ $1 error",
"",
"// New$1Error creates an untranslated error to",
"// indicate tbd...",
"func New$1Error(value string) error {",
" return errors.Wrap(",
" err$1,",
" fmt.Sprintf(\"value: %v\", value),",
" )",
"}",
"",
"// Is$1Error uses errors.Is to check",
"// if the err's error tree contains the core error:",
"// $1Error",
"func Is$1Error(err error) bool {",
" return errors.Is(err, err$1)",
"}",
"",
"var err$1 = errors.New(",
" \"tbd...\",",
")",
""
]
},

"Ginko Variable Native Error": {
"scope": "go",
"prefix": "gverrt",
"body": [
"Context(\"$1 error\", func() {",
"When(\"variant error created\", func() {",
" It(\"should: render translated content\", func() {",
" const (",
" expected = \"wiz...\"",
" )",
" text := locale.New$1Error(",
" \"wiz\",",
" ).Error()",
" Expect(text).To(Equal(expected))",
" })",
"})",
" When(\"given: matching error\", func() {",
" It(\"🧪 should: affirm\", func() {",
" err := $2.New$1Error(\"bar\")",
" Expect(",
" $2.Is$1Error(err),",
" ).To(BeTrue(),",
" \"error does not match $1\",",
" )",
" })",
" })",
"",
" When(\"given: non matching error\", func() {",
" It(\"🧪 should: reject\", func() {",
" err := errors.New(\"fake\")",
" Expect(",
" $2.Is$1Error(err),",
" ).To(BeFalse(),",
" \"not matching error should not match $1\",",
" )",
" })",
" })",
"})",
""
]
},

"Simple i18n Error": {
"scope": "go",
"prefix": "s18e",
"body": [
"// ❌ $1",
"",
"// $1TemplData",
"type $1ErrorTemplData struct {",
" $2TemplData",
"}",
"",
"// Message",
"func (td $1ErrorTemplData) Message() *i18n.Message {",
" return &i18n.Message{",
" ID: \".error\",",
" Description: \"description\",",
" Other: \"content\",",
" }",
"}",
"",
"type $1Error struct {",
" li18ngo.LocalisableError",
"}",
"",
"var Err$1 = $1Error{",
" LocalisableError: li18ngo.LocalisableError{",
" Data: $1ErrorTemplData{},",
" },",
"}"
]
}
}
Loading

0 comments on commit 57ce4b6

Please sign in to comment.