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
Léo-Paul Géneau
gitlab-ce
Commits
2c4f9b7a
Commit
2c4f9b7a
authored
Aug 30, 2017
by
Bob Van Landuyt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Check for newlines in different methods on TranslationEntry
parent
f35a5d0d
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
59 additions
and
2 deletions
+59
-2
lib/gitlab/i18n/po_linter.rb
lib/gitlab/i18n/po_linter.rb
+6
-2
lib/gitlab/i18n/translation_entry.rb
lib/gitlab/i18n/translation_entry.rb
+12
-0
spec/fixtures/newlines.po
spec/fixtures/newlines.po
+7
-0
spec/lib/gitlab/i18n/po_linter_spec.rb
spec/lib/gitlab/i18n/po_linter_spec.rb
+7
-0
spec/lib/gitlab/i18n/translation_entry_spec.rb
spec/lib/gitlab/i18n/translation_entry_spec.rb
+27
-0
No files found.
lib/gitlab/i18n/po_linter.rb
View file @
2c4f9b7a
...
...
@@ -71,11 +71,15 @@ module Gitlab
end
def
validate_newlines
(
errors
,
entry
)
if
entry
.
msgid
.
is_a?
(
Array
)
if
entry
.
msgid
_contains_newlines?
errors
<<
"is defined over multiple lines, this breaks some tooling."
end
if
entry
.
all_translations
.
any?
{
|
translation
|
translation
.
is_a?
(
Array
)
}
if
entry
.
plural_id_contains_newlines?
errors
<<
"plural is defined over multiple lines, this breaks some tooling."
end
if
entry
.
translations_contain_newlines?
errors
<<
"has translations defined over multiple lines, this breaks some tooling."
end
end
...
...
lib/gitlab/i18n/translation_entry.rb
View file @
2c4f9b7a
...
...
@@ -47,6 +47,18 @@ module Gitlab
!
plural?
||
all_translations
.
size
>
1
end
def
msgid_contains_newlines?
msgid
.
is_a?
(
Array
)
end
def
plural_id_contains_newlines?
plural_id
.
is_a?
(
Array
)
end
def
translations_contain_newlines?
all_translations
.
any?
{
|
translation
|
translation
.
is_a?
(
Array
)
}
end
private
def
plural_translation_keys
...
...
spec/fixtures/newlines.po
View file @
2c4f9b7a
...
...
@@ -39,3 +39,10 @@ msgstr[2] ""
"with"
"multiple"
"lines"
msgid "multiline plural id"
msgid_plural ""
"Plural"
"Id"
msgstr[0] "first"
msgstr[1] "second"
spec/lib/gitlab/i18n/po_linter_spec.rb
View file @
2c4f9b7a
...
...
@@ -46,6 +46,13 @@ describe Gitlab::I18n::PoLinter do
expect
(
errors
[
message_id
]).
to
include
(
expected_message
)
end
it
'raises an error when the plural id is defined over multiple lines'
do
message_id
=
'multiline plural id'
expected_message
=
"plural is defined over multiple lines, this breaks some tooling."
expect
(
errors
[
message_id
]).
to
include
(
expected_message
)
end
end
context
'with an invalid po'
do
...
...
spec/lib/gitlab/i18n/translation_entry_spec.rb
View file @
2c4f9b7a
...
...
@@ -103,4 +103,31 @@ describe Gitlab::I18n::TranslationEntry do
expect
(
entry
).
not_to
have_singular
end
end
describe
'#msgid_contains_newlines'
do
it
'is true when the msgid is an array'
do
data
=
{
msgid:
%w(hello world)
}
entry
=
described_class
.
new
(
data
)
expect
(
entry
.
msgid_contains_newlines?
).
to
be_truthy
end
end
describe
'#plural_id_contains_newlines'
do
it
'is true when the msgid is an array'
do
data
=
{
plural_id:
%w(hello world)
}
entry
=
described_class
.
new
(
data
)
expect
(
entry
.
plural_id_contains_newlines?
).
to
be_truthy
end
end
describe
'#translations_contain_newlines'
do
it
'is true when the msgid is an array'
do
data
=
{
msgstr:
%w(hello world)
}
entry
=
described_class
.
new
(
data
)
expect
(
entry
.
translations_contain_newlines?
).
to
be_truthy
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