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

Added a generic way to translate the necessary fields in composite entities. #9722

Merged
merged 10 commits into from
Aug 9, 2024

Conversation

2403905
Copy link
Contributor

@2403905 2403905 commented Aug 1, 2024

Description

Added a generic way to translate the necessary fields in composite entities.

// TranslateEntity function provides the generic way to translate a struct, array or slice.
// Support for maps is also provided, but non-pointer values will not work.
// The function also takes the entity with fields to translate.
// The function supports nested structs and slices of structs.
/*
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"),
	},
*/

Related Issue

Motivation and Context

How Has This Been Tested?

  • test environment:
  • test case 1:
  • test case 2:
  • ...

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Technical debt
  • Tests only (no source changes)

Checklist:

  • Code changes
  • Unit tests added
  • Acceptance tests added
  • Documentation ticket raised:

Copy link

update-docs bot commented Aug 1, 2024

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.

@2403905 2403905 force-pushed the issue-9700 branch 3 times, most recently from 5832a4e to 7013d7a Compare August 2, 2024 06:39
@2403905
Copy link
Contributor Author

2403905 commented Aug 2, 2024

@2403905 2403905 marked this pull request as ready for review August 2, 2024 13:12
@2403905 2403905 changed the title added TranslateEntity Added a generic way to translate the necessary fields in composite entities. Aug 2, 2024
@2403905 2403905 requested review from micbar and kobergj August 2, 2024 13:30
@2403905 2403905 force-pushed the issue-9700 branch 2 times, most recently from ecb8451 to 8648e08 Compare August 4, 2024 19:16
@kobergj kobergj force-pushed the issue-9700 branch 2 times, most recently from 8488863 to 098ea97 Compare August 6, 2024 14:52
Copy link

sonarqubecloud bot commented Aug 6, 2024

Comment on lines +76 to +122
/*
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"),
},
*/
Copy link
Member

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?

Copy link
Collaborator

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in a subsequent pr?

@butonic butonic merged commit f2620b9 into owncloud:master Aug 9, 2024
3 checks passed
ownclouders pushed a commit that referenced this pull request Aug 9, 2024
Added a generic way to translate the necessary fields in composite entities.
@ScharfViktor ScharfViktor mentioned this pull request Aug 20, 2024
21 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[oCIS] Provide Translations for unified Roles
3 participants