mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-05-24 08:27:27 -04:00
the translator added to handlers
This commit is contained in:
@@ -85,6 +85,10 @@ func (s *ActivitylogService) HandleGetItemActivities(w http.ResponseWriter, r *h
|
||||
return
|
||||
}
|
||||
|
||||
// FIXME: configurable default locale?
|
||||
loc := l10n.MustGetUserLocale(r.Context(), activeUser.GetId().GetOpaqueId(), r.Header.Get(l10n.HeaderAcceptLanguage), s.valService)
|
||||
t := l10n.NewTranslatorFromCommonConfig("en", _domain, "", _localeFS, _localeSubPath)
|
||||
|
||||
resp := GetActivitiesResponse{Activities: make([]libregraph.Activity, 0, len(evRes.GetEvents()))}
|
||||
for _, e := range evRes.GetEvents() {
|
||||
delete(toDelete, e.GetId())
|
||||
@@ -164,10 +168,6 @@ func (s *ActivitylogService) HandleGetItemActivities(w http.ResponseWriter, r *h
|
||||
continue
|
||||
}
|
||||
|
||||
// FIXME: configurable default locale?
|
||||
loc := l10n.MustGetUserLocale(r.Context(), activeUser.GetId().GetOpaqueId(), r.Header.Get(l10n.HeaderAcceptLanguage), s.valService)
|
||||
t := l10n.NewTranslatorFromCommonConfig("en", _domain, "", _localeFS, _localeSubPath)
|
||||
|
||||
resp.Activities = append(resp.Activities, NewActivity(t.Translate(message, loc), ts, e.GetId(), vars))
|
||||
}
|
||||
|
||||
|
||||
@@ -2,8 +2,8 @@ SHELL := bash
|
||||
NAME := graph
|
||||
|
||||
# Where to write the files generated by this makefile.
|
||||
OUTPUT_DIR = ./pkg/service/v0/l10n
|
||||
TEMPLATE_FILE = ./pkg/service/v0/l10n/graph.pot
|
||||
OUTPUT_DIR = ./pkg/l10n
|
||||
TEMPLATE_FILE = ./pkg/l10n/graph.pot
|
||||
|
||||
include ../../.make/recursion.mk
|
||||
|
||||
@@ -45,7 +45,7 @@ l10n-push:
|
||||
|
||||
.PHONY: l10n-read
|
||||
l10n-read: $(GO_XGETTEXT)
|
||||
go-xgettext -o $(OUTPUT_DIR)/graph.pot --keyword=l10n.Template --add-comments -s pkg/service/v0/spacetemplates.go
|
||||
go-xgettext -o $(OUTPUT_DIR)/graph.pot --keyword=l10n.Template --add-comments -s pkg/service/v0/spacetemplates.go -s pkg/unifiedrole/unifiedrole.go
|
||||
|
||||
.PHONY: l10n-write
|
||||
l10n-write:
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
|
||||
# This file is distributed under the same license as the PACKAGE package.
|
||||
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
|
||||
#
|
||||
#
|
||||
# Translators:
|
||||
# Alex <hostspepc@gmail.com>, 2024
|
||||
#
|
||||
#
|
||||
#, fuzzy
|
||||
msgid ""
|
||||
msgstr ""
|
||||
@@ -25,3 +25,38 @@ msgstr ""
|
||||
#: pkg/service/v0/spacetemplates.go:37
|
||||
msgid "Here you can add a description for this Space."
|
||||
msgstr "Здесь вы можете добавить описание этого пространства."
|
||||
|
||||
#: pkg/unifiedrole/unifiedrole.go:87
|
||||
msgid "Can edit"
|
||||
msgstr ""
|
||||
|
||||
#. UnifiedRole Viewer, Role DisplayName (resolves directly)
|
||||
#: pkg/unifiedrole/unifiedrole.go:79
|
||||
msgid "Can view"
|
||||
msgstr ""
|
||||
|
||||
#. default description for new spaces
|
||||
#: pkg/service/v0/spacetemplates.go:31
|
||||
msgid "Here you can add a description for this Space."
|
||||
msgstr ""
|
||||
|
||||
#. UnifiedRole Viewer, Role Description (resolves directly)
|
||||
#. UnifiedRole SpaceViewer, Role Description (resolves directly)
|
||||
#: pkg/unifiedrole/unifiedrole.go:77 pkg/unifiedrole/unifiedrole.go:82
|
||||
msgid "View and download."
|
||||
msgstr ""
|
||||
|
||||
#: pkg/unifiedrole/unifiedrole.go:91
|
||||
msgid "View, download and edit."
|
||||
msgstr ""
|
||||
|
||||
#: pkg/unifiedrole/unifiedrole.go:92
|
||||
msgid "View, download and upload."
|
||||
msgstr ""
|
||||
|
||||
#. canEdit := "Can edit"
|
||||
#. UnifiedRole Editor, Role Description (resolves directly)
|
||||
#. UnifiedRole SpaseEditor, Role Description (resolves directly)
|
||||
#: pkg/unifiedrole/unifiedrole.go:86 pkg/unifiedrole/unifiedrole.go:90
|
||||
msgid "View, download, upload, edit, add and delete."
|
||||
msgstr ""
|
||||
30
services/graph/pkg/l10n/translation.go
Normal file
30
services/graph/pkg/l10n/translation.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package l10n
|
||||
|
||||
import (
|
||||
"embed"
|
||||
|
||||
l10npkg "github.com/owncloud/ocis/v2/ocis-pkg/l10n"
|
||||
)
|
||||
|
||||
var (
|
||||
//go:embed locale
|
||||
_localeFS embed.FS
|
||||
)
|
||||
|
||||
const (
|
||||
// subfolder where the translation files are stored
|
||||
_localeSubPath = "locale"
|
||||
|
||||
// domain of the graph service (transifex)
|
||||
_domain = "graph"
|
||||
)
|
||||
|
||||
func Translate(content, locale, defaultLocale string) string {
|
||||
t := l10npkg.NewTranslatorFromCommonConfig(defaultLocale, _domain, "", _localeFS, _localeSubPath)
|
||||
return t.Translate(content, locale)
|
||||
}
|
||||
|
||||
func NewTranslateLocation(locale, defaultLocale string) func(string, ...any) string {
|
||||
t := l10npkg.NewTranslatorFromCommonConfig(defaultLocale, _domain, "", _localeFS, _localeSubPath)
|
||||
return t.Locale(locale).Get
|
||||
}
|
||||
@@ -25,6 +25,8 @@ import (
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/go-chi/render"
|
||||
libregraph "github.com/owncloud/libre-graph-api-go"
|
||||
"github.com/owncloud/ocis/v2/ocis-pkg/l10n"
|
||||
l10n2 "github.com/owncloud/ocis/v2/services/graph/pkg/l10n"
|
||||
|
||||
"github.com/owncloud/ocis/v2/ocis-pkg/conversions"
|
||||
"github.com/owncloud/ocis/v2/ocis-pkg/log"
|
||||
@@ -632,6 +634,22 @@ func (api DriveItemPermissionsApi) ListPermissions(w http.ResponseWriter, r *htt
|
||||
return
|
||||
}
|
||||
|
||||
loc := r.Header.Get(l10n.HeaderAcceptLanguage)
|
||||
w.Header().Add("Content-Language", loc)
|
||||
if loc != "" && loc != "en" {
|
||||
trf := l10n2.NewTranslateLocation(loc, "en")
|
||||
for i, role := range permissions.LibreGraphPermissionsRolesAllowedValues {
|
||||
err := l10n.TranslateEntity(&role, trf,
|
||||
l10n.TranslateField("Description"),
|
||||
l10n.TranslateField("DisplayName"))
|
||||
if err != nil {
|
||||
api.logger.Warn().Err(err).Msg("tranlation error")
|
||||
continue
|
||||
}
|
||||
permissions.LibreGraphPermissionsRolesAllowedValues[i] = role
|
||||
}
|
||||
}
|
||||
|
||||
render.Status(r, http.StatusOK)
|
||||
render.JSON(w, r, permissions)
|
||||
}
|
||||
@@ -653,6 +671,22 @@ func (api DriveItemPermissionsApi) ListSpaceRootPermissions(w http.ResponseWrite
|
||||
return
|
||||
}
|
||||
|
||||
loc := r.Header.Get(l10n.HeaderAcceptLanguage)
|
||||
w.Header().Add("Content-Language", loc)
|
||||
if loc != "" && loc != "en" {
|
||||
trf := l10n2.NewTranslateLocation(loc, "en")
|
||||
for i, role := range permissions.LibreGraphPermissionsRolesAllowedValues {
|
||||
err := l10n.TranslateEntity(&role, trf,
|
||||
l10n.TranslateField("Description"),
|
||||
l10n.TranslateField("DisplayName"))
|
||||
if err != nil {
|
||||
api.logger.Warn().Err(err).Msg("tranlation error")
|
||||
continue
|
||||
}
|
||||
permissions.LibreGraphPermissionsRolesAllowedValues[i] = role
|
||||
}
|
||||
}
|
||||
|
||||
render.Status(r, http.StatusOK)
|
||||
render.JSON(w, r, permissions)
|
||||
}
|
||||
|
||||
@@ -15,18 +15,13 @@ import (
|
||||
"github.com/cs3org/reva/v2/pkg/storagespace"
|
||||
"github.com/cs3org/reva/v2/pkg/utils"
|
||||
"github.com/owncloud/ocis/v2/ocis-pkg/l10n"
|
||||
l10n_pkg "github.com/owncloud/ocis/v2/services/graph/pkg/l10n"
|
||||
)
|
||||
|
||||
var (
|
||||
//go:embed spacetemplate/*
|
||||
_spaceTemplateFS embed.FS
|
||||
|
||||
//go:embed l10n/locale
|
||||
_localeFS embed.FS
|
||||
|
||||
// subfolder where the translation files are stored
|
||||
_localeSubPath = "l10n/locale"
|
||||
|
||||
// name of the secret space folder
|
||||
_spaceFolderName = ".space"
|
||||
|
||||
@@ -39,9 +34,6 @@ var (
|
||||
// name of the readme.md file
|
||||
_readmeName = "readme.md"
|
||||
|
||||
// domain of the graph service (transifex)
|
||||
_domain = "graph"
|
||||
|
||||
// HeaderAcceptLanguage is the header key for the accept-language header
|
||||
HeaderAcceptLanguage = "Accept-Language"
|
||||
|
||||
@@ -121,10 +113,9 @@ func imageUpload(ctx context.Context, mdc *metadata.CS3) (string, error) {
|
||||
}
|
||||
|
||||
func readmeUpload(ctx context.Context, mdc *metadata.CS3, locale string, defaultLocale string) (string, error) {
|
||||
t := l10n.NewTranslatorFromCommonConfig(defaultLocale, _domain, "", _localeFS, _localeSubPath)
|
||||
res, err := mdc.Upload(ctx, metadata.UploadRequest{
|
||||
Path: filepath.Join(_spaceFolderName, _readmeName),
|
||||
Content: []byte(t.Translate(_readmeText, locale)),
|
||||
Content: []byte(l10n_pkg.Translate(_readmeText, locale, defaultLocale)),
|
||||
})
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
|
||||
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
|
||||
libregraph "github.com/owncloud/libre-graph-api-go"
|
||||
"github.com/owncloud/ocis/v2/ocis-pkg/l10n"
|
||||
"google.golang.org/protobuf/proto"
|
||||
|
||||
"github.com/cs3org/reva/v2/pkg/conversions"
|
||||
@@ -71,12 +72,54 @@ var legacyNames map[string]string = map[string]string{
|
||||
UnifiedRoleSecureViewerID: conversions.RoleSecureViewer,
|
||||
}
|
||||
|
||||
var (
|
||||
// UnifiedRole Viewer, Role Description (resolves directly)
|
||||
_viewerUnifiedRoleDescription = l10n.Template("View and download.")
|
||||
// UnifiedRole Viewer, Role DisplayName (resolves directly)
|
||||
_viewerUnifiedRoleDisplayName = l10n.Template("Can view")
|
||||
|
||||
// UnifiedRole SpaceViewer, Role Description (resolves directly)
|
||||
_spaceViewerUnifiedRoleDescription = l10n.Template("View and download.")
|
||||
// UnifiedRole SpaseViewer, Role DisplayName (resolves directly)
|
||||
_spaceViewerUnifiedRoleDisplayName = l10n.Template("Can view")
|
||||
|
||||
// UnifiedRole Editor, Role Description (resolves directly)
|
||||
_editorUnifiedRoleDescription = l10n.Template("View, download, upload, edit, add and delete.")
|
||||
// UnifiedRole Editor, Role DisplayName (resolves directly)
|
||||
_editorUnifiedRoleDisplayName = l10n.Template("Can edit")
|
||||
|
||||
// UnifiedRole SpaseEditor, Role Description (resolves directly)
|
||||
_spaceEditorUnifiedRoleDescription = l10n.Template("View, download, upload, edit, add and delete.")
|
||||
// UnifiedRole SpaseEditor, Role DisplayName (resolves directly)
|
||||
_spaceEditorUnifiedRoleDisplayName = l10n.Template("Can edit")
|
||||
|
||||
// UnifiedRole FileEditor, Role Description (resolves directly)
|
||||
_fileEditorUnifiedRoleDescription = l10n.Template("View, download and edit.")
|
||||
// UnifiedRole FileEditor, Role DisplayName (resolves directly)
|
||||
_fileEditorUnifiedRoleDisplayName = l10n.Template("Can edit")
|
||||
|
||||
// UnifiedRole EditorLite, Role Description (resolves directly)
|
||||
_editorLiteUnifiedRoleDescription = l10n.Template("View, download and upload.")
|
||||
// UnifiedRole EditorLite, Role DisplayName (resolves directly)
|
||||
_editorLiteUnifiedRoleDisplayName = l10n.Template("Can upload")
|
||||
|
||||
// UnifiedRole Manager, Role Description (resolves directly)
|
||||
_managerUnifiedRoleDescription = l10n.Template("View, download, upload, edit, add, delete and manage members.")
|
||||
// UnifiedRole Manager, Role DisplayName (resolves directly)
|
||||
_managerUnifiedRoleDisplayName = l10n.Template("Can manage")
|
||||
|
||||
// UnifiedRole SecureViewer, Role Description (resolves directly)
|
||||
_secureViewerUnifiedRoleDescription = l10n.Template("View only documents, images and PDFs. Watermarks will be applied.")
|
||||
// UnifiedRole SecureViewer, Role DisplayName (resolves directly)
|
||||
_secureViewerUnifiedRoleDisplayName = l10n.Template("Can view (secure)")
|
||||
)
|
||||
|
||||
// NewViewerUnifiedRole creates a viewer role.
|
||||
func NewViewerUnifiedRole() *libregraph.UnifiedRoleDefinition {
|
||||
r := conversions.NewViewerRole()
|
||||
return &libregraph.UnifiedRoleDefinition{
|
||||
Id: proto.String(UnifiedRoleViewerID),
|
||||
Description: proto.String("View and download."),
|
||||
Description: proto.String(_viewerUnifiedRoleDescription),
|
||||
DisplayName: displayName(r),
|
||||
RolePermissions: []libregraph.UnifiedRolePermission{
|
||||
{
|
||||
@@ -97,7 +140,7 @@ func NewSpaceViewerUnifiedRole() *libregraph.UnifiedRoleDefinition {
|
||||
r := conversions.NewSpaceViewerRole()
|
||||
return &libregraph.UnifiedRoleDefinition{
|
||||
Id: proto.String(UnifiedRoleSpaceViewerID),
|
||||
Description: proto.String("View and download."),
|
||||
Description: proto.String(_spaceViewerUnifiedRoleDescription),
|
||||
DisplayName: displayName(r),
|
||||
RolePermissions: []libregraph.UnifiedRolePermission{
|
||||
{
|
||||
@@ -114,7 +157,7 @@ func NewEditorUnifiedRole() *libregraph.UnifiedRoleDefinition {
|
||||
r := conversions.NewEditorRole()
|
||||
return &libregraph.UnifiedRoleDefinition{
|
||||
Id: proto.String(UnifiedRoleEditorID),
|
||||
Description: proto.String("View, download, upload, edit, add and delete."),
|
||||
Description: proto.String(_editorUnifiedRoleDescription),
|
||||
DisplayName: displayName(r),
|
||||
RolePermissions: []libregraph.UnifiedRolePermission{
|
||||
{
|
||||
@@ -131,7 +174,7 @@ func NewSpaceEditorUnifiedRole() *libregraph.UnifiedRoleDefinition {
|
||||
r := conversions.NewSpaceEditorRole()
|
||||
return &libregraph.UnifiedRoleDefinition{
|
||||
Id: proto.String(UnifiedRoleSpaceEditorID),
|
||||
Description: proto.String("View, download, upload, edit, add and delete."),
|
||||
Description: proto.String(_spaceEditorUnifiedRoleDescription),
|
||||
DisplayName: displayName(r),
|
||||
RolePermissions: []libregraph.UnifiedRolePermission{
|
||||
{
|
||||
@@ -148,7 +191,7 @@ func NewFileEditorUnifiedRole() *libregraph.UnifiedRoleDefinition {
|
||||
r := conversions.NewFileEditorRole()
|
||||
return &libregraph.UnifiedRoleDefinition{
|
||||
Id: proto.String(UnifiedRoleFileEditorID),
|
||||
Description: proto.String("View, download and edit."),
|
||||
Description: proto.String(_fileEditorUnifiedRoleDescription),
|
||||
DisplayName: displayName(r),
|
||||
RolePermissions: []libregraph.UnifiedRolePermission{
|
||||
{
|
||||
@@ -165,7 +208,7 @@ func NewEditorLiteUnifiedRole() *libregraph.UnifiedRoleDefinition {
|
||||
r := conversions.NewEditorLiteRole()
|
||||
return &libregraph.UnifiedRoleDefinition{
|
||||
Id: proto.String(UnifiedRoleEditorLiteID),
|
||||
Description: proto.String("View, download and upload."),
|
||||
Description: proto.String(_editorLiteUnifiedRoleDescription),
|
||||
DisplayName: displayName(r),
|
||||
RolePermissions: []libregraph.UnifiedRolePermission{
|
||||
{
|
||||
@@ -182,7 +225,7 @@ func NewManagerUnifiedRole() *libregraph.UnifiedRoleDefinition {
|
||||
r := conversions.NewManagerRole()
|
||||
return &libregraph.UnifiedRoleDefinition{
|
||||
Id: proto.String(UnifiedRoleManagerID),
|
||||
Description: proto.String("View, download, upload, edit, add, delete and manage members."),
|
||||
Description: proto.String(_managerUnifiedRoleDescription),
|
||||
DisplayName: displayName(r),
|
||||
RolePermissions: []libregraph.UnifiedRolePermission{
|
||||
{
|
||||
@@ -199,7 +242,7 @@ func NewSecureViewerUnifiedRole() *libregraph.UnifiedRoleDefinition {
|
||||
r := conversions.NewSecureViewerRole()
|
||||
return &libregraph.UnifiedRoleDefinition{
|
||||
Id: proto.String(UnifiedRoleSecureViewerID),
|
||||
Description: proto.String("View only documents, images and PDFs. Watermarks will be applied."),
|
||||
Description: proto.String(_secureViewerUnifiedRoleDescription),
|
||||
DisplayName: displayName(r),
|
||||
RolePermissions: []libregraph.UnifiedRolePermission{
|
||||
{
|
||||
@@ -482,27 +525,24 @@ func displayName(role *conversions.Role) *string {
|
||||
return nil
|
||||
}
|
||||
|
||||
// linter wants this to be a var
|
||||
canEdit := "Can edit"
|
||||
|
||||
var displayName string
|
||||
switch role.Name {
|
||||
case conversions.RoleViewer:
|
||||
displayName = "Can view"
|
||||
displayName = _viewerUnifiedRoleDisplayName
|
||||
case conversions.RoleSpaceViewer:
|
||||
displayName = "Can view"
|
||||
displayName = _spaceViewerUnifiedRoleDisplayName
|
||||
case conversions.RoleEditor:
|
||||
displayName = canEdit
|
||||
displayName = _editorUnifiedRoleDisplayName
|
||||
case conversions.RoleSpaceEditor:
|
||||
displayName = canEdit
|
||||
displayName = _spaceEditorUnifiedRoleDisplayName
|
||||
case conversions.RoleFileEditor:
|
||||
displayName = canEdit
|
||||
displayName = _fileEditorUnifiedRoleDisplayName
|
||||
case conversions.RoleEditorLite:
|
||||
displayName = "Can upload"
|
||||
displayName = _editorLiteUnifiedRoleDisplayName
|
||||
case conversions.RoleManager:
|
||||
displayName = "Can manage"
|
||||
displayName = _managerUnifiedRoleDisplayName
|
||||
case conversions.RoleSecureViewer:
|
||||
displayName = "Can view (secure)"
|
||||
displayName = _secureViewerUnifiedRoleDisplayName
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user