Joomla! Discussion Forums



It is currently Wed Nov 25, 2009 2:25 am (All times are UTC )

 




Post new topic Reply to topic  [ 13 posts ] 
Author Message
 Post subject: %s What does it mean?
Posted: Thu Nov 05, 2009 7:46 pm 
Joomla! Intern
Joomla! Intern
Offline

Joined: Tue Oct 28, 2008 4:20 pm
Posts: 60
I am trying to find some information on the meaning and use of this little %s that is found in the language ini files, for exaple:
Quote:
EMAIL_MSG=This is an e-mail from (%s) sent by %s (%s). You may also find the following link interesting: %s


I have googled and search the forums, but can't find an explantion on what it is, does or how to use it.

Can anyone point me a link?

Thanks.

Simon


Top
  E-mail  
 
Posted: Thu Nov 05, 2009 7:50 pm 
Joomla! Enthusiast
Joomla! Enthusiast
Offline

Joined: Fri Oct 16, 2009 7:22 pm
Posts: 135
Location: Lincoln, NE USA
It is a string replacement for a sprintf statement.
Here is a link with more information on sprintf:

http://php.net/manual/en/function.sprintf.php

Hope that helps.


Top
  E-mail  
 
Posted: Thu Nov 05, 2009 7:51 pm 
User avatar
Joomla! Master
Joomla! Master
Offline

Joined: Thu Aug 18, 2005 7:13 am
Posts: 13249
They are placeholders for text that is inserted when that specific message is triggered somewhere and is used through JText.

_________________
Antonie de Wilde - Forum admin
All Joomla! release dates and days between releases: http://jfoobar.org/blog/189-days-betwee ... a-releases.test


Top
   
 
Posted: Thu Nov 05, 2009 7:51 pm 
Joomla! Intern
Joomla! Intern
Offline

Joined: Tue Oct 28, 2008 4:20 pm
Posts: 60
Thanks for the link, I can se I am going to have great fun now :)


Top
  E-mail  
 
Posted: Thu Nov 05, 2009 8:00 pm 
Joomla! Intern
Joomla! Intern
Offline

Joined: Tue Oct 28, 2008 4:20 pm
Posts: 60
Looking at the sprintf documents, it is well over my head.

The main problem I have is when a user registers on my site through JomSocial.
For some reason the activation email that is received by the user is incorrectly showing the registered Username and instead putting in the domain name.
But in the confirmation email sent to admin, it is pulling the Username correctly.

I have been looking through the en-GB.com_community.ini file which states:

Code:
SEND_MSG_ACTIVATE=Hello %s,\n\nThank you for registering at The LED Community. Your account has been created and must be activated before you can use it.\nTo activate the account click on the following link or copy-&-paste it in your browser:\n%s\n\nAfter activation you may login to %s using the following username and password:\n\nUsername: %s\nPassword: %s

SEND_MSG_ADMIN=Hello %s,\n\nA new user has registered at %s.\nThis e-mail contains their details:\n\nName: %s\nE-mail: %s\nUsername: %s\n\nPlease do not respond to this message. It is automatically generated and is for information purposes only.


I now wonder were it gets the data when %s is called.


Top
  E-mail  
 
Posted: Fri Nov 06, 2009 10:01 am 
User avatar
Joomla! Exemplar
Joomla! Exemplar
Offline

Joined: Thu Jul 17, 2008 3:10 pm
Posts: 7669
Location: Europe
tllcuk wrote:
I now wonder were it gets the data when %s is called.


It is called with the sprintf function:
Code:
sprintf ( JText::_( 'MAIL_MSG_ADMIN' ), $adminName, $type, $title, $author, $url, $url, 'administrator', $type);


Please note that the order of the %s variables is important.

Olaf

_________________
Olaf Offick
Learn Skills - a world of learning at your fingertips
http://learn-skills.org


Top
   
 
Posted: Fri Nov 06, 2009 1:40 pm 
Joomla! Apprentice
Joomla! Apprentice
Offline

Joined: Thu Oct 29, 2009 1:40 pm
Posts: 23
Thanks Olaf.

I found the issue, it was due to one of the %s being removed in the language.ini file.

Where would I find the file that contains the sprintf function and variables for this?
I also guess there is some document listing all the types of variables for sprintf in joomla?

Thanks again.


Top
  E-mail  
 
Posted: Fri Nov 06, 2009 2:34 pm 
User avatar
Joomla! Exemplar
Joomla! Exemplar
Offline

Joined: Thu Jul 17, 2008 3:10 pm
Posts: 7669
Location: Europe
Here are the types specified:
http://php.net/manual/en/function.sprintf.php

Olaf

_________________
Olaf Offick
Learn Skills - a world of learning at your fingertips
http://learn-skills.org


Top
   
 
Posted: Fri Nov 06, 2009 3:12 pm 
Joomla! Apprentice
Joomla! Apprentice
Offline

Joined: Thu Oct 29, 2009 1:40 pm
Posts: 23
Thanks again Olaf.

So if I understand this correctly, all joomla php files contain these strings and placeholders.
Having looked and paid a bit more attention to the php side of things, instead of the css and html, I can see these now, but may not understand it all.

Taking the previous code from the en-GB.com_community.ini file

Code:
SEND_MSG_ACTIVATE=Hello %s,\n\nThank you for registering at $s. Your account has been created and must be activated before you can use it.\nTo activate the account click on the following link or copy-&-paste it in your browser:\n%s\n\nAfter activation you may login to %s using the following username and password:\n\nUsername: %s\nPassword: %s


I am now curious to know which file the %s are setup to specify the username, domain, activation link, domain, username, password as seen in that string.


Top
  E-mail  
 
Posted: Fri Nov 06, 2009 3:52 pm 
User avatar
Joomla! Exemplar
Joomla! Exemplar
Offline

Joined: Thu Jul 17, 2008 3:10 pm
Posts: 7669
Location: Europe
That would be some files which are from the third party extension com_community.

Olaf

_________________
Olaf Offick
Learn Skills - a world of learning at your fingertips
http://learn-skills.org


Top
   
 
Posted: Fri Nov 06, 2009 4:26 pm 
Joomla! Apprentice
Joomla! Apprentice
Offline

Joined: Thu Oct 29, 2009 1:40 pm
Posts: 23
Thanks Olaf,

Time to start digging harder into the files for com_community.


Top
  E-mail  
 
Posted: Sun Nov 08, 2009 5:02 am 
User avatar
Joomla! Virtuoso
Joomla! Virtuoso
Offline

Joined: Sat Sep 24, 2005 11:01 pm
Posts: 4482
Location: Toronto, Canada
simonwellsuk wrote:
Thanks again Olaf.

So if I understand this correctly, all joomla php files contain these strings and placeholders.
Having looked and paid a bit more attention to the php side of things, instead of the css and html, I can see these now, but may not understand it all.

Taking the previous code from the en-GB.com_community.ini file

Code:
SEND_MSG_ACTIVATE=Hello %s,\n\nThank you for registering at $s. Your account has been created and must be activated before you can use it.\nTo activate the account click on the following link or copy-&-paste it in your browser:\n%s\n\nAfter activation you may login to %s using the following username and password:\n\nUsername: %s\nPassword: %s


I am now curious to know which file the %s are setup to specify the username, domain, activation link, domain, username, password as seen in that string.

I think what you want to do is specify the optional ordering in your replacement string.

By default, using a series of %s will replace the %s's with the strings in the order that they appear.

But you can also use syntax like %1$s, %2$s, %3$s etc to specify exactly which string you want to display where. To figure out the order of the strings, look at the original string and see what order they are presented.

Hope that helps :)
Ian

_________________
Joomla! Leadership Team - Production Working Group
Joomla! Bug Squad Coordinator
Joomla! Developer Documentation Team
Please don't say something 'isn't working'. Explain what you tried, and what happened as a result.


Top
   
 
Posted: Sun Nov 08, 2009 8:18 am 
Joomla! Intern
Joomla! Intern
Offline

Joined: Tue Oct 28, 2008 4:20 pm
Posts: 60
Thanks Ian,

Yes, i understand.
I can see the order of the string as shown in the example and presumed what the data would be, I just cant find a file that stores all the arrays to which these strings look at.

Thanks

Simon


Top
  E-mail  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ] 

Quick reply

 



Who is online

Users browsing this forum: amanara, mirror51, trgduy, weber12 and 14 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group