Skip to content

Commit 1e4948b

Browse files
authored
Added support for language locales in apps (partly backported from edge) (#3303)
1 parent 3a0b14f commit 1e4948b

File tree

7 files changed

+32
-5
lines changed

7 files changed

+32
-5
lines changed
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Enhancement: added support for configuring language locales in apps
2+
3+
This is a partial backport from edge: we introduce a language option
4+
in the appprovider, which if set is passed as appropriate parameter
5+
to the external apps in order to force a given localization. In particular,
6+
for Microsoft Office 365 the DC_LLCC option is set as well.
7+
The default behavior is unset, where apps try and resolve the
8+
localization from the browser headers.
9+
10+
https://github.com/cs3org/reva/pull/3303

examples/storage-references/gateway.toml

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ mime_types = [
4646

4747
[grpc.services.appprovider]
4848
mime_types = ["text/plain"]
49+
language = "en-GB"
4950

5051
[http.services.datagateway]
5152
[http.services.prometheus]

internal/grpc/services/appprovider/appprovider.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ type config struct {
5858
GatewaySvc string `mapstructure:"gatewaysvc"`
5959
MimeTypes []string `mapstructure:"mime_types"`
6060
Priority uint64 `mapstructure:"priority"`
61+
Language string `mapstructure:"language"`
6162
}
6263

6364
func (c *config) init() {
@@ -170,7 +171,7 @@ func getProvider(c *config) (app.Provider, error) {
170171
}
171172

172173
func (s *service) OpenInApp(ctx context.Context, req *providerpb.OpenInAppRequest) (*providerpb.OpenInAppResponse, error) {
173-
appURL, err := s.provider.GetAppURL(ctx, req.ResourceInfo, req.ViewMode, req.AccessToken)
174+
appURL, err := s.provider.GetAppURL(ctx, req.ResourceInfo, req.ViewMode, req.AccessToken, s.conf.Language)
174175
if err != nil {
175176
res := &providerpb.OpenInAppResponse{
176177
Status: status.NewInternal(ctx, errors.New("appprovider: error calling GetAppURL"), err.Error()),

pkg/app/app.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,6 @@ type Registry interface {
4040
// Provider is the interface that application providers implement
4141
// for interacting with external apps that serve the requested resource.
4242
type Provider interface {
43-
GetAppURL(ctx context.Context, resource *provider.ResourceInfo, viewMode appprovider.OpenInAppRequest_ViewMode, token string) (*appprovider.OpenInAppURL, error)
43+
GetAppURL(ctx context.Context, resource *provider.ResourceInfo, viewMode appprovider.OpenInAppRequest_ViewMode, token, language string) (*appprovider.OpenInAppURL, error)
4444
GetAppProviderInfo(ctx context.Context) (*registry.ProviderInfo, error)
4545
}

pkg/app/provider/demo/demo.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ type demoProvider struct {
3838
iframeUIProvider string
3939
}
4040

41-
func (p *demoProvider) GetAppURL(ctx context.Context, resource *provider.ResourceInfo, viewMode appprovider.OpenInAppRequest_ViewMode, token string) (*appprovider.OpenInAppURL, error) {
42-
url := fmt.Sprintf("<iframe src=%s/open/%s?view-mode=%s&access-token=%s />", p.iframeUIProvider, resource.Id.StorageId+":"+resource.Id.OpaqueId, viewMode.String(), token)
41+
func (p *demoProvider) GetAppURL(ctx context.Context, resource *provider.ResourceInfo, viewMode appprovider.OpenInAppRequest_ViewMode, token, language string) (*appprovider.OpenInAppURL, error) {
42+
url := fmt.Sprintf("<iframe src=%s/open/%s?view-mode=%s&access-token=%s&lang=%s />", p.iframeUIProvider, resource.Id.StorageId+":"+resource.Id.OpaqueId, viewMode.String(), token, language)
4343
return &appprovider.OpenInAppURL{
4444
AppUrl: url,
4545
Method: "GET",

pkg/app/provider/wopi/wopi.go

+14-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ func New(m map[string]interface{}) (app.Provider, error) {
125125
}, nil
126126
}
127127

128-
func (p *wopiProvider) GetAppURL(ctx context.Context, resource *provider.ResourceInfo, viewMode appprovider.OpenInAppRequest_ViewMode, token string) (*appprovider.OpenInAppURL, error) {
128+
func (p *wopiProvider) GetAppURL(ctx context.Context, resource *provider.ResourceInfo, viewMode appprovider.OpenInAppRequest_ViewMode, token, language string) (*appprovider.OpenInAppURL, error) {
129129
log := appctx.GetLogger(ctx)
130130

131131
ext := path.Ext(resource.Path)
@@ -238,6 +238,19 @@ func (p *wopiProvider) GetAppURL(ctx context.Context, resource *provider.Resourc
238238

239239
appFullURL := result["app-url"].(string)
240240

241+
if language != "" {
242+
url, err := url.Parse(appFullURL)
243+
if err != nil {
244+
return nil, err
245+
}
246+
urlQuery := url.Query()
247+
urlQuery.Set("ui", language) // OnlyOffice + Office365
248+
urlQuery.Set("lang", language) // Collabora
249+
urlQuery.Set("rs", language) // Office365, https://learn.microsoft.com/en-us/microsoft-365/cloud-storage-partner-program/online/discovery#dc_llcc
250+
url.RawQuery = urlQuery.Encode()
251+
appFullURL = url.String()
252+
}
253+
241254
// Depending on whether wopi server returned any form parameters or not,
242255
// we decide whether the request method is POST or GET
243256
var formParams map[string]string

pkg/utils/utils.go

+2
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,8 @@ func GetViewMode(viewMode string) gateway.OpenInAppRequest_ViewMode {
348348
return gateway.OpenInAppRequest_VIEW_MODE_READ_ONLY
349349
case "write":
350350
return gateway.OpenInAppRequest_VIEW_MODE_READ_WRITE
351+
case "preview":
352+
return gateway.OpenInAppRequest_VIEW_MODE_PREVIEW
351353
default:
352354
return gateway.OpenInAppRequest_VIEW_MODE_INVALID
353355
}

0 commit comments

Comments
 (0)