diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-24 00:08:51 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-24 00:08:51 +0000 |
commit | 1ce6af4aad0107b6d604f89a3c0b530476a10165 (patch) | |
tree | 4956b0d395cd9232bca14f83daca3cd8616cc842 /doc/development/i18n | |
parent | 24256212ea84e6fb6509f6fb317a2d2bac3d0d06 (diff) | |
download | gitlab-ce-1ce6af4aad0107b6d604f89a3c0b530476a10165.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'doc/development/i18n')
-rw-r--r-- | doc/development/i18n/externalization.md | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/doc/development/i18n/externalization.md b/doc/development/i18n/externalization.md index 386baf825b8..488d7ae6762 100644 --- a/doc/development/i18n/externalization.md +++ b/doc/development/i18n/externalization.md @@ -77,6 +77,24 @@ Or: hello = _("Hello world!") ``` +Be careful when translating strings at the class or module level since these would only be +evaluated once at class load time. + +For example: + +```ruby +validates :group_id, uniqueness: { scope: [:project_id], message: _("already shared with this group") } +``` + +This would be translated when the class is loaded and result in the error message +always being in the default locale. + +Active Record's `:message` option accepts a `Proc`, so we can do this instead: + +```ruby +validates :group_id, uniqueness: { scope: [:project_id], message: -> (object, data) { _("already shared with this group") } } +``` + NOTE: **Note:** Messages in the API (`lib/api/` or `app/graphql`) do not need to be externalised. |