generated from snivilised/astrolib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ref(locale): define i18n translatable content (#115)
- Loading branch information
1 parent
e955c90
commit 57ce4b6
Showing
57 changed files
with
1,332 additions
and
340 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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{},", | ||
" },", | ||
"}" | ||
] | ||
} | ||
} |
Oops, something went wrong.