From c314e71c0535921e60ad76ac81790877eb1e6b74 Mon Sep 17 00:00:00 2001 From: jkoberg Date: Mon, 30 Dec 2024 11:41:48 +0100 Subject: [PATCH] fix(docs): improve l10n docs Signed-off-by: jkoberg --- docs/services/general-info/add-translations.md | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/docs/services/general-info/add-translations.md b/docs/services/general-info/add-translations.md index 46065f642..481302270 100644 --- a/docs/services/general-info/add-translations.md +++ b/docs/services/general-info/add-translations.md @@ -29,7 +29,13 @@ Translations have a `context` and a `translatable string`. The context is shown * Add the `OCIS_DEFAULT_LANGUAGE` envvar in `services//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 `_TRANSLATION_PATH` envvar in `services//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//pkg/service/l10n/.tx/config` with the following content. Note that it is important to stick with `ocis-` to easily identify all ocis translations on Transifex: ``` @@ -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//pkg/service` that will define your translation sources like the following: +* Create an empty file `services//pkg/service/l10n/locale/en/LC_MESSAGES/.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//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") ``` @@ -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)/.pot \ --keyword=l10n.Template --add-comments -s \ - ocis/services//pkg/service/templates.go + pkg/service/templates.go .PHONY: l10n-write l10n-write: