منتدى استراحات زايد

منتدى استراحات زايد (http://vb.ma7room.com/index.php)
-   منتدى أخبار المواقع والمنتديات العربية والأجنبية (http://vb.ma7room.com/forumdisplay.php?f=183)
-   -   Forum vB_Template->render templates in different languages? (http://vb.ma7room.com/showthread.php?t=356366)

محروم.كوم 03-15-2010 04:10 AM

Forum vB_Template->render templates in different languages?
 
Hi guys,

I am wondering if anyone has figured out how to render a template in a language that differs from the currently session's language preference.

My use case is that I'm writing a mod that that allows users to request permission to a particular resource. Those applications can be reviewed/approved/rejected by an admin. When a user applies for access, an email is sent out to the admins. When the admins approve/reject and application, a PM is sent to the applicant and an email is sent out to the rest of the admins telling them that the request has already been dealt with.

Here's the rub. My board has users and admins from several different countries, each having their own language preferences. Therefore, I have created templates for the emails/PMs with phrases in them. The problem that i'm having is that vB_Template->render() is only concerned with the language preference of the current session and I can't figure out how to get it to render for a different language.

class_core.php: vB_Template->render() is pretty simple; ultimately it just calls 'eval' on the template text which is stored in the vb_template table. Instances of {vb:rawphrase phraseName} in the template are stored, in vb_template as:

PHP Code:
vB_Template_Runtime::parsePhrase("phraseName")

If you have a look at class_core.php: vb_Template_Runtime->parsePhrase reads as follows:

PHP Code:
public static function parsePhrase($phraseName)
{
global
$vbphrase;
$arg_list = func_get_args();
$arg_list[0] = $vbphrase[$phraseName];
return
construct_phrase_from_array($arg_list);
}

Okay, so functions.php: construct_phrase_from_array() is commented as the following:

Code:
/**
* Construct Phrase from Array
*
* this function is actually just a wrapper for sprintf but makes identification of phrase code easier
* and will not error if there are no additional arguments. The first element of the array is the phrase text, and
* the (unlimited number of) following elements are the variables to be parsed into that phrase.
[snip]
Cool, so construct_phrase_from_array is nothing but a wrapper for sprintf (and it accepts parameters for phrases) but the key here lies in parsePhrase where it takes the phrase text from $vbphrase. This variable only stores the phrases for the current language preference meaning that when I call vB_Template->render(), the template (and phrases in the templates) will be rendered in a single language.

That's not what I want. I want the PM to be sent to the applicant in their own language and I want to send the email out to each admin in their own language.

From what I can see, this isn't currently possible.

Note: There are three workarounds here:
  1. Don't use templates and build the PMs/emails in code, but I don't like that because then the messages won't be configurable
  2. Come up with some proprietary way of parsing the templates (ie - don't use vb's {} syntax so that the template is stored as straight text, allowing me to parse it myself)
  3. Scan my message templates for instances of ::parsePhrase and modify $vbphrase manually to hold the text from the language that I want to render, then call vB_Template->render(), then restore $vbphrase to it's original state.
Either way, all three of these are dirty hacks.

Has anyone found a way around this? Am I missing something [non-]obvious?

Cheers,
Dave.


الساعة الآن 08:34 PM

Powered by vBulletin® Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.5.2 TranZ By Almuhajir


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227