Jump to content
rash

[Solved] No translations display

Recommended Posts

Hi guys,

after hours of trying and reading several threads I suppose tears will start running soon.  I work with the widely spread and documented method of a _strings.php file and a t() function. Everything seeems to run fine, the translator finds the _strings file, all phrases are translated properly and no error messages are showing up. Except that no translatiions are shown at all, no matter what I do:  It's like a hopeless struggle with deceitful demons.

My _init.php:

include_once("./_func.php");
include_once("./_strings.php");

(in this order). Then in _func.php:

function _t($text, $context, $textdomain = "/site/templates/_strings.php") {
    return _x($text, $context, $textdomain);
}

and in _strings.php:

<?php namespace ProcessWire;
/*
_x('Home', 'generic');
_x('/en/', 'generic');
_x('Contact', 'footer');
_x('/en/contact/', 'footer');
_x('Other projects', 'footer');
*/
?>

Trying to call the translations for example in the footer template like this:

<li><a href='<?php echo _t('/en/contact/', 'footer'); ?>'><?php echo _t('Contact', 'footer'); ?></a></li>

leads to this result , no matter what language is active.

<li><a href='/en/contact/'>Contact</a></li>

The translator has everything it needs:

{
    "file": "site\/\/templates\/_strings.php",
    "textdomain": "site----templates--_strings-php",
    "translations": {
        "33fa1c21648d73e1ac14e0db66b4fa9e": {
            "text": "Start"
        },
        "2f73c44cbb8a98616f8aeca67192aec6": {
            "text": "\/de\/"
        },
        "77eb6543a21ba5c45f9c11f899136eee": {
            "text": "Kontakt"
        },
        "68780987fca9c3f52fb511f87cd43262": {
            "text": "\/de\/kontakt\/"
        },
        "184cf75de619c2e3a02a40f163c81c5e": {
            "text": "Weitere Projekte"
        }
    }
}

Obviously there seems to be a connection problem between the _func and the _strings file. Instead of $textdomain = '/site/templates/_strings.php' I can fill in whatever I want without any recognizable difference. Any hints what else I could try?

Cheers
Ralf

 

 

Share this post


Link to post
Share on other sites
25 minutes ago, rash said:

It's like a hopeless struggle with deceitful demons.

I don't know anything about translations because where I live there is no demand for multi-language websites. I'm sure someone will help you with specifics for that soon.

But as some general advice, you'll find that any development problem becomes a lot less confusing and frustrating as soon as you install Tracy Debugger and learn how the basic bardump works. Then you can start dumping variables in your template files, includes and functions and that way find out where your problem lies. I can testify that it's very empowering and greatly reduces feelings of hopelessness. :-) 

  • Like 2

Share this post


Link to post
Share on other sites

@rash I downloaded a fresh copy of PW master, installed the Multi language profile and replicated your settings. Everything worked! So, there's something you may have missed in your setup.

 

  • Like 1

Share this post


Link to post
Share on other sites

Found something different: my string-php.json file has two hyphens instead of 3 on the textdomain line, look:

{
    "file": "site\\templates\\_strings.php",
    "textdomain": "site--templates--_strings-php",
    "translations": {
        "2f73c44cbb8a98616f8aeca67192aec6": {
            "text": "\/de\/"
        },
        "77eb6543a21ba5c45f9c11f899136eee": {
            "text": "Kontakt"
        },
        "68780987fca9c3f52fb511f87cd43262": {
            "text": "\/de\/kontakt\/"
        }
    }
}

I'm on Windows 10.

  • Like 1

Share this post


Link to post
Share on other sites

@Robin S Thanks for your recommendation. I installed TracyDebugger and spontaneously I'm a bit overwhelmed (it's long after midnight here and the fights did weaken me). Anyway, it's definitely a highly interesting tool that I will examine in detail soon.

@Sergio You do lot of work to help me, that’s very friendly. Your secont hint could lead into the near of a solution, as I assume a problem with paths. Unfortunately I don’t understand the relation of the path in the function and the  number of hyphens the translator produces. Regarding my settings: before I tried the _strings.php method, I travelled the exhausting road of translating with __('term') file by file. That worked just fine, I only found it a bit too exhausting on the long run and started looking for a faster way (haha). So there might be something wrong with the settings, but it must be very subtile then.

Share this post


Link to post
Share on other sites
9 hours ago, Sergio said:

Found something different: my string-php.json file has two hyphens instead of 3 on the textdomain line, look:

@Sergio A late Bingo! After a few hours of sleep I picked up your hint once more, although I still don’t understand what's going on with the hyphens. So I simply deleted the _strings.php of the translater and re-imported it. The number of hyphens appeared reduced and everything works now as expected. Another big thank you – the day is suddenly showing a much sunnier face as this little evil is defeated.

  • Like 1

Share this post


Link to post
Share on other sites

That's great, @rash!!

The hyphens seems to be created by the escaping of the forward/back slashs on the file path, one hyphen replace each, so that's why I noticed that your _strings.php file appeared to have the wrong path.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...