Skip to content

Commit 9cae035

Browse files
authored
pluralize: avoid double pluralization
2 parents ad76172 + eea5199 commit 9cae035

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

Text/Countable.hs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ data Inflection
4949
pluralize :: Text -> Text
5050
pluralize = pluralizeWith mapping
5151
where
52-
mapping = defaultIrregulars ++ defaultUncountables ++ defaultPlurals
52+
mapping = defaultUncountables ++ defaultPlurals ++ irregularPluralsAsUncountables ++ defaultIrregulars
5353

5454
-- | singularize a word given a default mapping
5555
singularize :: Text -> Text
@@ -149,3 +149,8 @@ regexPattern pat = toMaybe reg
149149
headMaybe :: [a] -> Maybe a
150150
headMaybe [] = Nothing
151151
headMaybe (x:_) = Just x
152+
153+
-- Treat irregular plurals as uncountables to avoid double pluralization
154+
irregularPluralsAsUncountables :: [Inflection]
155+
irregularPluralsAsUncountables =
156+
makeUncountableMapping (map snd defaultIrregulars')

test/Text/CountableSpec.hs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ matchingCases = do
4646
pluralize "ox" `shouldBe` "oxen"
4747
pluralize "vertex" `shouldBe` "vertices"
4848

49+
it "can doesn't pluralize plurals a second time" $
50+
pluralize "people" `shouldBe` "people"
51+
4952
describe "singularize" $ do
5053
it "singularizes regex cases" $ do
5154
singularize "mice" `shouldBe` "mouse"
@@ -59,4 +62,4 @@ matchingCases = do
5962
irregularCases :: Spec
6063
irregularCases =
6164
it "can singularize irregulars" $
62-
singularize "people" `shouldBe` "person"
65+
singularize "people" `shouldBe` "person"

0 commit comments

Comments
 (0)