-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8723 from kobergj/SpaceTemplatesII
Server-Side Space Templates
- Loading branch information
Showing
23 changed files
with
387 additions
and
298 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Enhancement: Make server side space templates production ready | ||
|
||
Fixes several smaller bugs and adds some improvements to space templates, introduced with https://github.com/owncloud/ocis/pull/8558 | ||
|
||
https://github.com/owncloud/ocis/pull/8723 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// package l10n holds translation mechanics that are used by user facing services (notifications, userlog, graph) | ||
package l10n | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"io/fs" | ||
"os" | ||
|
||
"github.com/leonelquinteros/gotext" | ||
"github.com/owncloud/ocis/v2/ocis-pkg/middleware" | ||
settingssvc "github.com/owncloud/ocis/v2/protogen/gen/ocis/services/settings/v0" | ||
"github.com/owncloud/ocis/v2/services/settings/pkg/store/defaults" | ||
micrometadata "go-micro.dev/v4/metadata" | ||
) | ||
|
||
// Template marks a string as translatable | ||
func Template(s string) string { return s } | ||
|
||
// Translator is able to translate strings | ||
type Translator struct { | ||
fs fs.FS | ||
defaultLocale string | ||
domain string | ||
} | ||
|
||
// NewTranslator creates a Translator with library path and language code and load default domain | ||
func NewTranslator(defaultLocale string, domain string, fsys fs.FS) Translator { | ||
return Translator{ | ||
fs: fsys, | ||
defaultLocale: defaultLocale, | ||
domain: domain, | ||
} | ||
} | ||
|
||
// NewTranslatorFromCommonConfig creates a new Translator from legacy config | ||
func NewTranslatorFromCommonConfig(defaultLocale string, domain string, path string, fsys fs.FS, fsSubPath string) Translator { | ||
var filesystem fs.FS | ||
if path == "" { | ||
filesystem, _ = fs.Sub(fsys, fsSubPath) | ||
} else { // use custom path instead | ||
filesystem = os.DirFS(path) | ||
} | ||
return NewTranslator(defaultLocale, domain, filesystem) | ||
} | ||
|
||
// Translate translates a string to the locale | ||
func (t Translator) Translate(str, locale string) string { | ||
return t.Locale(locale).Get(str) | ||
} | ||
|
||
// Locale returns the gotext.Locale, use `.Get` method to translate strings | ||
func (t Translator) Locale(locale string) *gotext.Locale { | ||
l := gotext.NewLocaleFS(locale, t.fs) | ||
l.AddDomain(t.domain) // make domain configurable only if needed | ||
if locale != "en" && len(l.GetTranslations()) == 0 { | ||
l = gotext.NewLocaleFS(t.defaultLocale, t.fs) | ||
l.AddDomain(t.domain) // make domain configurable only if needed | ||
} | ||
return l | ||
} | ||
|
||
// MustGetUserLocale returns the locale the user wants to use, omitting errors | ||
func MustGetUserLocale(ctx context.Context, userID string, preferedLang string, vc settingssvc.ValueService) string { | ||
if preferedLang != "" { | ||
return preferedLang | ||
} | ||
|
||
locale, _ := GetUserLocale(ctx, userID, vc) | ||
return locale | ||
} | ||
|
||
// GetUserLocale returns the locale of the user | ||
func GetUserLocale(ctx context.Context, userID string, vc settingssvc.ValueService) (string, error) { | ||
resp, err := vc.GetValueByUniqueIdentifiers( | ||
micrometadata.Set(ctx, middleware.AccountID, userID), | ||
&settingssvc.GetValueByUniqueIdentifiersRequest{ | ||
AccountUuid: userID, | ||
SettingId: defaults.SettingUUIDProfileLanguage, | ||
}, | ||
) | ||
if err != nil { | ||
return "", err | ||
} | ||
val := resp.GetValue().GetValue().GetListValue().GetValues() | ||
if len(val) == 0 { | ||
return "", errors.New("no language setting found") | ||
} | ||
return val[0].GetStringValue(), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[main] | ||
host = https://www.transifex.com | ||
|
||
[o:owncloud-org:p:owncloud:r:ocis-graph] | ||
file_filter = locale/<lang>/LC_MESSAGES/graph.po | ||
minimum_perc = 75 | ||
source_file = graph.pot | ||
source_lang = en | ||
type = PO |
22 changes: 22 additions & 0 deletions
22
services/graph/pkg/service/v0/l10n/locale/en_GB/LC_MESSAGES/graph.po
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# SOME DESCRIPTIVE TITLE. | ||
# 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. | ||
# | ||
#, fuzzy | ||
msgid "" | ||
msgstr "Project-Id-Version: \n" | ||
"Report-Msgid-Bugs-To: EMAIL\n" | ||
"POT-Creation-Date: 2024-03-26 15:11+0100\n" | ||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" | ||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" | ||
"Language-Team: LANGUAGE <[email protected]>\n" | ||
"Language: \n" | ||
"MIME-Version: 1.0\n" | ||
"Content-Type: text/plain; charset=CHARSET\n" | ||
"Content-Transfer-Encoding: 8bit\n" | ||
|
||
#: pkg/service/v0/spacetemplates.go:29 | ||
msgid "Here you can add a description for this Space." | ||
msgstr "" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file was deleted.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.