Converts words between their singular and plural forms. The rules of a language are declared inside of a Flow.Inflector:inflections block as pattern replacements, irregular words and uncountable words; the English rules ship with Flux. Flow.Inflector:pluralize and Flow.Inflector:singularize apply the rules of the current language to the last part of a snake_case word. ActiveRecord uses them to derive the names of database tables from the names of models, turning 'user' into 'users', and the names of foreign keys from the names of tables.

Summary

Methods

Defines the inflection rules of a language.
Adds a word that does not follow the regular rules to the current language.
Returns the irregular words of the current language.
Returns the irregular words of the current language, the other way around.
Adds a pluralization rule to the current language.
Converts a word to its plural form using the rules of the current language.
plurals()shared
Returns the pluralization rules of the current language.
Adds a singularization rule to the current language.
Converts a word to its singular form using the rules of the current language.
Returns the singularization rules of the current language.
Adds words that have no separate plural form to the current language.
Returns the uncountable words of the current language.

Methods

Flow.Inflector:inflections(lang, func)

shared packages/flow/lib/inflector/sh_inflector.lua:30

Defines the inflection rules of a language. The rules added inside of the callback (and anything looked up afterward) belong to that language.

Flow.Inflector:inflections('en', function(inflect)
  inflect:plural(i'^(ox)$', '%1en')
  inflect:singular(i'(quiz)zes$', '%1')
  inflect:irregular('person', 'people')
  inflect:uncountable(w'data ammo equipment')
end)

Parameters

  • lang String language code
  • func Function receives the inflector

Returns

  • Flow::Inflector self, for chaining

Flow.Inflector:irregular(word, replacement)

shared packages/flow/lib/inflector/sh_inflector.lua:109

Adds a word that does not follow the regular rules to the current language.

Parameters

  • word String singular form
  • replacement String plural form

Returns

  • Flow::Inflector self, for chaining

Flow.Inflector:irregulars()

shared packages/flow/lib/inflector/sh_inflector.lua:65

Returns the irregular words of the current language.

Returns

  • Map plural forms by singular form

Flow.Inflector:irregulars_reverse()

shared packages/flow/lib/inflector/sh_inflector.lua:71

Returns the irregular words of the current language, the other way around.

Returns

  • Map singular forms by plural form

Flow.Inflector:plural(expression, replacement)

shared packages/flow/lib/inflector/sh_inflector.lua:79

Adds a pluralization rule to the current language.

Parameters

  • expression String Lua pattern that the singular form must match
  • replacement String what to replace the match with, can refer to captures

Returns

  • Flow::Inflector self, for chaining

Flow.Inflector:pluralize(word)

shared packages/flow/lib/inflector/sh_inflector.lua:157

Converts a word to its plural form using the rules of the current language. Only the last part of a snake_case word is converted.

Parameters

  • word String

Returns

  • String plural form

Flow.Inflector:plurals()

shared packages/flow/lib/inflector/sh_inflector.lua:47

Returns the pluralization rules of the current language.

Returns

  • List<Map> rules with the expression and replacement keys

Flow.Inflector:singular(expression, replacement)

shared packages/flow/lib/inflector/sh_inflector.lua:94

Adds a singularization rule to the current language.

Parameters

  • expression String Lua pattern that the plural form must match
  • replacement String what to replace the match with, can refer to captures

Returns

  • Flow::Inflector self, for chaining

Flow.Inflector:singularize(word)

shared packages/flow/lib/inflector/sh_inflector.lua:165

Converts a word to its singular form using the rules of the current language. Only the last part of a snake_case word is converted.

Parameters

  • word String

Returns

  • String singular form

Flow.Inflector:singulars()

shared packages/flow/lib/inflector/sh_inflector.lua:53

Returns the singularization rules of the current language.

Returns

  • List<Map> rules with the expression and replacement keys

Flow.Inflector:uncountable(words)

shared packages/flow/lib/inflector/sh_inflector.lua:119

Adds words that have no separate plural form to the current language.

Parameters

  • words String/List<String> a word or a list of words

Returns

  • Flow::Inflector self, for chaining

Flow.Inflector:uncountables()

shared packages/flow/lib/inflector/sh_inflector.lua:59

Returns the uncountable words of the current language.

Returns

  • Map true by word

Defined in