Simple Machines Community Forum

Customizing SMF => Graphics and Templates => Topic started by: forsakenlad on September 12, 2008, 05:24:04 PM

Title: Text Strings in Themes
Post by: forsakenlad on September 12, 2008, 05:24:04 PM
As per the Theme Approval Guidelines, all text should be in a theme language string, however the Guidelines are lenient with copyrights and allow these to be hard-coded.

Theme authors will commonly place their strings into the wrong file, for example:  Modifications.language.php (Eg: Modifications.english.php, Modifications.turkish.php). Although this is not technically the wrong place to put the strings, it will cause issues with modifications being installed on the theme.

When making a theme you can simply add 2 or 3 extra lines of code into your index.template.php, which will call a ThemeStrings.language.php file where your strings can go. This will prevent conflicts with modifications and your theme.

Search for this in index.template.php:


   /* Show sticky and lock status seperate from topic icons? */
   $settings['seperate_sticky_lock'] = true;


Replace it with:


   /* Show sticky and lock status seperate from topic icons? */
   $settings['seperate_sticky_lock'] = true;

   /* Call to Theme String for languages  */
   if (loadlanguage('ThemeStrings') == false)
      loadLanguage('ThemeStrings', 'english');





In 2.0 RC1 and onwards, a new way of including ThemeStrings.language.php would be to set $settings['require_theme_strings'] to true in index.template.php.  It would look something like this:

/* Set the following variable to true if this theme requires the optional theme strings file to be loaded. */
$settings['require_theme_strings'] = false;


by default, and when false is changed to true, it'll start to load ThemeStrings alongside the other language files SMF needs to display the page.

An English version of this file can be found attached.
Title: Re: Theme Strings in Themes
Post by: Antechinus on September 14, 2008, 05:34:50 AM
I have a question.  :D  You knew it had to happen.

Anyway I was using this code, which seems to work just fine:

/* Call to Theme String for languages  */
loadLanguage('ThemeStrings');


Is the code you posted better in some way or doesn't it matter?  If it is better I'll use it in future.
Title: Re: Theme Strings in Themes
Post by: Deaks on September 14, 2008, 05:41:51 AM
The one we have included will fall back to the english version (as this will always be in a new theme) so say you are using Hungarian and there is no hungarian ThemeStrings the english version will show.  Its just an updated version of the code you will find in many older themes
Title: Re: Theme Strings in Themes
Post by: rapidvectorseo on September 29, 2008, 07:26:16 AM
English version does not required code.
Title: Re: Theme Strings in Themes
Post by: Deaks on September 29, 2008, 08:06:39 AM
We advise even english  speaking authors add this aswell it helps with making trhe theme suitable for all languages
Title: Re: Text Strings in Themes
Post by: Orangine on July 14, 2012, 03:25:20 PM
I'm trying to separate theme strings to make it easier to add more languages in future, but I'm stuck here. It seems this method doesn't work anymore. Can you help me and point me to the right direction? Many thanks!
Title: Re: Text Strings in Themes
Post by: Gary on July 14, 2012, 04:34:44 PM
The second method Eren pointed you to of setting $settings['require_theme_strings'] in index.template.php to true, will cover you. It's not there by default, so you need to add it into the template_init function yourself.
Title: Re: Text Strings in Themes
Post by: Orangine on July 14, 2012, 04:47:13 PM
I've added that, created ThemeStrings.english.php and ThemeStrings.english-utf8.php then I've put them into my theme's folder, but still the strings are not showing up. What I'm doing wrong?

edit:
Ok, got it. ThemeStrings.english.php has to be put inside 'languages' folder, works ok now.
Title: Re: Text Strings in Themes
Post by: Deaks on July 15, 2012, 01:50:30 AM
always the simple things that fix the issue :)
Title: Re: Text Strings in Themes
Post by: Orangine on July 15, 2012, 09:34:52 AM
I have added this info to Creating and Understanding Themes (http://wiki.simplemachines.org/smf/Creating_and_Understanding_Themes#Theme_Strings_in_Themes) in wiki.