Embedded and backend
How to translate embedded comments and the backend parts
The backend (the server part) and the embedded comment engine share the same set of so-called messages, all of them located under resources/i18n/ in the project root.
You can see the list of available languages by logging into the Administration UI as a superuser and navigating to Configuration ⇒ Static: the section Available UI languages lists all installed translations.
Each translation is a text-based YAML file, providing a mapping between Message ID and Message translation. The file name must be a RFC 5646 tag of the target language, and its extension yaml. For example:
ru.yamlfor Russianen.yamlfor Englishen-gb.yamlfor British Englishpt.yamlfor Portuguese (Portugal)pt-br.yamlfor Brazilian Portuguese
Here’s an example for English:
# en.yaml
- {id: accountCreatedConfirmEmail, translation: Account is successfully created. Please check your email and click the confirmation link it contains.}
- {id: actionAddComment, translation: Add Comment}
- {id: actionApprove, translation: Approve}
- {id: actionCancel, translation: Cancel}
And below is an example how the same messages look in Russian:
# ru.yaml
- {id: accountCreatedConfirmEmail, translation: Аккаунт успешно зарегистрирован. Мы отправили вам емэйл, пожалуйста, подтвердите свой адрес, перейдя по содержащейся в нём ссылке.}
- {id: actionAddComment, translation: Добавить комментарий}
- {id: actionApprove, translation: Утвердить}
- {id: actionCancel, translation: Отмена}
Placeholders
Some messages have a blank in them that the application fills in — a user’s name, a domain, a date. It’s written as the name of the value in double curly braces, and it has to survive into the translation exactly as it is, spelling and capitalisation included:
# en.yaml
- {id: helloName, translation: 'Hello {{ .Name }}!'}
- {id: newCommentOn, translation: 'New comment on {{ .Page }}'}
# ru.yaml
- {id: helloName, translation: 'Привет, {{ .Name }}!'}
- {id: newCommentOn, translation: 'Новый комментарий на {{ .Page }}'}
The name says what goes there, so a translation is free to put it wherever the language needs it, and to use it more than once. A name that doesn’t exist (e.g. a typo, or one invented for the translation) isn’t an error the build catches: it shows up in the message as <no value>, so it’s worth copying rather than retyping.
Missing translations
A message missing from a translation falls back to its English (en.yaml) version. To see which messages a translation lacks, start the server with the --log.missing-i18n option and at least the info log level (e.g. -v): it lists the IDs of the missing messages for every language on startup. Without that option, only their count per language is logged, at the debug level.
Process
If you’d like to contribute your own translation for a language that is missing, follow these steps:
- Fork the Comentario repository.
- Make a copy of an existing translation (
resources/i18n/en.yamlis always the most complete one) into a newresources/i18n/<language_tag>.yaml. - Translate every message.
- Modify the file
cypress/support/cy-utils.tsby adding your new language spec to the constantUI_LANGUAGES, making sure to maintain alphabetical order of keys: it gets verified by the automated end-2-end tests. - Commit both files into your fork.
- Make sure the build pipeline has finished successfully.
- Submit a Merge Request for merging your changes into the
devbranch.
