Jump to content

Translatable string in namespaced code

Recommended Posts


I face interesting issue in PW v3. I have utility class, which is loaded from template. Class is put in namespace due to some naming collisions. But it is impossible now to use translatable strings in it.

<?php namespace site\util;

class Utils {
  public function func() {
    __('car'); // Error - function site\util\__ does not exist.
    $this->__('car'); // Error - method Utils::__ does not exist.
    \ProcessWire\__('car'); // Code runs, but PW does not recognize translatable string in admin area.

I guess that this will not be issue in PHP 5.6 anymore, because you can use...

use function ProcessWire\__;

But how to deal with it in PHP 5.5? May be I could extend class Utils from some PW class to make $this->__() accessible? I mean...

class Utils extends ProcessWire\ClassWithTranslationMethod {

    public function func() {


Or do you see other solution? Thank you for all your ideas.


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

  • Create New...