Jump to content

Using translatable strings outside normal page context


Neo
 Share

Recommended Posts

I have saved a couple of string phrases inside my static code that need to be translated.

I saved those in the central site translation files.

What you would normally do then in the page-context is the following, which works without problems:

<?php echo __("This is my string."); ?>

 

Now, I have a situation, where I need one of those strings in a functions-file that is included in one of my templates.

As this is not the normal page-context, all ProcessWire objects need to be wrapped in the wire() function.

 

I tried to call my translatable strings in different ways, but without success:

$translation = __("My string"); // will always show the string in the default language

$translation = wire('this')->_("My string"); // call to member function on null

Would appreciate your advice.

 

UPDATE:

I got it working now with the normal way that you would use in the page-context. Not sure what the problem was

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...