Skip to content

Commit 5fa4d8e

Browse files
authored
Merge pull request #10812 from kobergj/NotificationSettingTranslations
Notification Option Translations
2 parents a2dbd71 + dd4b168 commit 5fa4d8e

File tree

15 files changed

+303
-99
lines changed

15 files changed

+303
-99
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ L10N_MODULES := \
1717
services/activitylog \
1818
services/graph \
1919
services/notifications \
20-
services/userlog
20+
services/userlog \
21+
services/settings
2122

2223
# if you add a module here please also add it to the .drone.star file
2324
OCIS_MODULES = \
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Enhancement: Translate Notification Settings
2+
3+
Translates the notification settings according to the users language preference.
4+
5+
https://github.com/owncloud/ocis/pull/10812

docs/services/general-info/add-translations.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,13 @@ Translations have a `context` and a `translatable string`. The context is shown
2929
* Add the `OCIS_DEFAULT_LANGUAGE` envvar in `services/<service-name>/pkg/config/config.go`.\
3030
For details see the userlog or notifications service code.
3131

32-
* Use `"github.com/owncloud/ocis/v2/ocis-pkg/l10n"` for the translation.
32+
* Add the `<SERVICE_NAME>_TRANSLATION_PATH` envvar in `services/<service-name>/pkg/config/config.go`.\
33+
For details see the userlog or notifications service code.
34+
35+
* Use `"github.com/owncloud/ocis/v2/ocis-pkg/l10n"` for the translation.\
36+
Use `l10n.Template` to define the translation string.\
37+
Use `l10n.NewTranslator` or `l10n.NewTranslatorFromCommonConfig` to get the translator.\
38+
Use `t.Get` to translate the string. See package for more advanced usage.
3339

3440
* 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:
3541
```
@@ -46,9 +52,11 @@ Translations have a `context` and a `translatable string`. The context is shown
4652
```
4753
Note: o: organization, p: project, r: resource
4854

49-
* Create a go file like `templates.go` in `ocis/services/<service-name>/pkg/service` that will define your translation sources like the following:
55+
* 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.
56+
57+
* 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:
5058
```
51-
// context string
59+
// this comment will appear in transifex as context
5260
var yourString = l10n.Template("Translation String")
5361
```
5462

@@ -85,7 +93,7 @@ Translations have a `context` and a `translatable string`. The context is shown
8593
l10n-read: $(GO_XGETTEXT)
8694
go-xgettext -o $(OUTPUT_DIR)/<service-name>.pot \
8795
--keyword=l10n.Template --add-comments -s \
88-
ocis/services/<service-name>/pkg/service/templates.go
96+
pkg/service/templates.go
8997
9098
.PHONY: l10n-write
9199
l10n-write:

ocis-pkg/l10n/l10n.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"github.com/leonelquinteros/gotext"
1212
"github.com/owncloud/ocis/v2/ocis-pkg/middleware"
1313
settingssvc "github.com/owncloud/ocis/v2/protogen/gen/ocis/services/settings/v0"
14-
"github.com/owncloud/ocis/v2/services/settings/pkg/store/defaults"
1514
micrometadata "go-micro.dev/v4/metadata"
1615
)
1716

@@ -140,7 +139,8 @@ func GetUserLocale(ctx context.Context, userID string, vc settingssvc.ValueServi
140139
micrometadata.Set(ctx, middleware.AccountID, userID),
141140
&settingssvc.GetValueByUniqueIdentifiersRequest{
142141
AccountUuid: userID,
143-
SettingId: defaults.SettingUUIDProfileLanguage,
142+
// this defaults.SettingUUIDProfileLanguage. Copied here to avoid import cycles.
143+
SettingId: "aa8cfbe5-95d4-4f7e-a032-c3c01f5f062f",
144144
},
145145
)
146146
if err != nil {

protogen/proto/ocis/services/settings/v0/settings.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ message GetBundleResponse {
168168

169169
message ListBundlesRequest {
170170
repeated string bundle_ids = 1;
171+
string locale = 2;
171172
}
172173

173174
message ListBundlesResponse {

services/frontend/pkg/config/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ type Config struct {
5858

5959
PasswordPolicy PasswordPolicy `yaml:"password_policy"`
6060

61+
ConfigurableNotifications bool `yaml:"configurable_notifications" env:"FRONTEND_CONFIGURABLE_NOTIFICATIONS" desc:"Allow configuring notifications via web client." introductionVersion:"7.1"`
62+
6163
Context context.Context `yaml:"-"`
6264
}
6365

services/frontend/pkg/revaconfig/config.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,8 @@ func FrontendConfigFromStruct(cfg *config.Config, logger log.Logger) (map[string
333333
},
334334
"password_policy": passwordPolicyCfg,
335335
"notifications": map[string]interface{}{
336-
"endpoints": []string{"list", "get", "delete"},
336+
"endpoints": []string{"list", "get", "delete"},
337+
"configurable": cfg.ConfigurableNotifications,
337338
},
338339
},
339340
"version": map[string]interface{}{

services/settings/Makefile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
SHELL := bash
22
NAME := settings
33

4+
# Where to write the files generated by this makefile.
5+
OUTPUT_DIR = ./pkg/service/v0/l10n
6+
TEMPLATE_FILE = ./pkg/service/v0/l10n/settings.pot
7+
48
include ../../.make/recursion.mk
59

610
############ tooling ############
@@ -45,3 +49,25 @@ ci-node-check-licenses:
4549

4650
.PHONY: ci-node-save-licenses
4751
ci-node-save-licenses:
52+
53+
############ translations ########
54+
.PHONY: l10n-pull
55+
l10n-pull:
56+
cd $(OUTPUT_DIR) && tx pull --all --force --skip --minimum-perc=75
57+
58+
.PHONY: l10n-push
59+
l10n-push:
60+
cd $(OUTPUT_DIR) && tx push -s --skip
61+
62+
.PHONY: l10n-read
63+
l10n-read: $(GO_XGETTEXT)
64+
go-xgettext -o $(OUTPUT_DIR)/settings.pot \
65+
--keyword=l10n.Template --add-comments -s \
66+
pkg/store/defaults/templates.go
67+
68+
.PHONY: l10n-write
69+
l10n-write:
70+
71+
.PHONY: l10n-clean
72+
l10n-clean:
73+
rm -f $(TEMPLATE_FILE);

services/settings/README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,28 @@ Services can set or query Infinite Scale *setting values* of a user from setting
6464

6565
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.
6666

67+
## Translations
68+
69+
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:
70+
71+
```text
72+
{SETTINGS_TRANSLATION_PATH}/{language-code}/LC_MESSAGES/settings.po
73+
```
74+
75+
The language code pattern is composed of `language[_territory]` where `language` is the base language and `_territory` is optional and defines a country.
76+
77+
For example, for the language `de`, one needs to place the corresponding translation files to `{SETTINGS_TRANSLATION_PATH}/de_DE/LC_MESSAGES/settings.po`.
78+
79+
<!-- also see the notifications readme -->
80+
81+
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.
82+
83+
### Translation Rules
84+
85+
* 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.
86+
* If the base language `de` is also not available, the service falls back to the system's default English (`en`),
87+
which is the source of the texts provided by the code.
88+
6789
## Default Language
6890

6991
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.

services/settings/pkg/config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ type Config struct {
3838
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"`
3939

4040
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"`
41+
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"`
4142

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

0 commit comments

Comments
 (0)