CodeCanyon

Just a quick suggestion about Smarty!

122 posts
  • Has been a member for 2-3 years
  • Exclusive Author
  • Bought between 10 and 49 items
  • Referred between 500 and 999 users
jackpotsoft says

Hi Devs,

I am working on a project

Most annoying things about it , is changing text in smarty templates

<div id="dashboard"> <span>${myvariable}</span> <span>Great Taste</span> <span>Great Reviews</span> </div> <div class="clear" id="content"> </div>

So you see there are 2 things in about smaty template code

1.HTML Code 2.PHP Variable ${myvariable}

3. Simple Text’s Like “Great Taste” “Great Reviews” I have 100’s of similar smarty files.

What i want is a tool or way where i open smarty file and see Simple Text files to be translated.

Or Automatically assign Them as Variable and there creates a language file.

So it looks like

<div id="dashboard"> <span>${myvariable}</span> <span>${lang['great_taste']}</span> <span>${lang['great_reviews']}</span> </div> <div class="clear" id="content"> </div>

I want a tool which can scan through all files and replace them to language variables.

Later i can change them in language file.

Please suggest!

I promise to buy that authors Item as my appreciate for helpful suggestion.

Thanks in advance

9 months ago
515 posts
  • Has been a member for 1-2 years
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Exclusive Author
  • Sold between 1 000 and 5 000 dollars
  • Bought between 100 and 499 items
  • United Kingdom
  • Referred between 10 and 49 users
aaranmcguire says

Hey,

am i right in saying you want a language file for your site….

this is what i do…

This would be a language like en.php then you change the long text to the translated language.. keep the $language and short text how it is..
$language = array();

// $language['type']['short_text'] = "long text";
$language['error']['wrong_username'] = "the username you entered was wrong.";

and if you have lots of languages you can do:

$lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
switch($lang){
    case "en": // english
    include_once("languages/en.php");
    break;
    case "fr": //french
        include_once("languages/fr.php");
        break;
        case "de": // german
        include_once("languages/de.php")

}    

no when you do a response you echo
$language['error']['wrong_username'];
and it should echo out the language thats included…
9 months ago
79 posts
  • Has been a member for 2-3 years
  • Exclusive Author
  • Sold between 5 000 and 10 000 dollars
  • Bought between 1 and 9 items
  • Australia
  • Referred between 10 and 49 users
jordie says

You can do as aaran suggested, by language packing it. Might save you time in future.

But if you want to make a quick change now, this is what I do:

I’m using windows, let me know if you’re on a mac and I’ll run through what I do on my laptop. But on my PC (where I do most of my dev work) I use EditPlus 3. (See http://www.editplus.com)

I open all the files I want to change in EditPlus, or alternatively, EditPlus has a “Find in Files” button. Click that, type what you want, select your directory and it’ll list all the files containing that text. Right click the list, select ‘Open All’.

With all the files open, click the ‘Replace’ button, or go to Search menu then ‘Replace’. Type the text you want to find, then type what you want to change it to. Then at the bottom under “Replace in Range” choose “All open files”. Click ‘Replace All’. All the files will then be changed. Right click on one file tab, and choose ‘Save All’. Done! :)

9 months ago
by
by
by
by
by