Skip to content

Commit

Permalink
added the translation
Browse files Browse the repository at this point in the history
  • Loading branch information
2403905 committed Sep 20, 2024
1 parent 3ad5eeb commit 3da79d5
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 33 deletions.
2 changes: 1 addition & 1 deletion changelog/unreleased/fix-acitivity-update-share.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
go Bugfix: Added ShareUpdate activity
Bugfix: Added ShareUpdate activity

Added the ShareUpdate activity in the space context.

Expand Down
11 changes: 6 additions & 5 deletions services/activitylog/pkg/service/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ func (s *ActivitylogService) HandleGetItemActivities(w http.ResponseWriter, r *h
vars map[string]interface{}
)

loc := l10n.MustGetUserLocale(r.Context(), activeUser.GetId().GetOpaqueId(), r.Header.Get(l10n.HeaderAcceptLanguage), s.valService)
t := l10n.NewTranslatorFromCommonConfig(s.cfg.DefaultLanguage, _domain, s.cfg.TranslationPath, _localeFS, _localeSubPath)

switch ev := s.unwrapEvent(e).(type) {
case nil:
// error already logged in unwrapEvent
Expand Down Expand Up @@ -158,7 +161,7 @@ func (s *ActivitylogService) HandleGetItemActivities(w http.ResponseWriter, r *h
}
message = MessageShareUpdated
ts = utils.TSToTime(ev.MTime)
vars, err = s.GetVars(ctx, WithResource(toRef(ev.ItemID), false), WithUser(ev.Executant, ""), WithFieldMask(ev.UpdateMask))
vars, err = s.GetVars(ctx, WithResource(toRef(ev.ItemID), false), WithUser(ev.Executant, ""), WithTranslation(&t, loc, "field", ev.UpdateMask))
case events.ShareRemoved:
message = MessageShareDeleted
ts = ev.Timestamp
Expand All @@ -176,7 +179,8 @@ func (s *ActivitylogService) HandleGetItemActivities(w http.ResponseWriter, r *h
vars, err = s.GetVars(ctx,
WithResource(toRef(ev.ItemID), false),
WithUser(ev.Executant, ""),
WithLinkFieldUpdated(&ev))
WithTranslation(&t, loc, "field", []string{ev.FieldUpdated}),
WithVar("token", ev.ItemID.GetOpaqueId(), ev.Token))
case events.LinkRemoved:
message = MessageLinkDeleted
ts = utils.TSToTime(ev.Timestamp)
Expand All @@ -196,9 +200,6 @@ func (s *ActivitylogService) HandleGetItemActivities(w http.ResponseWriter, r *h
continue
}

loc := l10n.MustGetUserLocale(r.Context(), activeUser.GetId().GetOpaqueId(), r.Header.Get(l10n.HeaderAcceptLanguage), s.valService)
t := l10n.NewTranslatorFromCommonConfig(s.cfg.DefaultLanguage, _domain, s.cfg.TranslationPath, _localeFS, _localeSubPath)

resp.Activities = append(resp.Activities, NewActivity(t.Translate(message, loc), ts, e.GetId(), vars))
}

Expand Down
73 changes: 46 additions & 27 deletions services/activitylog/pkg/service/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
user "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
"github.com/cs3org/reva/v2/pkg/events"
"github.com/cs3org/reva/v2/pkg/storagespace"
"github.com/cs3org/reva/v2/pkg/utils"
libregraph "github.com/owncloud/libre-graph-api-go"
Expand All @@ -35,6 +34,22 @@ var (
MessageLinkDeleted = l10n.Template("{user} removed link to {resource}")
MessageSpaceShared = l10n.Template("{user} added {sharee} as member of {space}")
MessageSpaceUnshared = l10n.Template("{user} removed {sharee} from {space}")

StrSomeField = l10n.Template(_someField)
StrPermission = l10n.Template(_permission)
StrPassword = l10n.Template(_password)
StrExpirationDate = l10n.Template(_expirationDate)
StrDisplayName = l10n.Template(_displayName)
StrDescription = l10n.Template(_description)
)

const (
_someField = "some field"
_permission = "permission"
_password = "password"
_expirationDate = "expiration date"
_displayName = "display name"
_description = "description"
)

// GetActivitiesResponse is the response on GET activities requests
Expand Down Expand Up @@ -220,41 +235,29 @@ func WithSpace(spaceid *provider.StorageSpaceId) ActivityOption {
}
}

func WithLinkFieldUpdated(e *events.LinkUpdated) ActivityOption {
// WithTranslation sets a variable that translation is needed for
func WithTranslation(t *l10n.Translator, locale string, key string, values []string) ActivityOption {
return func(_ context.Context, _ gateway.GatewayAPIClient, vars map[string]interface{}) error {
f := "some field"
switch e.FieldUpdated {
case "TYPE_PERMISSIONS":
f = "permission"
case "TYPE_PASSWORD":
f = "password"
case "TYPE_EXPIRATION":
f = "expiration date"
case "TYPE_DISPLAYNAME":
f = "display name"
case "TYPE_DESCRIPTION":
f = "description"
f := t.Translate(StrSomeField, locale)
if len(values) > 0 {
for i := range values {
values[i] = t.Translate(mapField(values[i]), locale)
}
f = strings.Join(values, ", ")
}
vars["field"] = Resource{
ID: e.ItemID.GetOpaqueId(),
vars[key] = Resource{
Name: f,
}
vars["token"] = Resource{
ID: e.ItemID.GetOpaqueId(),
Name: e.Token,
}
return nil
}
}

func WithFieldMask(mask []string) ActivityOption {
// WithVar sets a variable for an activity
func WithVar(key, id, name string) ActivityOption {
return func(_ context.Context, _ gateway.GatewayAPIClient, vars map[string]interface{}) error {
f := "some field"
if len(mask) > 0 {
f = strings.Join(mask, ", ")
}
vars["field"] = Resource{
Name: f,
vars[key] = Resource{
ID: id,
Name: name,
}
return nil
}
Expand Down Expand Up @@ -288,3 +291,19 @@ func (s *ActivitylogService) GetVars(ctx context.Context, opts ...ActivityOption

return vars, nil
}

func mapField(val string) string {
switch val {
case "TYPE_PERMISSIONS", "permission":
return _permission
case "TYPE_PASSWORD", "password":
return _password
case "TYPE_EXPIRATION", "expiration":
return _expirationDate
case "TYPE_DISPLAYNAME":
return _displayName
case "TYPE_DESCRIPTION":
return _description
}
return _someField
}

0 comments on commit 3da79d5

Please sign in to comment.