1 # TWiki Enterprise Collaboration Platform, http://TWiki.org/
3 # Copyright (C) 1999-2007 TWiki Contributors. All Rights Reserved.
4 # TWiki Contributors are listed in the AUTHORS file in the root of
6 # NOTE: Please extend that file, not this notice.
8 # Additional copyrights apply to some or all of the code in this
10 # Copyright (C) 2005 Martin Cleaver.
12 # This program is free software; you can redistribute it and/or
13 # modify it under the terms of the GNU General Public License
14 # as published by the Free Software Foundation; either version 2
15 # of the License, or (at your option) any later version. For
16 # more details read LICENSE in the root of this distribution.
18 # This program is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
22 # As per the GPL, removal of this notice is prohibited.
26 ---+ package TWiki::Plurals
28 Handle conversion of plural topic names to singular form.
32 package TWiki::Plurals;
38 ---++ StaticMethod singularForm($web, $pluralForm) -> $singularForm
40 Try to singularise plural topic name.
41 * =$web= - the web the topic must be in
42 * =$pluralForm= - topic name
43 Returns undef if no singular form exists, otherwise returns the
44 singular form of the topic
46 I18N - Only apply plural processing if site language is English, or
47 if a built-in English-language web (Main, TWiki or Plugins). Plurals
48 apply to names ending in 's', where topic doesn't exist with plural
51 Note that this is highly langauge specific, and need to be enabled
52 on a per-installation basis with $TWiki::cfg{PluralToSingular}.
57 my( $web, $pluralForm ) = @_;
60 # Plural processing only if enabled in configure or one of the
62 return undef unless( $TWiki::cfg{PluralToSingular} or
63 $web eq $TWiki::cfg{UsersWebName} or
64 $web eq $TWiki::cfg{SystemWebName} );
65 return undef unless( $pluralForm =~ /s$/ );
67 # Topic name is plural in form
68 my $singularForm = $pluralForm;
69 $singularForm =~ s/ies$/y/; # plurals like policy / policies
70 $singularForm =~ s/sses$/ss/; # plurals like address / addresses
71 $singularForm =~ s/ches$/ch/; # plurals like search / searches
72 $singularForm =~ s/(oes|os)$/o/; # plurals like veto / vetoes
73 $singularForm =~ s/([Xx])es$/$1/;# plurals like box / boxes
74 $singularForm =~ s/([^s])s$/$1/; # others, excluding ss like address(es)