diff --git a/changelog/unreleased/lang-supp-in-app.md b/changelog/unreleased/lang-supp-in-app.md
new file mode 100644
index 00000000000..042920589d4
--- /dev/null
+++ b/changelog/unreleased/lang-supp-in-app.md
@@ -0,0 +1,5 @@
+Enhancement: added support for language locales in apps
+
+This is a backport of code in the edge branch
+
+https://github.com/cs3org/reva/pull/3303
diff --git a/internal/grpc/services/appprovider/appprovider.go b/internal/grpc/services/appprovider/appprovider.go
index eea33b20c17..df979ebf746 100644
--- a/internal/grpc/services/appprovider/appprovider.go
+++ b/internal/grpc/services/appprovider/appprovider.go
@@ -170,7 +170,8 @@ func getProvider(c *config) (app.Provider, error) {
}
func (s *service) OpenInApp(ctx context.Context, req *providerpb.OpenInAppRequest) (*providerpb.OpenInAppResponse, error) {
- appURL, err := s.provider.GetAppURL(ctx, req.ResourceInfo, req.ViewMode, req.AccessToken)
+ // TODO(lopresti) adding now an hardcoded language, in the HTTP appprovider in edge this is read as a form parameter from the frontend
+ appURL, err := s.provider.GetAppURL(ctx, req.ResourceInfo, req.ViewMode, req.AccessToken, "en-GB")
if err != nil {
res := &providerpb.OpenInAppResponse{
Status: status.NewInternal(ctx, errors.New("appprovider: error calling GetAppURL"), err.Error()),
diff --git a/pkg/app/app.go b/pkg/app/app.go
index a6edad2a022..50e6ce28d8b 100644
--- a/pkg/app/app.go
+++ b/pkg/app/app.go
@@ -40,6 +40,6 @@ type Registry interface {
// Provider is the interface that application providers implement
// for interacting with external apps that serve the requested resource.
type Provider interface {
- GetAppURL(ctx context.Context, resource *provider.ResourceInfo, viewMode appprovider.OpenInAppRequest_ViewMode, token string) (*appprovider.OpenInAppURL, error)
+ GetAppURL(ctx context.Context, resource *provider.ResourceInfo, viewMode appprovider.OpenInAppRequest_ViewMode, token, language string) (*appprovider.OpenInAppURL, error)
GetAppProviderInfo(ctx context.Context) (*registry.ProviderInfo, error)
}
diff --git a/pkg/app/provider/demo/demo.go b/pkg/app/provider/demo/demo.go
index 896893fa658..9376251aa18 100644
--- a/pkg/app/provider/demo/demo.go
+++ b/pkg/app/provider/demo/demo.go
@@ -38,8 +38,8 @@ type demoProvider struct {
iframeUIProvider string
}
-func (p *demoProvider) GetAppURL(ctx context.Context, resource *provider.ResourceInfo, viewMode appprovider.OpenInAppRequest_ViewMode, token string) (*appprovider.OpenInAppURL, error) {
- url := fmt.Sprintf("", p.iframeUIProvider, resource.Id.StorageId+":"+resource.Id.OpaqueId, viewMode.String(), token)
+func (p *demoProvider) GetAppURL(ctx context.Context, resource *provider.ResourceInfo, viewMode appprovider.OpenInAppRequest_ViewMode, token, language string) (*appprovider.OpenInAppURL, error) {
+ url := fmt.Sprintf("", p.iframeUIProvider, resource.Id.StorageId+":"+resource.Id.OpaqueId, viewMode.String(), token, language)
return &appprovider.OpenInAppURL{
AppUrl: url,
Method: "GET",
diff --git a/pkg/app/provider/wopi/wopi.go b/pkg/app/provider/wopi/wopi.go
index bec75f63a39..88e2e03527c 100644
--- a/pkg/app/provider/wopi/wopi.go
+++ b/pkg/app/provider/wopi/wopi.go
@@ -125,7 +125,7 @@ func New(m map[string]interface{}) (app.Provider, error) {
}, nil
}
-func (p *wopiProvider) GetAppURL(ctx context.Context, resource *provider.ResourceInfo, viewMode appprovider.OpenInAppRequest_ViewMode, token string) (*appprovider.OpenInAppURL, error) {
+func (p *wopiProvider) GetAppURL(ctx context.Context, resource *provider.ResourceInfo, viewMode appprovider.OpenInAppRequest_ViewMode, token, language string) (*appprovider.OpenInAppURL, error) {
log := appctx.GetLogger(ctx)
ext := path.Ext(resource.Path)
@@ -238,6 +238,19 @@ func (p *wopiProvider) GetAppURL(ctx context.Context, resource *provider.Resourc
appFullURL := result["app-url"].(string)
+ if language != "" {
+ url, err := url.Parse(appFullURL)
+ if err != nil {
+ return nil, err
+ }
+ urlQuery := url.Query()
+ urlQuery.Set("ui", language) // OnlyOffice
+ urlQuery.Set("lang", language) // Collabora
+ urlQuery.Set("UI_LLCC", language) // Office365
+ url.RawQuery = urlQuery.Encode()
+ appFullURL = url.String()
+ }
+
// Depending on whether wopi server returned any form parameters or not,
// we decide whether the request method is POST or GET
var formParams map[string]string
diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go
index 14ec95e4faf..d78af3fec0b 100644
--- a/pkg/utils/utils.go
+++ b/pkg/utils/utils.go
@@ -24,6 +24,7 @@ import (
"net"
"net/http"
"net/url"
+ "os"
"os/user"
"path"
"path/filepath"
@@ -348,7 +349,80 @@ func GetViewMode(viewMode string) gateway.OpenInAppRequest_ViewMode {
return gateway.OpenInAppRequest_VIEW_MODE_READ_ONLY
case "write":
return gateway.OpenInAppRequest_VIEW_MODE_READ_WRITE
+ case "preview":
+ return gateway.OpenInAppRequest_VIEW_MODE_PREVIEW
default:
return gateway.OpenInAppRequest_VIEW_MODE_INVALID
}
}
+
+// AppendPlainToOpaque adds a new key value pair as a plain string on the given opaque and returns it
+func AppendPlainToOpaque(o *types.Opaque, key, value string) *types.Opaque {
+ o = ensureOpaque(o)
+
+ o.Map[key] = &types.OpaqueEntry{
+ Decoder: "plain",
+ Value: []byte(value),
+ }
+ return o
+}
+
+// ReadPlainFromOpaque reads a plain string from the given opaque map
+func ReadPlainFromOpaque(o *types.Opaque, key string) string {
+ if o.GetMap() == nil {
+ return ""
+ }
+ if e, ok := o.Map[key]; ok && e.Decoder == "plain" {
+ return string(e.Value)
+ }
+ return ""
+}
+
+// ExistsInOpaque returns true if the key exists in the opaque (ignoring the value)
+func ExistsInOpaque(o *types.Opaque, key string) bool {
+ if o.GetMap() == nil {
+ return false
+ }
+
+ _, ok := o.Map[key]
+ return ok
+}
+
+// MergeOpaques will merge the opaques. If a key exists in both opaques
+// the values from the first opaque will be taken
+func MergeOpaques(o *types.Opaque, p *types.Opaque) *types.Opaque {
+ p = ensureOpaque(p)
+ for k, v := range o.GetMap() {
+ p.Map[k] = v
+ }
+ return p
+}
+
+// ensures the opaque is initialized
+func ensureOpaque(o *types.Opaque) *types.Opaque {
+ if o == nil {
+ o = &types.Opaque{}
+ }
+ if o.Map == nil {
+ o.Map = map[string]*types.OpaqueEntry{}
+ }
+ return o
+}
+
+// RemoveItem removes the given item, its children and all empty parent folders
+func RemoveItem(path string) error {
+ if err := os.RemoveAll(path); err != nil {
+ return err
+ }
+
+ for {
+ path = filepath.Dir(path)
+ if err := os.Remove(path); err != nil {
+ // remove will fail when the dir is not empty.
+ // We can exit in that case
+ return nil
+ }
+
+ }
+
+}