Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
62f0112c
Commit
62f0112c
authored
Jan 21, 2020
by
Heinrich Lee Yu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add note about translating class-level strings
parent
dc6db392
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
0 deletions
+18
-0
doc/development/i18n/externalization.md
doc/development/i18n/externalization.md
+18
-0
No files found.
doc/development/i18n/externalization.md
View file @
62f0112c
...
...
@@ -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.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment