Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

include file will not be replaced at a next call

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Smarty Development
View previous topic :: View next topic  
Author Message
0rientsieg
Smarty Rookie


Joined: 08 Jan 2014
Posts: 24

PostPosted: Sun Jan 12, 2014 4:32 am    Post subject: include file will not be replaced at a next call Reply with quote

Dear All,
Again I face a problem with Smarty. My concern is using only one Smarty initialization file for the insertion of 3 different language files English, Thai, and German one at a time in a common .tpl file. So I created 3 differen language files for Smarty with identicsal structure with the text variables of the languages in an array. Basically each language file works perfectly in conjunction with the .tpl file for a call to the Smarty initialization file. But if I call Smarty from my application with the correct language, the lamnguage does only change occasionally, that means not at each call.
The names of the language files are 'sprache_enS.php', 'sprache_thS.php, and 'sprache_deS.php. I hand over the required language in a variable I call $pasa. The include tag looks as follows:

$SPRACHE_PATH = "/home/www/virtual/moon-and-sun.com/htdocs/resort/sprache/";
include $SPRACHE_PATH . $pasa;

The per php-echo retrieved value for '$SPRACHE_PATH . $pasa' is at every time correct, e.g.

/home/www/virtual/moon-and-sun.com/htdocs/resort/sprache/sprache-enS.php

But if I had previously the language German or Thai displayed the language does not change, although the previously opened .tpl file was correctly closed on escape.
My personal impression is, that for some reasons the previously opened include file for the previous language ist still loaded and the required new language file does not replace the previous language file but may be appended. I such a case the variable names for the language to be inserted will be found in the 'old' previously inserted language file, which is in first place and the wrong language is displayed.
Is there a method to kill an included file, that means to remove it before a new include file will be loaded?
With regards
Siegfried
Back to top
View user's profile Send private message
0rientsieg
Smarty Rookie


Joined: 08 Jan 2014
Posts: 24

PostPosted: Sun Jan 12, 2014 12:09 pm    Post subject: New submitted include file will not be processed Reply with quote

Dear All,
Also for this problem I found after some hours trial a solution.
The situation was as follows: A .tpl file was processed with a specific language file. After submission of a new language file with the same .tpl file the language at the displayed .tpl file did not change.
I set now the Smarty parameter force compile to 'true' as shown below and the problem is solved.
$smarty->force_compile = true;
In my understanding Smarty only occasionally does a new compilation run if it is called for the same .tpl file independently of other parameters that may differ from the previous run. But if force_compile is set to true a compilation run will be performed for every call independently whether the .tpl file changes or remains as is.
But the response from this forum community is very poor and a person with less experience will be lost.
The thread is now solved finally.
With regards from sunny, moderate warm Thailand
Siegfried
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Sun Jan 12, 2014 10:39 pm    Post subject: Reply with quote

Setting $smarty->force_compile = true; is a bad solution for performance as it will recompile on each call.

For a case like yours you must use a compile_id like

Code:
$smarty->compile_id = some thing unique

The compile id should be set to something unique like the language name. Then Smarty stores different compiled versions for each language.

http://www.smarty.net/docs/en/variable.compile.id.tpl
Back to top
View user's profile Send private message
0rientsieg
Smarty Rookie


Joined: 08 Jan 2014
Posts: 24

PostPosted: Mon Jan 13, 2014 11:55 am    Post subject: Reply with quote

Thank you for your advice, U. Tews.
I inserted the line and it works now without force_compile.
Beginners need badly the support of experienced persons.
Thanks again
With regards
Siegfried
Permanent resident of Thailand.
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Sat Jan 18, 2014 1:59 pm    Post subject: Reply with quote

Here is another example how you could handle language dependent text by using config files.

Create a config file for each language and place it in the configs folder.

File en.conf
Code:
title = "My Title"
text1 = "my text 1"
...


Config variables will be called in the template like this
Code:
{#title#}
...
{#text1#}


Load in your PHP script the config file of the required language
Code:
$language = 'en';
$smarty->configLoad($language'.conf');



Don't use a compile_id as stated in my previous post but set a cache _id

Code:
$smarty->cache_id = $language;


It might be easier to maintain the different languages in config files as in PHP script files and $smarty->assign() calls.

Learn more here
http://www.smarty.net/docs/en/config.files.tpl
http://www.smarty.net/docs/en/api.config.load.tpl
http://www.smarty.net/docs/en/language.config.variables.tpl
Back to top
View user's profile Send private message
0rientsieg
Smarty Rookie


Joined: 08 Jan 2014
Posts: 24

PostPosted: Sat Jan 18, 2014 2:59 pm    Post subject: Insertion of text into javascript files at compilation time Reply with quote

Dear U. Tews,
Thank you very much for your previous hint that in front of the include routine the {/literal} tag is missing. You were fully right, that was the problem. I arranged now all {literal}{/literal} tags correctly AND NOW THE TEXT INSERTION INTO THE JAVASCRIPT FILE AT SMARTY COMPILATION TIME WORKS PERFECTLY!!!
Thanks to you and to mohrt for your patience! But the success counts only.
If you want to see the result in English language click
http://www.moon-and-sun.com/booking/makewp/input.php?tpl=ms-gallery&pasa=en
The same template but with German language inserted you find under:
http://www.moon-and-sun.com/booking/makewp/input.php?tpl=ms-gallery&pasa=de
The inserted text into the javascript file you will find after a single click at one of the slides below the enlarged image that then appears as e.g. 'Image 35 of 92' in English or as e.g. 'Bild 61 von 92' in German language.
These are still my development pages. Therefore, at the top of the pages there is a a line in which I echoed some important variables which have shown me the correct calculation of the identification and the selection of the correct language file. The final version will not show this line. Also the headline of the page I'll rearrange.
Your suggestions included in your last answer to that thread, U. Tews, I'll study and test thoroughly.
Thanks again to both of you.
With regards
Siegfried
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Smarty Development All times are GMT
Page 1 of 1

 
Jump to:  
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 vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP