HTML Logo by World Wide Web Consortium (www.w3.org). Click to learn more about our commitment to accessibility and standards.

Moving forward with Composr

ocPortal has been relaunched as Composr CMS, which is now in beta. ocPortal 9 will be superseded by Composr 10.

Head over to compo.sr for our new site, and to our migration roadmap. Existing ocPortal member accounts have been mirrored.


Translating language file srings with comcode in them

Login / Search

 [ Join | More ]
 Add topic 
Posted
Rating:
#96309 (In Topic #19130)
Avatar

Community saint

How do I?

Ok so I have this line in a template:

Code

<strong>{$NUMBER_FORMAT*,{NUM_CREDITS}}</strong> credits currently cost {$COMCODE,[currency="{S_CURRENCY}" bracket="1"]{PRICE}[/currency]} &dagger;&dagger; and are good for:

I wanted to conver to lang string so added this to lang file:

Code

BLOCK_CREDITS_EXP_INNER_MSG=[b]{1}[/] credits currently cost [currency="{2}" bracket="1"]{3}[/currency] &dagger;&dagger; and are good for:

And this is the line to call it from my block file:

Code

$msg = do_lang_tempcode('BLOCK_CREDITS_EXP_INNER_MSG',strval($num_credits),strval($s_currency),float_format($v[1]));

Obviously I am doing something wrong. Could someone tell me what it is?
Back to the top
 
Posted
Rating:
#96313
Avatar

Language strings do not support Comcode or Tempcode (mainly for performance reasons), you need to pass data into them in a prepared state.

The only exception is the DOC_* strings, which are specially cached.

It is very rare for this to be an issue, just parameterise it:

Code

{!BLOCK_CREDITS_EXP_INNER_MSG,{$NUMBER_FORMAT*,{NUM_CREDITS}},{$COMCODE,[currency="{S_CURRENCY}" bracket="1"]{PRICE}[/currency]}}
and:

Code

BLOCK_CREDITS_EXP_INNER_MSG=<strong>{1}</strong> credits currently cost {2} &dagger;&dagger; and are good for:

That also leads to cleaner, better-tiered code. E.g. easier for a translator to work with.


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
Posted
Rating:
#96318
Avatar

Community saint

Ok so that almost worked for me but it seems the comcode portion is not working correctly

I had to add a 3rd var to lang string as such but the template is the same as what you posted.

Code

BLOCK_CREDITS_EXP_INNER_MSG=<strong>{1}</strong> credits currently cost {2} {3} &dagger;&dagger; and are good for:

However it outputs like this (and yes I set a user currency for the account checking)
50 credits currently cost GBP 275.00 †† and are good for:

but it should look like this:
50 credits currently cost £275.00 GBP ($340 CAD)†† and are good for:

Don't know what to do here?
Back to the top
 
Posted
Rating:
#96320
Avatar

Community saint

Oh do note i reversed the vars 2 and 3 so it i s 1 3 2 which should be correct I think based on the order of them sent in the array to the template but the conversion in brackets is still not computed.
Back to the top
 
Posted
Rating:
#96321
Avatar

Community saint

Nevermind got it working!

Problem was S_CURRENCY was further down the array list than it should have been when passed to the template! Thanks for help!
Back to the top
 
Posted
Rating:
#96322
Avatar

Community saint

Oh and I didn't nned the 3rd var after all lol DOH! you had it right from the beginning I just had my array in the wrong order
Back to the top
 
There are too many online users to list.
Control functions:

Quick reply   Contract

Your name:
Your message: