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