Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-01-24 03:08:51 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-01-24 03:08:51 +0300
commit1ce6af4aad0107b6d604f89a3c0b530476a10165 (patch)
tree4956b0d395cd9232bca14f83daca3cd8616cc842 /doc/development/i18n
parent24256212ea84e6fb6509f6fb317a2d2bac3d0d06 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'doc/development/i18n')
-rw-r--r--doc/development/i18n/externalization.md18
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.