| 1 |
<?php
|
| 2 |
// $Id:$
|
| 3 |
|
| 4 |
/**
|
| 5 |
* rpg.t.inc
|
| 6 |
* this file defines the rpg_t function, which provides for substitution strings for messages displayed to players.
|
| 7 |
*/
|
| 8 |
|
| 9 |
function rpg_t($message, $objects = array(), $translations = array()) {
|
| 10 |
global $rpg;
|
| 11 |
|
| 12 |
// default $pc is $rpg['pc']
|
| 13 |
if (!isset($objects['pc'])) {
|
| 14 |
$objects['pc'] = rpg_object($rpg['pc']);
|
| 15 |
}
|
| 16 |
else {
|
| 17 |
$objects['pc'] = rpg_object($objects['pc']);
|
| 18 |
}
|
| 19 |
|
| 20 |
// default $room is pc's room
|
| 21 |
if (!isset($objects['room']) && is_object($objects['pc'])) {
|
| 22 |
$objects['room'] = rpg_object($objects['pc']->location);
|
| 23 |
}
|
| 24 |
else if (isset($objects['room'])) {
|
| 25 |
$objects['room'] = rpg_object($objects['room']);
|
| 26 |
}
|
| 27 |
|
| 28 |
// default $observer is the pc
|
| 29 |
// this affects things like 'you' and verb tense
|
| 30 |
// this will ultimately be called for all potentially human observers of an event
|
| 31 |
if (!isset($objects['observer']) && is_object($objects['pc'])) {
|
| 32 |
$objects['observer'] = $objects['pc'];
|
| 33 |
}
|
| 34 |
else if (isset($objects['observer'])) {
|
| 35 |
$objects['observer'] = rpg_object($objects['observer']);
|
| 36 |
}
|
| 37 |
|
| 38 |
if (is_object($objects['pc'])) {
|
| 39 |
$pc = $objects['pc'];
|
| 40 |
if ($pc == $objects['observer']) {
|
| 41 |
$translations = array_merge($translations, array(
|
| 42 |
'!you' => l(t('you'), 'rpg/view/' . $pc->rid),
|
| 43 |
'!You' => l(t('You'), 'rpg/view/' . $pc->rid),
|
| 44 |
'!your' => l(t('your'), 'rpg/view/' . $pc->rid),
|
| 45 |
'!Your' => l(t('Your'), 'rpg/view/' . $pc->rid),
|
| 46 |
'!yours' => l(t('yours'), 'rpg/view/' . $pc->rid),
|
| 47 |
'!Yours' => l(t('Yours'), 'rpg/view/' . $pc->rid),
|
| 48 |
'!is' => t('are'),
|
| 49 |
'!are' => t('are'),
|
| 50 |
'!Is' => t('Are'),
|
| 51 |
'!Are' => t('Are'),
|
| 52 |
'!s' => '',
|
| 53 |
));
|
| 54 |
} else {
|
| 55 |
$translations = array_merge($translations, array(
|
| 56 |
'!you' => l($pc->name, 'rpg/view/' . $pc->rid),
|
| 57 |
'!You' => l($pc->name, 'rpg/view/' . $pc->rid),
|
| 58 |
'!your' => l($pc->name . '\'s', 'rpg/view/' . $pc->rid),
|
| 59 |
'!Your' => l($pc->name . '\'s', 'rpg/view/' . $pc->rid),
|
| 60 |
'!yours' => l($pc->name . '\'s', 'rpg/view/' . $pc->rid),
|
| 61 |
'!Yours' => l($pc->name . '\'s', 'rpg/view/' . $pc->rid),
|
| 62 |
'!is' => t('is'),
|
| 63 |
'!are' => t('is'),
|
| 64 |
'!Is' => t('Is'),
|
| 65 |
'!Are' => t('Is'),
|
| 66 |
'!s' => 's',
|
| 67 |
));
|
| 68 |
}
|
| 69 |
// pronouns -- TODO: assign to genders & link
|
| 70 |
$translations = array_merge($translations, array(
|
| 71 |
'!he' => t('it'), // he/she/it plays
|
| 72 |
'!she' => t('it'), // he/she/it plays
|
| 73 |
'!him' => t('it'), // give the ball to him/her/it
|
| 74 |
'!her' => t('it'), // give the ball to him/her/it
|
| 75 |
'!his' => t('its'), // that is his/her/its ball
|
| 76 |
'!hers' => t('its'), // that ball is his/hers/its
|
| 77 |
'!himself' => t('itself'), // he looks at himself/herself/itself
|
| 78 |
'!herself' => t('itself'), // he looks at himself/herself/itself
|
| 79 |
'!He' => t('It'),
|
| 80 |
'!She' => t('It'),
|
| 81 |
'!Her' => t('It'),
|
| 82 |
'!His' => t('Its'),
|
| 83 |
'!Hers' => t('Its'),
|
| 84 |
'!Himself' => t('Itself'),
|
| 85 |
'!Herself' => t('Itself'),
|
| 86 |
));
|
| 87 |
}
|
| 88 |
if (is_object($objects['obj'])) {
|
| 89 |
$obj = $objects['obj'];
|
| 90 |
$translations = array_merge($translations, array(
|
| 91 |
'!obj' => l($obj->name, 'rpg/view/' . $obj->rid),
|
| 92 |
'!Obj' => l(ucfirst($obj->name), 'rpg/view/' . $obj->rid),
|
| 93 |
'!theobj' => rpg_t_thename($obj),
|
| 94 |
'!Theobj' => ucfirst(rpg_t_thename($obj)),
|
| 95 |
));
|
| 96 |
}
|
| 97 |
if (is_object($objects['dobj'])) {
|
| 98 |
$dobj = $objects['dobj'];
|
| 99 |
$translations = array_merge($translations, array(
|
| 100 |
'!dobj' => l($dobj->name, 'rpg/view/' . $dobj->rid),
|
| 101 |
'!Dobj' => l(ucfirst($dobj->name), 'rpg/view/' . $dobj->rid),
|
| 102 |
'!thedobj' => rpg_t_thename($dobj),
|
| 103 |
'!Thedobj' => ucfirst(rpg_t_thename($dobj)),
|
| 104 |
));
|
| 105 |
}
|
| 106 |
if (is_object($objects['room'])) {
|
| 107 |
$room = $objects['room'];
|
| 108 |
$translations = array_merge($translations, array(
|
| 109 |
'!theroom' => rpg_t_thename($room),
|
| 110 |
'!Theroom' => ucfirst(rpg_t_thename($room)),
|
| 111 |
));
|
| 112 |
}
|
| 113 |
return t($message, $translations);
|
| 114 |
}
|
| 115 |
|
| 116 |
function rpg_t_thename($object) {
|
| 117 |
$object = rpg_object($object);
|
| 118 |
if (rpg_get('proper', $object)) {
|
| 119 |
return l(rpg_get('name', $object), 'rpg/view/' . $object->rid);
|
| 120 |
}
|
| 121 |
return t('the !object', array('!object' => l(rpg_get('name', $object), 'rpg/view/' . $object->rid)));
|
| 122 |
}
|
| 123 |
|