Jump to content

Files are compiled twice / Translatable strings are not translated


Zeka
 Share

Recommended Posts

After update to PW 3.0.15 everything works great, thanks to FileCompiler, but i found strange behavior for some translatable strings.
I'm using delegate template approach, so my _done.php file contain this code
<?php
    include("views/layout/head.inc");
    include("views/layout/header.inc");
    include("views/layout/headerline.inc");
    include("views/layout/breadcrumbs.inc");
?>

<?php echo $content;?>

<?php
    include("views/layout/footer.inc"); 
?>
In footer.inc i have some strings that have to be translated.
<?php echo __('FAX'); ?>
Here comes unclear things for me.
In backend i set translation for this string, but in frontend i still get untranslated string.
And it heppens only for strings that are located in files that are included in _done.php. Translation for every translatable string in other template files that goes from delegate approach works.
Also if i put some translatable sting to _done.php it also works.
 
One thing more: only files that included to _done.php get compiled twice.
You can see it on the screenshot.
PdP0gyc.png
 
In files that stored in FileCompiler/views/layout string 
 <?php echo __('PHYSICAL_ADRESS'); ?> 
becomes
<?php echo \ProcessWire\__('PHONE'); ?>
but in files that stored in FileCompiler/site/tempales/view/layout its still 
<?php echo __('PHYSICAL_ADRESS'); ?> 

So i can not understand what is going on. Is it a bug, or am i missing something?

Thanks
 
Link to comment
Share on other sites

I'm not positive this is the solution to the exact issue you are seeing, but I think there's definitely an issue with the include() statements being relative... so the question becomes, relative to what? The screenshot shows on /views/layout/ directory off of the installation root, and another off of the /site/templates/ directory, so I am also confused. :) The _done.php file appears to be in the /site/templates/views/ directory, but it's using include statements like this that don't specify the starting point: 

include("views/layout/head.inc");

The problem with the above is that no starting point means it's off to being looked for in all of PHP's include paths. If you want the starting point to be from the current directory, then you'd want to make it "./views/layout/head.inc". However, that wouldn't seem to be right here, since _done.php is already in the "views" directory (rather than the /site/templates/ directory). So it seems like it should instead be this:

include("./layout/head.inc"); 

I'm still a little confused about there being multiple /views/layout/ directories (if I understood that correctly), so it may be worthwhile to be even more specific, like specifying if you want the one that's off of $config->paths->root, or the one off of $config->paths->templates. For example, include($config->paths->templates . "views/layout/head.inc");

  • Like 1
Link to comment
Share on other sites

I can see the issue with using include, but shouldn't wireRenderFile (what I'm using) resolve relative paths automatically to absolute ones? I'm using wireRenderFile partly for not having to deal with absolute or relative paths, but simply relying on the automatic resolving of paths (e.g. relative to site/templates no matter from where I call wireRenderFile). The strange thing was, that parts of my files where correctly compiled (also in the correct place in the folder structure) whereas some files where not. I've not found the determining factor, but it seemed to only happen if there where multiple nested wireRenderFile calls and adding $config->paths->templates in front of the relative paths did resolve the issue. 

It might be, that my folder naming did play into this as I've the following structure: site/templates/templates/… and most of my wireRenderFile calls therefore look like this: wireRenderFile("templates/someFile.php", array());

I had exactly the same outcome as Zeka, where the folder structure was partly correct and some files where instead falsely compiled "relative to the root dir".

Link to comment
Share on other sites

  • 1 year later...

Hi, I confirm there is an issue with strings not translated in files included using relative path (I am using Processwire 3.0.62): the strings are not translated in frontend even if I have inserted the translations in the backend.

I solved it using absolute path to include the files, so instead of using:

include './views/_home.php';
I used:
include $config->paths->templates . 'views/_home.php';
  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...