3.4 KiB
title, date, weight, geekdocRepo, geekdocEditPath, geekdocFilePath, geekdocCollapseSection
| title | date | weight | geekdocRepo | geekdocEditPath | geekdocFilePath | geekdocCollapseSection |
|---|---|---|---|---|---|---|
| Add Translations | 2024-04-08T00:00:00+00:00 | 20 | https://github.com/owncloud/ocis | edit/master/docs/services/general-info | add-translations.md | true |
Services can have texts that need to be translated. These translations will be shown in the ownCloud Web UI. Compared to web, these translations are:
- Independent of ownCloud Web on Transifex.
- Are located in the ownCloud Transifex Project.
- Have a name starting with
ocis-for ease of identification.
The process for synchronisation with Transifex is already setup and nothing needs to be done here. For any translation, it is necessary to set it up in the respective service and tell to sync it.
Translations are automatically synced on a daily basis in the night.
Implementing ocis Translations
The implementation example is a guide and shall show how to do it. You can derive at any time according to your needs.
Note that paths are examples and can be adapted based on requirements.
Replace <service-name> with the name of the respective service.
Translations have a context and a translatable string. The context is shown on Transifex but not translated and helps translators to get a context for the string to be translated.
-
Add the
OCIS_DEFAULT_LANGUAGEenvvar inservices/<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. -
Create a config in
services/<service-name>/pkg/service/l10n/.tx/configwith the following content. Note that it is important to stick withocis-<service-name>to easily identify all ocis translations on Transifex:[main] host = https://www.transifex.com [o:owncloud-org:p:owncloud:r:ocis-<service-name>] file_filter = locale/<lang>/LC_MESSAGES/<service-name>.po minimum_perc = 75 source_file = <service-name>.pot source_lang = en type = PO -
Create a go file like
templates.goinocis/services/<service-name>/pkg/servicethat will define your translation sources like the following:// context string var yourString = l10n.Template("Translation String") -
In the
Makefilein the ocis root, add in the following section the service you want to synchronize translations with Transifex:# add a service here when it uses transifex L10N_MODULES := \ services/notifications \ services/userlog \ services/graph \ services/<service-name> -
In the
Makefileof the<service-name>add:
At the beginning:# Where to write the files generated by this makefile. OUTPUT_DIR = ./pkg/service/<...>/l10n TEMPLATE_FILE = ./pkg/service/<...>/l10n/<service-name>.potIn the
.PHONYlist:############ 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)/<service-name>.pot \ --keyword=l10n.Template --add-comments -s \ ocis/services/<service-name>/pkg/service/templates.go .PHONY: l10n-write l10n-write: .PHONY: l10n-clean l10n-clean: rm -f $(TEMPLATE_FILE);