Skip to content

Commit

Permalink
Merge pull request #10812 from kobergj/NotificationSettingTranslations
Browse files Browse the repository at this point in the history
Notification Option Translations
  • Loading branch information
kobergj authored Jan 8, 2025
2 parents a2dbd71 + dd4b168 commit 5fa4d8e
Show file tree
Hide file tree
Showing 15 changed files with 303 additions and 99 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ L10N_MODULES := \
services/activitylog \
services/graph \
services/notifications \
services/userlog
services/userlog \
services/settings

# if you add a module here please also add it to the .drone.star file
OCIS_MODULES = \
Expand Down
5 changes: 5 additions & 0 deletions changelog/unreleased/notification-settings-translations.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Enhancement: Translate Notification Settings

Translates the notification settings according to the users language preference.

https://github.com/owncloud/ocis/pull/10812
16 changes: 12 additions & 4 deletions docs/services/general-info/add-translations.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ Translations have a `context` and a `translatable string`. The context is shown
* Add the `OCIS_DEFAULT_LANGUAGE` envvar in `services/<service-name>/pkg/config/config.go`.\
For details see the userlog or notifications service code.

* Use `"github.com/owncloud/ocis/v2/ocis-pkg/l10n"` for the translation.
* Add the `<SERVICE_NAME>_TRANSLATION_PATH` envvar in `services/<service-name>/pkg/config/config.go`.\
For details see the userlog or notifications service code.

* Use `"github.com/owncloud/ocis/v2/ocis-pkg/l10n"` for the translation.\
Use `l10n.Template` to define the translation string.\
Use `l10n.NewTranslator` or `l10n.NewTranslatorFromCommonConfig` to get the translator.\
Use `t.Get` to translate the string. See package for more advanced usage.

* Create a config in `services/<service-name>/pkg/service/l10n/.tx/config` with the following content. Note that it is important to stick with `ocis-<service-name>` to easily identify all ocis translations on Transifex:
```
Expand All @@ -46,9 +52,11 @@ Translations have a `context` and a `translatable string`. The context is shown
```
Note: o: organization, p: project, r: resource

* Create a go file like `templates.go` in `ocis/services/<service-name>/pkg/service` that will define your translation sources like the following:
* Create an empty file `services/<service-name>/pkg/service/l10n/locale/en/LC_MESSAGES/<service-name>.po`. This is required for ocis to build. This file will be replaced nightly with the latest translations from Transifex.

* Create a go file like `templates.go` in e.g. `ocis/services/<service-name>/pkg/service` that will define your translation sources like the following:
```
// context string
// this comment will appear in transifex as context
var yourString = l10n.Template("Translation String")
```

Expand Down Expand Up @@ -85,7 +93,7 @@ Translations have a `context` and a `translatable string`. The context is shown
l10n-read: $(GO_XGETTEXT)
go-xgettext -o $(OUTPUT_DIR)/<service-name>.pot \
--keyword=l10n.Template --add-comments -s \
ocis/services/<service-name>/pkg/service/templates.go
pkg/service/templates.go
.PHONY: l10n-write
l10n-write:
Expand Down
4 changes: 2 additions & 2 deletions ocis-pkg/l10n/l10n.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"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"
)

Expand Down Expand Up @@ -140,7 +139,8 @@ func GetUserLocale(ctx context.Context, userID string, vc settingssvc.ValueServi
micrometadata.Set(ctx, middleware.AccountID, userID),
&settingssvc.GetValueByUniqueIdentifiersRequest{
AccountUuid: userID,
SettingId: defaults.SettingUUIDProfileLanguage,
// this defaults.SettingUUIDProfileLanguage. Copied here to avoid import cycles.
SettingId: "aa8cfbe5-95d4-4f7e-a032-c3c01f5f062f",
},
)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions protogen/proto/ocis/services/settings/v0/settings.proto
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ message GetBundleResponse {

message ListBundlesRequest {
repeated string bundle_ids = 1;
string locale = 2;
}

message ListBundlesResponse {
Expand Down
2 changes: 2 additions & 0 deletions services/frontend/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ type Config struct {

PasswordPolicy PasswordPolicy `yaml:"password_policy"`

ConfigurableNotifications bool `yaml:"configurable_notifications" env:"FRONTEND_CONFIGURABLE_NOTIFICATIONS" desc:"Allow configuring notifications via web client." introductionVersion:"7.1"`

Context context.Context `yaml:"-"`
}

Expand Down
3 changes: 2 additions & 1 deletion services/frontend/pkg/revaconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,8 @@ func FrontendConfigFromStruct(cfg *config.Config, logger log.Logger) (map[string
},
"password_policy": passwordPolicyCfg,
"notifications": map[string]interface{}{
"endpoints": []string{"list", "get", "delete"},
"endpoints": []string{"list", "get", "delete"},
"configurable": cfg.ConfigurableNotifications,
},
},
"version": map[string]interface{}{
Expand Down
26 changes: 26 additions & 0 deletions services/settings/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
SHELL := bash
NAME := settings

# Where to write the files generated by this makefile.
OUTPUT_DIR = ./pkg/service/v0/l10n
TEMPLATE_FILE = ./pkg/service/v0/l10n/settings.pot

include ../../.make/recursion.mk

############ tooling ############
Expand Down Expand Up @@ -45,3 +49,25 @@ ci-node-check-licenses:

.PHONY: ci-node-save-licenses
ci-node-save-licenses:

############ translations ########
.PHONY: l10n-pull
l10n-pull:
cd $(OUTPUT_DIR) && tx pull --all --force --skip --minimum-perc=75

.PHONY: l10n-push
l10n-push:
cd $(OUTPUT_DIR) && tx push -s --skip

.PHONY: l10n-read
l10n-read: $(GO_XGETTEXT)
go-xgettext -o $(OUTPUT_DIR)/settings.pot \
--keyword=l10n.Template --add-comments -s \
pkg/store/defaults/templates.go

.PHONY: l10n-write
l10n-write:

.PHONY: l10n-clean
l10n-clean:
rm -f $(TEMPLATE_FILE);
22 changes: 22 additions & 0 deletions services/settings/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,28 @@ Services can set or query Infinite Scale *setting values* of a user from setting

The settings service needs to know the IDs of service accounts but it doesn't need their secrets. They can be configured using the `SETTINGS_SERVICE_ACCOUNTS_IDS` envvar. When only using one service account `OCIS_SERVICE_ACCOUNT_ID` can also be used. All configured service accounts will get a hidden 'service-account' role. This role contains all permissions the service account needs but will not appear calls to the list roles endpoint. It is not possible to assign the 'service-account' role to a normal user.

## Translations

The `settings` service has embedded translations sourced via transifex to provide a basic set of translated languages. These embedded translations are available for all deployment scenarios. In addition, the service supports custom translations, though it is currently not possible to just add custom translations to embedded ones. If custom translations are configured, the embedded ones are not used. To configure custom translations, the `SETTINGS_TRANSLATION_PATH` environment variable needs to point to a base folder that will contain the translation files. This path must be available from all instances of the userlog service, a shared storage is recommended. Translation files must be of type [.po](https://www.gnu.org/software/gettext/manual/html_node/PO-Files.html#PO-Files) or [.mo](https://www.gnu.org/software/gettext/manual/html_node/Binaries.html). For each language, the filename needs to be `settings.po` (or `settings.mo`) and stored in a folder structure defining the language code. In general the path/name pattern for a translation file needs to be:

```text
{SETTINGS_TRANSLATION_PATH}/{language-code}/LC_MESSAGES/settings.po
```

The language code pattern is composed of `language[_territory]` where `language` is the base language and `_territory` is optional and defines a country.

For example, for the language `de`, one needs to place the corresponding translation files to `{SETTINGS_TRANSLATION_PATH}/de_DE/LC_MESSAGES/settings.po`.

<!-- also see the notifications readme -->

Important: For the time being, the embedded ownCloud Web frontend only supports the main language code but does not handle any territory. When strings are available in the language code `language_territory`, the web frontend does not see it as it only requests `language`. In consequence, any translations made must exist in the requested `language` to avoid a fallback to the default.

### Translation Rules

* If a requested language code is not available, the service tries to fall back to the base language if available. For example, if the requested language-code `de_DE` is not available, the service tries to fall back to translations in the `de` folder.
* If the base language `de` is also not available, the service falls back to the system's default English (`en`),
which is the source of the texts provided by the code.

## Default Language

The default language can be defined via the `OCIS_DEFAULT_LANGUAGE` environment variable. If this variable is not defined, English will be used as default. The value has the ISO 639-1 format ("de", "en", etc.) and is limited by the list supported languages. This setting can be used to set the default language for notification and invitation emails.
Expand Down
1 change: 1 addition & 0 deletions services/settings/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type Config struct {
ServiceAccountIDs []string `yaml:"service_account_ids" env:"SETTINGS_SERVICE_ACCOUNT_IDS;OCIS_SERVICE_ACCOUNT_ID" desc:"The list of all service account IDs. These will be assigned the hidden 'service-account' role. Note: When using 'OCIS_SERVICE_ACCOUNT_ID' this will contain only one value while 'SETTINGS_SERVICE_ACCOUNT_IDS' can have multiple. See the 'auth-service' service description for more details about service accounts." introductionVersion:"5.0"`

DefaultLanguage string `yaml:"default_language" env:"OCIS_DEFAULT_LANGUAGE" desc:"The default language used by services and the WebUI. If not defined, English will be used as default. See the documentation for more details." introductionVersion:"5.0"`
TranslationPath string `yaml:"translation_path" env:"OCIS_TRANSLATION_PATH;SETTINGS_TRANSLATION_PATH" desc:"(optional) Set this to a path with custom translations to overwrite the builtin translations. Note that file and folder naming rules apply, see the documentation for more details." introductionVersion:"7.1"`

Context context.Context `yaml:"-"`
}
Expand Down
10 changes: 10 additions & 0 deletions services/settings/pkg/service/v0/l10n/.tx/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[main]
host = https://www.transifex.com

[o:owncloud-org:p:owncloud:r:ocis-settings]
file_filter = locale/<lang>/LC_MESSAGES/settings.po
minimum_perc = 75
resource_name = ocis-settings
source_file = settings.pot
source_lang = en
type = PO
Empty file.
Loading

0 comments on commit 5fa4d8e

Please sign in to comment.