Jump to content

How to get the value from specific language in a textdomain


markus_blue_tomato
 Share

Recommended Posts

Is it possible to get the value of a specific language in ProcessWire's translation tools?

What I want to is following: Before printing out $key as fallback, I want to use a "fallback" language. Only after the fallback language has also no result, the $key should be printed out.

//users current language is for example: german

$key = "lorem_ipsum";
$string = __($key, "path/to/my/textdomain.php");

if(empty($string)) {
	$string = __($key, "path/to/my/textdomain.php", "english");
}

echo $string;

And yes I know I could put the fallback into the code as key, but I don't want this. If the fallback has to change, the customer can't do it on his own and I have to to this with a full deployment.

Link to comment
Share on other sites

I found a solution which works:

//users current language is for example: german
// language "default" is english

$key = "lorem_ipsum";
$string = __($key, "path/to/my/textdomain.php");

if($key == $string && wire('user')->language->name != "default") {
	wire('languages')->setLanguage('default');
    $string = __($key, "path/to/my/textdomain.php");
    wire('languages')->unsetLanguage();
}

echo $string;

 

  • Like 2
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...