<?php use Lead\Inflector\Inflector; Inflector::singular('/s$/i', '', 'es'); Inflector::plural('/$/i', 's', 'es'); Inflector::singular('/es$/i', '', 'es'); Inflector::plural('/([^aeéiou])$/i', '\\1es', 'es'); Inflector::singular('/ces$/i', 'z', 'es'); Inflector::plural('/z$/i', 'ces', 'es'); Inflector::singular('/iones$/i', 'ión', 'es'); Inflector::plural('/ión$/i', 'iones', 'es'); Inflector::irregular('carácter', 'caracteres', 'es'); /** * Warning, using an "exhastive" list of rules will slow * down all singularizations/pluralizations generation. * So it's preferable to only add the ones you are actually using. */
<?php use Lead\Inflector\Inflector; Inflector::singular('/s$/i', '', 'fr'); Inflector::plural('/([^s])$/i', '\\1s', 'fr'); Inflector::plural('/(eu|eau)$/i', '\\1x', 'fr'); Inflector::singular('/(eu|eau)x$/i', '\\1', 'fr'); Inflector::plural('/(x|z)$/i', '\\1', 'fr'); Inflector::irregular('monsieur', 'messieurs', 'fr'); Inflector::irregular('madame', 'mesdames', 'fr'); Inflector::irregular('mademoiselle', 'mesdemoiselles', 'fr'); /** * Warning, using an "exhastive" list of rules will slow * down all singularizations/pluralizations generation. * So it's preferable to only add the ones you are actually using. */
it("reset the inflector rules", function () { Inflector::reset(); expect(Inflector::singularize('posts'))->toBe('post'); expect(Inflector::pluralize('post'))->toBe('posts'); }); it("clears all the inflector rules", function () { Inflector::reset(true); expect(Inflector::singularize('posts'))->toBe('posts'); expect(Inflector::pluralize('post'))->toBe('post'); }); }); context("using a custom language", function () { describe("::singularize/pluralize()", function () { it("can manages several languages", function () { Inflector::reset(); require 'spec/Fixture/fr.php'; require 'spec/Fixture/es.php'; expect(Inflector::singularize('taxes'))->toBe('tax'); expect(Inflector::pluralize('tax'))->toBe('taxes'); expect(Inflector::singularize('bateaux', 'fr'))->toBe('bateau'); expect(Inflector::pluralize('bateau', 'fr'))->toBe('bateaux'); expect(Inflector::singularize('ediciones', 'es'))->toBe('edición'); expect(Inflector::pluralize('edición', 'es'))->toBe('ediciones'); Inflector::singular('/x$/i', '', 'zz'); Inflector::plural('/([^x])$/i', '\\1x', 'zz'); expect(Inflector::singularize('abcdefx', 'zz'))->toBe('abcdef'); expect(Inflector::pluralize('abcdef', 'zz'))->toBe('abcdefx'); }); }); }); });