english: new word count-of-things, it pluralizes depending on count

locals-and-roots
Björn Lindqvist 2016-03-25 14:08:14 +01:00
parent 52c5d2b0a4
commit a974e752ab
2 changed files with 9 additions and 4 deletions

View File

@ -10,3 +10,7 @@ IN: english
{ "a10n" } [ "abbreviation" a10n ] unit-test
{ "i18n" } [ "internationalization" a10n ] unit-test
{ "3 babies" } [ 3 "baby" count-of-things ] unit-test
{ "1 pipe" } [ 1 "pipe" count-of-things ] unit-test
{ "0 pipes" } [ 0 "pipe" count-of-things ] unit-test

View File

@ -1,9 +1,7 @@
! Copyright (C) 2015 John Benediktsson
! See http://factorcode.org/license.txt for BSD license
USING: assocs assocs.extras combinators kernel literals locals
math math.parser sequences splitting unicode.case
unicode.categories ;
USING: assocs assocs.extras combinators formatting kernel literals
locals math math.parser sequences splitting unicode.case ;
IN: english
@ -143,6 +141,9 @@ PRIVATE>
[ "s" append ]
} cond match-case ;
: count-of-things ( count word -- str )
over 1 = [ pluralize ] unless "%d %s" sprintf ;
: a10n ( str -- str' )
dup length 3 > [
[ 1 head ] [ length 2 - number>string ] [ 1 tail* ] tri