Publisher does not support the Fluid field type. Please do not contact asking when support will be available.

If you purchased an add-on from expressionengine.com, be sure to visit boldminded.com/claim to add the license to your account here on boldminded.com.

Ticket: Translate Tags

Status Resolved
Add-on / Version Publisher
Severity Trivial
EE Version

Matt Bulfair

Mar 13, 2013

I am not 100% sure this is possible, but would it be possible to get the {phrase:} to take a variable? Perhaps a parse inward option?

I am using a tag module by solspace.

{exp:tag:tags entry_id="{entry_id}” }
{phrase:{tag}}
{/exp:tag:tags}

Would be nice if the “word” {tag} could be parsed before the phrase so it can be translated, since multilingual tags seems to be a tough one to crack.

#1

BoldMinded (Brian)

Try {exp:publisher:translate_phrase name=”{tag}”}

#2

Matt Bulfair

This works! Except if a translated word doesn’t exist it won’t render the others in english.

#3

Matt Bulfair

I modified this file: mod.publisher.php

Line 422:

to:

/** * Tag to translate phrases, just pulls from the global config, * but provides an option to get a phrase based on another variable value. * * {exp:publisher:translate_phrase name=”{foo}” show_all=”yes”} * * @return string */ public function translate_phrase() { $phrase_name = $this->EE->TMPL->fetch_param(‘name’); $prefix = $this->EE->publisher_setting->get(‘phrase_prefix’);

    $show_all = $this->EE->TMPL->fetch_param('show_all', false);

    if (isset($this->EE->config->_global_vars[$prefix.$phrase_name]))
    {
        return $this->EE->config->_global_vars[$prefix.$phrase_name];
    }

    if ($show_all == "yes") {
     return $phrase_name;
    }

    return '';
}

This fixes it for me, in this situation, but not sure it’s the proper approach.

#4

BoldMinded (Brian)

Oh I see what you did. I think removing that show_all though would be optimal, just have that last parameter return the requested phrase value.

return $phrase_name;
#5

Matt Bulfair

If that works for you, sure, if you were to roll this into a future release, I know this may be a unique case, but there aren’t any tag translation modules out there.

Here’s the updated version:

/** * Tag to translate phrases, just pulls from the global config, * but provides an option to get a phrase based on another variable value. * * {exp:publisher:translate_phrase name=”{foo}”} * * @return string */ public function translate_phrase() { $phrase_name = $this->EE->TMPL->fetch_param(‘name’); $prefix = $this->EE->publisher_setting->get(‘phrase_prefix’);

    if (isset($this->EE->config->_global_vars[$prefix.$phrase_name]))
    {
        return $this->EE->config->_global_vars[$prefix.$phrase_name];
    }

    return $phrase_name;
}
#6

BoldMinded (Brian)

I’ve already made the commit, so it’ll be in the next release.

#7

Matt Bulfair

Great, glad to help. Great work!

Login to reply