Difference between revisions of "Template:Plural"

From RimWorld Wiki
Jump to navigation Jump to search
(added "s" detection and start of list of common uncountable nouns)
Line 1: Line 1:
<includeonly>{{plural:{{#expr: {{{1|}}} }}|{{#expr: {{{1|}}} }}&nbsp;{{{2|}}}|{{#expr: {{{1|}}} }}&nbsp;{{{2|}}}s}}</includeonly><noinclude>{{recode|reason=Add "s" detection for automated use - [[potatoes]] not potatoess}}{{Documentation}}</noinclude>
+
<includeonly>{{#expr: {{{1|}}} }}&nbsp;{{{2|}}}{{plural: {{#expr: {{{1|}}} }}
 +
  || {{#ifeq: {{#sub: {{{2|}}} | -1}} | s
 +
    || {{#switch: {{lc: {{{2|}}} }}
 +
     | chemfuel | cloth | steel = <!-- Add nouns to this list that are usually used as uncountable nouns on this wiki. -->
 +
      | #default = s
 +
}} }} }}</includeonly><noinclude>{{Documentation}}</noinclude>

Revision as of 10:27, 28 October 2022

Documentation icon Template documentation[view] [edit] [history] [purge]

Usage

This template can be used to properly localise units.

The template has two parameters:

{{Plural|"value"|"text"|link=}}

  • The first parameter can be any value, usually in form of an expression. This parameter is optional. When it i omitted the template just return the plural form of the second parameter.
  • The second parameter can be any text including links and templates. It should end with the unit of the value as this template simply adds an "s" at the end of the text, if the value isn't 1.
  • The link= parameter can be set to any value, if the second parameter should be turned into a link.

Examples

{{Plural|1|component}} produces: 1 component

{{Plural|2|component}} produces: 2 components

{{Plural|1/3 round 2|component}} produces: 0.33 components

{{Plural|2|component|link=true}} produces: 2 components

{{Plural||component}} produces:  components

Special cases (evalueated in this order)

Uncountable things

{{Plural|2|gold}} produces: 2 golds (there is a hardcoded list of uncountable things)

Depending on last two letters

{{Plural|2|day}} produces: 2 days (everything ending in "-ay")

{{Plural|2|sash}} produces: 2 sashs (everything ending in "-ch", "-sh" or "-ss")

{{Plural|2|knife}} produces: 2 knifes (everything ending in "-fe")

{{Plural|2|gladius}} produces: 2 gladius (everything ending in "-us")

Depending on last letter

{{Plural|2|shelf}} produces: 2 shelfs (everything ending in "-f")

{{Plural|2|molotov cocktails}} produces: 2 molotov cocktails (everything ending in "-s")

{{Plural|2|toy box}} produces: 2 toy boxs (everything ending in "-x")

{{Plural|2|battery}} produces: 2 batterys (everything ending in "-y")

{{Plural|2|table (1x2)}} produces: 2 table (1x2)s (everything ending in "-)")