5

I'm building out a multi-language site using Transcribe which is coming along nicely. I'm having one issue with my navigation snippet (using low variables early parsing turned on).

I've got the following conditional working elsewhere in the site (in an embedded template)

{if '{transcribe:language_abbreviation}' =="en"}{category_name}{/if}{if '{transcribe:language_abbreviation}' =="fr"}{category_name_fr}{/if}

However when I use the same conditional inside the lv_nav snippet it fails to render anything. Relevant code below:

{exp:channel:categories channel="people" style="linear"}
    <li><a href="{path='about/people'}">{if '{transcribe:language_abbreviation}' =="en"}{category_name}{/if}{if '{transcribe:language_abbreviation}' =="fr"}{category_name_fr}{/if}</a></li>
{/exp:channel:categories}

If instead of using the conditional I just use {category_name} everything works fine except that on the French pages I've got English displaying and not French.

Any ideas why this is happening? I've also tried replacing {transcribe:language_abbreviation} with {exp:transcribe:language_abbreviation} and there was no change.

1 Answer 1

7

I'm not sure what type of variable {transcribe:language_abbreviation} is, but I presume it's an early parsed var, which could cause parsing issues. If both the LV and Transcribe var are parsed early, there's no way to control which one is parsed first in the same stage. There are 2 workarounds I can think of, assuming the Transcribe var is parsed early (which it is, according to the tag reference):

Preload Replace

Use Preload Replace vars to define the language suffix for the categories, similar to the approach I explained in this blog post:

{if transcribe:language_abbreviation != 'en'}
    {preload_replace:pre_lang_suffix="_{transcribe:language_abbreviation}"}
{/if}
{if transcribe:language_abbreviation == 'en'}
    {preload_replace:pre_lang_suffix=""}
{/if}

Note that if the Transcribe vars are indeed early parsed vars, the simple conditional syntax should work. Using simple conditionals here is necessary; don't use the {if:else} statement.

Then use this inside your LV instead of the conditionals:

{exp:channel:categories channel="people" style="linear"}
    <li><a href="{path='about/people'}">{category_name{pre_lang_suffix}}</a></li>
{/exp:channel:categories}

You can then keep using the variable syntax for the LV: {lv_nav}

LV Tag Syntax + Preparse

Another workaround would be to use LV's tag syntax and the preparse: parameter to pass on the Transcribe var. Something like this:

{exp:low_variables:single
    var="lv_nav"
    preparse:lang_abbr="{transcribe:language_abbreviation}"
}

And use the variable {lang_abbr} inside the LV instead of the full Transcribe variable:

{if lang_abbr == 'en'}
    {category_name}
{if:elseif lang_abbr == 'fr'}
    {category_name_fr}
{/if}

You should also be able to use the full Transcribe variable name with the preparse parameter:

{exp:low_variables:single
    var="lv_nav"
    preparse:transcribe:language_abbreviation="{transcribe:language_abbreviation}"
}

That way, you can leave the LV content as is.

1
  • Low - you are amazing. I had tried re-ordering my variables, but that didn't work. I clearly should've thought of preparse.
    – CreateSean
    Jan 4, 2013 at 14:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.