The pluralize
Ballerina Connector is designed to assist with the pluralization and singularization of English words. This can be particularly useful when generating dynamic strings based on numerical values.
This module utilizes a predefined list of rules, applied sequentially, to singularize or pluralize a given word. This can be beneficial in many scenarios, such as automating tasks based on user input. For applications where the words are known in advance, a simple ternary (or function) can be used as a lighter alternative.
This module is a migration of the pluralize
library by Blake Embrey
. All credit goes to him.
To use the pluralize
connector in your Ballerina application, modify the .bal
file as follows:
Import the pluralize
module.
import niveathika/pluralize;
Now, utilize the available connector operations.
pluralize:pluralize('test'); //=> "tests"
pluralize:pluralize('test', 0); //=> "tests"
pluralize:pluralize('test', 1); //=> "test"
pluralize:pluralize('test', 5); //=> "tests"
pluralize:pluralize('test', 1, true); //=> "1 test"
pluralize:pluralize('test', 5, true); //=> "5 tests"
pluralize:pluralize('蘋果', 2, true); //=> "2 蘋果"
pluralize:isPlural("test"); // false
pluralize:isPlural("tests"); // true
bal run
-
Download and install Java SE Development Kit (JDK) version 17. You can download it from either of the following sources:
Note: After installation, remember to set the
JAVA_HOME
environment variable to the directory where JDK was installed. -
Download and install Ballerina Swan Lake.
-
Download and install Docker.
Note: Ensure that the Docker daemon is running before executing any tests.
Execute the commands below to build from the source.
-
To build the package:
./gradlew clean build
-
To run the tests:
./gradlew clean test
-
To build the without the tests:
./gradlew clean build -x test
-
To debug package with a remote debugger:
./gradlew clean build -Pdebug=<port>
-
Publish the generated artifacts to the local Ballerina Central repository:
./gradlew clean build -PpublishToLocalCentral=true
-
Publish the generated artifacts to the Ballerina Central repository:
./gradlew clean build -PpublishToCentral=true