Difference between revisions of "Template:Plural"

From RimWorld Wiki
Jump to navigation Jump to search
(general case for all strings with brackets. Cut off part in brackets -> evaluate plural -> re-add part in brackets)
 
(5 intermediate revisions by one other user not shown)
Line 1: Line 1:
<includeonly>{{#if: {{{1|}}} | {{#expr: {{{1|}}} }}&nbsp;}}{{#vardefine:string|{{#if:{{{link|}}}|[[{{{2|}}}]]|{{{2|}}} }} }}{{plural: {{#expr: {{{1|}}} }} | {{#var:string}} |
+
<includeonly>{{#if: {{{1|}}} | {{#expr: {{{1|}}} }}&nbsp;}}<!-- Prints the first parameter as a number.
   {{#switch: {{lc: {{{2}}} }} | Totemic slab (broad) = Totemic slabs (broad) | alpaca wool | bioferrite | bison wool | cataphract armor | chemfuel | cloth | devilstrand | dog leather | elephant leather | flake | grenadier armor | go-juice | gold | human leather | hyperweave | jade | kid tribalwear | lightleather | locust armor | marine armor | mechlord armor | megasloth wool | muffalo wool | neutroamine | patchleather | phoenix armor | plainleather | plasteel | plate armor | prestige recon armor | prestige marine armor | prestige cataphract armor | recon armor | rhinoceros leather | sheep wool | steel | stuff | synthread | tribal wear | twisted meat | uranium | wake-up | wood | yayo = {{#var:string}}<!-- Add nouns to this alphabetical ordered list that are usually used as uncountable nouns on this wiki. --> | #default =
+
-->{{#vardefine: singular | {{#sub: {{{2|}}} | 0 | {{#pos: {{{2|}}} | (}} }} }}<!-- Splits of the part in brackets, if any.
     {{#switch: {{#sub: {{{2|}}} | -2}} | ay = {{{2|}}}s | ch | sh | ss = {{#var:string}}es | fe = {{#sub: {{{2|}}} | 0 | -2}}ves | us = {{#sub: {{{2|}}} | 0 | -2}}i | #default =
+
-->{{#vardefine: plural |
       {{#switch: {{#sub: {{{2|}}} | -1}} | f = {{#sub: {{{2|}}} | 0 | -1}}ves | s = {{#var:string}} | x = {{#var:string}}es | y = {{#sub: {{{2|}}} | 0 | -1}}ies | ) = {{#sub: {{{2|}}} | 0 | -6}}s{{#sub: {{{2|}}} | -6}} | #default ={{#var:string}}s
+
{{plural: {{#expr: {{{1|}}} }} | {{#var:singular}} |
}} }} }} }}</includeonly><noinclude>{{Documentation}}</noinclude>
+
   {{#switch: {{lc: {{#var:singular}} }} | alpaca wool | bioferrite | bison wool | cataphract armor | chemfuel | cloth | devilstrand | dog leather | elephant leather | flake | grenadier armor | go-juice | gold | human leather | human meat | hyperweave | insect meat | jade | kid tribalwear | lightleather | locust armor | marine armor | mechlord armor | megasloth wool | muffalo wool | neutroamine | patchleather | phoenix armor | plainleather | plasteel | plate armor | prestige recon armor | prestige marine armor | prestige cataphract armor | recon armor | rhinoceros leather | sheep wool | steel | stuff | synthread | tribal wear | twisted meat | uranium | wake-up | wood | yayo = {{#var:singular}}<!-- Add nouns to this alphabetical ordered list that are usually used as uncountable nouns on this wiki. --> | #default =
 +
     {{#switch: {{#sub: {{#var:singular}} | -2}} | ay = {{#var:singular}}s | ch | sh | ss = {{#var:singular}}es | fe = {{#sub: {{#var:singular}} | 0 | -2}}ves | us = {{#sub: {{#var:singular}} | 0 | -2}}i | #default =
 +
       {{#switch: {{#sub: {{#var:singular}} | -1}} | f = {{#sub: {{#var:singular}} | 0 | -1}}ves | s = {{#var:singular}} | x = {{#var:singular}}es | y = {{#sub: {{#var:singular}} | 0 | -1}}ies | #default = {{#var:singular}}s
 +
}} }} }} }}<!-- Defines the proper plural.
 +
-->{{#if: {{#pos: {{{2|}}} | (}} | <nowiki/> <nowiki/>{{#sub: {{{2|}}} | {{#pos: {{{2|}}} | (}} }} }} }}<!-- Re-adds the part in brackets, if any.
 +
-->{{#if:{{{link|}}}|[[{{{2|}}}|{{#var:plural}}]]|{{#var:plural}} }}<!-- Prints the plural of the second parameter. Optionally as a link.
 +
--></includeonly><noinclude>{{Documentation}}</noinclude>

Latest revision as of 15:33, 18 October 2024

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

Usage[edit]

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[edit]

{{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:components

{{Plural||component}} produces: components

Special cases (evaluated in this order)[edit]

Bracket names[edit]

{{Plural|2|Animalist slab (broad)}} produces: 2 Animalist slabs (broad) (the plural is defined by the last word before the first "(" in the string)

Uncountable things[edit]

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

Depending on last two letters[edit]

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

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

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

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

Depending on last letter[edit]

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

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

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

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