english: new word count-of-things, it pluralizes depending on count
parent
52c5d2b0a4
commit
a974e752ab
|
@ -10,3 +10,7 @@ IN: english
|
||||||
|
|
||||||
{ "a10n" } [ "abbreviation" a10n ] unit-test
|
{ "a10n" } [ "abbreviation" a10n ] unit-test
|
||||||
{ "i18n" } [ "internationalization" 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
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
! Copyright (C) 2015 John Benediktsson
|
! Copyright (C) 2015 John Benediktsson
|
||||||
! See http://factorcode.org/license.txt for BSD license
|
! See http://factorcode.org/license.txt for BSD license
|
||||||
|
USING: assocs assocs.extras combinators formatting kernel literals
|
||||||
USING: assocs assocs.extras combinators kernel literals locals
|
locals math math.parser sequences splitting unicode.case ;
|
||||||
math math.parser sequences splitting unicode.case
|
|
||||||
unicode.categories ;
|
|
||||||
|
|
||||||
IN: english
|
IN: english
|
||||||
|
|
||||||
|
@ -143,6 +141,9 @@ PRIVATE>
|
||||||
[ "s" append ]
|
[ "s" append ]
|
||||||
} cond match-case ;
|
} cond match-case ;
|
||||||
|
|
||||||
|
: count-of-things ( count word -- str )
|
||||||
|
over 1 = [ pluralize ] unless "%d %s" sprintf ;
|
||||||
|
|
||||||
: a10n ( str -- str' )
|
: a10n ( str -- str' )
|
||||||
dup length 3 > [
|
dup length 3 > [
|
||||||
[ 1 head ] [ length 2 - number>string ] [ 1 tail* ] tri
|
[ 1 head ] [ length 2 - number>string ] [ 1 tail* ] tri
|
||||||
|
|
Loading…
Reference in New Issue