-
Notifications
You must be signed in to change notification settings - Fork 187
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
Added a generic way to translate the necessary fields in composite entities. #9722
Conversation
Thanks for opening this pull request! The maintainers of this repository would appreciate it if you would create a changelog item based on your changes. |
5832a4e
to
7013d7a
Compare
@kobergj The translate functions are separated semantically |
ecb8451
to
8648e08
Compare
Signed-off-by: jkoberg <[email protected]>
Signed-off-by: jkoberg <[email protected]>
8488863
to
098ea97
Compare
Signed-off-by: jkoberg <[email protected]>
Quality Gate passedIssues Measures |
/* | ||
tr := NewTranslator("en", _domain, _fsys) | ||
|
||
// a slice of translatables can be passed directly | ||
val := []string{"description", "display name"} | ||
err := tr.TranslateEntity(tr, s, val) | ||
|
||
// string maps work the same way | ||
val := map[string]string{ | ||
"entryOne": "description", | ||
"entryTwo": "display name", | ||
} | ||
err := TranslateEntity(tr, val) | ||
|
||
// struct fields need to be specified | ||
type Struct struct { | ||
Description string | ||
DisplayName string | ||
MetaInformation string | ||
} | ||
val := Struct{} | ||
err := TranslateEntity(tr, val, | ||
l10n.TranslateField("Description"), | ||
l10n.TranslateField("DisplayName"), | ||
) | ||
|
||
// nested structures are supported | ||
type InnerStruct struct { | ||
Description string | ||
Roles []string | ||
} | ||
type OuterStruct struct { | ||
DisplayName string | ||
First InnerStruct | ||
Others map[string]InnerStruct | ||
} | ||
val := OuterStruct{} | ||
err := TranslateEntity(tr, val, | ||
l10n.TranslateField("DisplayName"), | ||
l10n.TranslateStruct("First", | ||
l10n.TranslateField("Description"), | ||
l10n.TranslateEach("Roles"), | ||
), | ||
l10n.TranslateMap("Others", | ||
l10n.TranslateField("Description"), | ||
}, | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is all this commented?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
info on how to use the pkg
v := value.MapIndex(k) | ||
switch v.Kind() { | ||
case reflect.Struct: | ||
// FIXME: add support for non-pointer values |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in a subsequent pr?
Added a generic way to translate the necessary fields in composite entities.
Description
Added a generic way to translate the necessary fields in composite entities.
Related Issue
Motivation and Context
How Has This Been Tested?
Screenshots (if appropriate):
Types of changes
Checklist: