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
97041bb6
Commit
97041bb6
authored
Feb 05, 2019
by
Phil Hughes
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'fe-grammar-util' into 'master'
FE grammar util See merge request gitlab-org/gitlab-ce!24893
parents
068b4127
9cfb253e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
84 additions
and
0 deletions
+84
-0
app/assets/javascripts/lib/utils/grammar.js
app/assets/javascripts/lib/utils/grammar.js
+40
-0
locale/gitlab.pot
locale/gitlab.pot
+9
-0
spec/javascripts/lib/utils/grammar_spec.js
spec/javascripts/lib/utils/grammar_spec.js
+35
-0
No files found.
app/assets/javascripts/lib/utils/grammar.js
0 → 100644
View file @
97041bb6
import
{
sprintf
,
s__
}
from
'
~/locale
'
;
/**
* Combines each given item into a noun series sentence fragment. It does this
* in a way that supports i18n by giving context and punctuation to the locale
* functions.
*
* **Examples:**
*
* - `["A", "B"] => "A and B"`
* - `["A", "B", "C"] => "A, B, and C"`
*
* **Why only nouns?**
*
* Some languages need a bit more context to translate other series.
*
* @param {String[]} items
*/
export
const
toNounSeriesText
=
items
=>
{
if
(
items
.
length
===
0
)
{
return
''
;
}
else
if
(
items
.
length
===
1
)
{
return
items
[
0
];
}
else
if
(
items
.
length
===
2
)
{
return
sprintf
(
s__
(
'
nounSeries|%{firstItem} and %{lastItem}
'
),
{
firstItem
:
items
[
0
],
lastItem
:
items
[
1
],
});
}
return
items
.
reduce
((
item
,
nextItem
,
idx
)
=>
idx
===
items
.
length
-
1
?
sprintf
(
s__
(
'
nounSeries|%{item}, and %{lastItem}
'
),
{
item
,
lastItem
:
nextItem
})
:
sprintf
(
s__
(
'
nounSeries|%{item}, %{nextItem}
'
),
{
item
,
nextItem
}),
);
};
export
default
{
toNounSeriesText
,
};
locale/gitlab.pot
View file @
97041bb6
...
@@ -8712,6 +8712,15 @@ msgstr ""
...
@@ -8712,6 +8712,15 @@ msgstr ""
msgid "notification emails"
msgid "notification emails"
msgstr ""
msgstr ""
msgid "nounSeries|%{firstItem} and %{lastItem}"
msgstr ""
msgid "nounSeries|%{item}, %{nextItem}"
msgstr ""
msgid "nounSeries|%{item}, and %{lastItem}"
msgstr ""
msgid "or"
msgid "or"
msgstr ""
msgstr ""
...
...
spec/javascripts/lib/utils/grammar_spec.js
0 → 100644
View file @
97041bb6
import
*
as
grammar
from
'
~/lib/utils/grammar
'
;
describe
(
'
utils/grammar
'
,
()
=>
{
describe
(
'
toNounSeriesText
'
,
()
=>
{
it
(
'
with empty items returns empty string
'
,
()
=>
{
expect
(
grammar
.
toNounSeriesText
([])).
toBe
(
''
);
});
it
(
'
with single item returns item
'
,
()
=>
{
const
items
=
[
'
Lorem Ipsum
'
];
expect
(
grammar
.
toNounSeriesText
(
items
)).
toBe
(
items
[
0
]);
});
it
(
'
with 2 items returns item1 and item2
'
,
()
=>
{
const
items
=
[
'
Dolar
'
,
'
Sit Amit
'
];
expect
(
grammar
.
toNounSeriesText
(
items
)).
toBe
(
`
${
items
[
0
]}
and
${
items
[
1
]}
`
);
});
it
(
'
with 3 items returns comma separated series
'
,
()
=>
{
const
items
=
[
'
Lorem
'
,
'
Ipsum
'
,
'
dolar
'
];
const
expected
=
'
Lorem, Ipsum, and dolar
'
;
expect
(
grammar
.
toNounSeriesText
(
items
)).
toBe
(
expected
);
});
it
(
'
with 6 items returns comma separated series
'
,
()
=>
{
const
items
=
[
'
Lorem
'
,
'
ipsum
'
,
'
dolar
'
,
'
sit
'
,
'
amit
'
,
'
consectetur
'
];
const
expected
=
'
Lorem, ipsum, dolar, sit, amit, and consectetur
'
;
expect
(
grammar
.
toNounSeriesText
(
items
)).
toBe
(
expected
);
});
});
});
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