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
0
Merge Requests
0
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
Jérome Perrin
gitlab-ce
Commits
1da594d3
Commit
1da594d3
authored
Aug 24, 2017
by
Bob Van Landuyt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Check newlines in translations
parent
973c6979
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
2 deletions
+41
-2
lib/gitlab/po_linter.rb
lib/gitlab/po_linter.rb
+16
-0
spec/fixtures/newlines.po
spec/fixtures/newlines.po
+9
-0
spec/lib/gitlab/po_linter_spec.rb
spec/lib/gitlab/po_linter_spec.rb
+16
-2
No files found.
lib/gitlab/po_linter.rb
View file @
1da594d3
...
@@ -61,6 +61,10 @@ module Gitlab
...
@@ -61,6 +61,10 @@ module Gitlab
if
entry
[
:msgid
].
is_a?
(
Array
)
if
entry
[
:msgid
].
is_a?
(
Array
)
errors
<<
"<
#{
message_id
}
> is defined over multiple lines, this breaks some tooling."
errors
<<
"<
#{
message_id
}
> is defined over multiple lines, this breaks some tooling."
end
end
if
translations_in_entry
(
entry
).
any?
{
|
translation
|
translation
.
is_a?
(
Array
)
}
errors
<<
"<
#{
message_id
}
> has translations defined over multiple lines, this breaks some tooling."
end
end
end
def
validate_variables
(
errors
,
entry
)
def
validate_variables
(
errors
,
entry
)
...
@@ -172,5 +176,17 @@ module Gitlab
...
@@ -172,5 +176,17 @@ module Gitlab
def
join_message
(
message
)
def
join_message
(
message
)
Array
(
message
).
join
Array
(
message
).
join
end
end
def
translations_in_entry
(
entry
)
if
entry
[
:msgid_plural
].
present?
entry
.
fetch_values
(
*
plural_translation_keys_in_entry
(
entry
))
else
[
entry
[
:msgstr
]]
end
end
def
plural_translation_keys_in_entry
(
entry
)
entry
.
keys
.
select
{
|
key
|
key
=~
/msgstr\[\d*\]/
}
end
end
end
end
end
spec/fixtures/newlines.po
View file @
1da594d3
...
@@ -30,3 +30,12 @@ msgstr ""
...
@@ -30,3 +30,12 @@ msgstr ""
"Va a eliminar %{group_name}.\n"
"Va a eliminar %{group_name}.\n"
"¡El grupo eliminado NO puede ser restaurado!\n"
"¡El grupo eliminado NO puede ser restaurado!\n"
"¿Estás TOTALMENTE seguro?"
"¿Estás TOTALMENTE seguro?"
msgid "With plural"
msgid_plural "with plurals"
msgstr[0] "first"
msgstr[1] "second"
msgstr[2] ""
"with"
"multiple"
"lines"
spec/lib/gitlab/po_linter_spec.rb
View file @
1da594d3
...
@@ -26,11 +26,25 @@ describe Gitlab::PoLinter do
...
@@ -26,11 +26,25 @@ describe Gitlab::PoLinter do
context
'for a translations with newlines'
do
context
'for a translations with newlines'
do
let
(
:po_path
)
{
'spec/fixtures/newlines.po'
}
let
(
:po_path
)
{
'spec/fixtures/newlines.po'
}
it
'has an error'
do
it
'has an error
for a normal string
'
do
message_id
=
"You are going to remove %{group_name}.
\\
nRemoved groups CANNOT be restored!
\\
nAre you ABSOLUTELY sure?"
message_id
=
"You are going to remove %{group_name}.
\\
nRemoved groups CANNOT be restored!
\\
nAre you ABSOLUTELY sure?"
expected_message
=
"<
#{
message_id
}
> is defined over multiple lines, this breaks some tooling."
expected_message
=
"<
#{
message_id
}
> is defined over multiple lines, this breaks some tooling."
is_expected
.
to
include
(
message_id
=>
[
expected_message
])
expect
(
errors
[
message_id
]).
to
include
(
expected_message
)
end
it
'has an error when a translation is defined over multiple lines'
do
message_id
=
"You are going to remove %{group_name}.
\\
nRemoved groups CANNOT be restored!
\\
nAre you ABSOLUTELY sure?"
expected_message
=
"<
#{
message_id
}
> has translations defined over multiple lines, this breaks some tooling."
expect
(
errors
[
message_id
]).
to
include
(
expected_message
)
end
it
'raises an error when a plural translation is defined over multiple lines'
do
message_id
=
'With plural'
expected_message
=
"<
#{
message_id
}
> has translations defined over multiple lines, this breaks some tooling."
expect
(
errors
[
message_id
]).
to
include
(
expected_message
)
end
end
end
end
...
...
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