Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

define i18n translatable content #18

Closed
plastikfan opened this issue Aug 24, 2024 · 2 comments · Fixed by #19
Closed

define i18n translatable content #18

plastikfan opened this issue Aug 24, 2024 · 2 comments · Fixed by #19
Assignees
Labels
refactor Refactor code

Comments

@plastikfan
Copy link
Contributor

No description provided.

@plastikfan plastikfan added the refactor Refactor code label Aug 24, 2024
@plastikfan plastikfan self-assigned this Aug 24, 2024
@plastikfan
Copy link
Contributor Author

plastikfan commented Aug 24, 2024

VSCode Snippet:

  • $1 is the core value, eg ErrLackPoolFunc
  • $2 is the TemplData prefix, for pants, the prefix is pants
	"Plain i18n Error": {
		"scope": "go",
    "prefix": "p18e",
    "body": [
			"// ❌ $1",
			"",
			"// $1TemplData",
			"type $1TemplData struct {",
			"  $2TemplData",
			"}",
			"",
			"// Message",
			"func (td $1TemplData) Message() *i18n.Message {",
			"  return &i18n.Message{",
			"    ID:    \".error\",",
			"    Description: \"description\",",
			"    Other:       \"content\",",
			"  }",
			"}",
			"",
			"// $1ErrorBehaviourQuery used to query if an error is:",
			"// \"tbd\"",
			"type $1ErrorBehaviourQuery interface {",
			"  $1() bool",
			"}",
			"",
			"type $1Error struct {",
			"  li18ngo.LocalisableError",
			"}",
			"",
			"// $1 enables the client to check if error is $1Error",
			"// via $1ErrorBehaviourQuery",
			"func (e $1Error) $1() bool {",
			"  return true",
			"}",
			"",
			"// New$1Error creates a $1Error",
			"func New$1Error() $1Error {",
			"  return $1Error{",
			"    LocalisableError: li18ngo.LocalisableError{",
			"      Data: $1TemplData{",
			"      },",
			"    },",
			"  }",
			"}",
    ]
  },

@plastikfan plastikfan pinned this issue Aug 24, 2024
@plastikfan
Copy link
Contributor Author

plastikfan commented Aug 24, 2024

VSCode Snippet:

  • $1 is the core value, eg LackPoolFunc
  • $2 is the TemplData prefix, for pants, the prefix is pants
  "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{},",
      "  },",
      "}",
    ],
  },

This is much better as is does away with the interface definition and creates a global variable instance which is compatible with the use of errors.Is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor Refactor code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant