Forum

Thread tagged as: Blog

Multi Language for Blog?

Hey, quick question... we have applied the multi-language region for each content page - works well and easy enough for client to edit.

But how do we set this up for Blog?? Or Events, Galleries etc. Standard content is fine but when listing items from custom arrays, where/how do we add the lang variable?

For standard content I used the code: <?php perch_content('My Content Area Name - '.$lang); ?>

Thanks.

Stuart Farrell

Stuart Farrell 0 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

How about using sections or categories?

Hmmm.... I don't really want to duplicate each Blog entry 4 times... particularly as they are already populated and have a heap of images in each.

I have four icons to switch languages, which is working great for generic content.

What I would really like is to have just the one text field duplicated four times in each Blog entry for the different languages and perhaps use a perch if to show/hide maybe??

Drew McLellan

Drew McLellan 2638 points
Perch Support

Yes, you could do that. Add the extra fields to your post.html template.

So would need to check for the variable if set and default to English... will see how we go!

Drew McLellan

Drew McLellan 2638 points
Perch Support

Yes, that's right.

Just on this... trying to use perch:if to check the variable value of "lang" in the URL but not having much luck?? Also trying to get it working for the icon nav...

For example, URL would be /about.php?lang=de

Template for icons to change language... (links are working fine, just trying to get on states working).

<perch:if id="lang" value="de"><li class="current"><perch:else /><li></perch:if>
    <a href="?lang=de">
        <i class="ico-deu"></i>

        <span>DEU</span>
    </a>
</li>

Am I going about this the wrong way?

We did have a JS function working well for on states but if no lang was defined in URL we got stuck, so thought it might be easier to bring into Perch.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Are you passing the lang variable into the template? If not:

PerchSystem::set_var('lang', perch_get('lang'));

Yeah, using content custom... but not getting anything out??

<?php 
    PerchSystem::set_var('lang', perch_get('lang'));
    perch_content_custom('Languages', array(
    'template'=>'languages.html'
    ));
?>

If I get vars on about.php?lang=de I see the below, so it should work yeah?

Array ( [lang] => de [perch_page_path] => /about.php )

There is no template error location and the template is as original post.

Drew McLellan

Drew McLellan 2638 points
Perch Support

What does <perch:showall /> output for your template?

Nothing.... ?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Which version of Perch are you using? It should be 2.8.8.

Yep.

Perch: 2.8.8 PHP: 5.4.37 MySQL: mysqlnd 5.0.10 - 20111026 Server OS: Linux, cgi-fcgi Installed apps: content (2.8.8), assets (2.8.8), categories (2.8.8), perch_forms (1.8.3), perch_blog (4.6)

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ok, <perch:showall /> should output in your template. If not, you have bigger issues.

OK... something is specifically wrong with this template or page...

If I add <perch:showall /> to other templates it works fine.

So...

Does it matter what you call the custom content region?

Should you see this region come up in Perch Admin? Because I can't.

I'm getting the same issues on two different servers - one runs over 20 of our Perch sites without issue, so assume it can't be a php setting.

The template should just be in the "../templates/content/" folder yeah?

Oh, just realised... this is in the header and loading from includes folder. Do I need to set any paths anywhere??

Drew McLellan

Drew McLellan 2638 points
Perch Support

If you turn on debug, what does it output?

Shows one alert:

No matching content regions found. Check region name (Languages) and page path options.

Full Debug Message:

SELECT * FROM perch2_pages WHERE pagePath='/about.php' LIMIT 1
Using template: /templates/pages/attributes/default.html
Using sub-template: /templates/pages/attributes/seo.html
Using template: /templates/pages/attributes/default.html
Using sub-template: /templates/pages/attributes/seo.html
SELECT groupID FROM perch2_navigation WHERE groupSlug='main-nav' LIMIT 1
SELECT np.pageID, np.pageParentID, p.pagePath, p.pageTitle, p.pageNavText, p.pageNew, p.pageOrder, np.pageDepth, p.pageSortPath, np.pageTreePosition, p.pageAccessTags, p.pageAttributes FROM perch2_navigation_pages np, perch2_pages p WHERE p.pageID=np.pageID AND np.groupID=1 AND p.pageNew=0 ORDER BY np.pageTreePosition ASC
SELECT np.pageTreePosition FROM perch2_pages p, perch2_navigation_pages np WHERE np.pageID=p.pageID AND np.groupID=1 AND p.pagePath='/about.php' LIMIT 1
SELECT pageID FROM perch2_navigation_pages WHERE groupID=1 AND pageTreePosition IN ('000-000', '000')
Using template: /templates/navigation/item.html
SELECT regionID, regionTemplate, regionPage, regionRev AS rev FROM perch2_content_regions WHERE regionKey='Languages' AND (regionPage='/about.php' OR regionPage='*')
No matching content regions found. Check region name (Languages) and page path options.
SELECT * FROM ( SELECT idx.itemID, c.regionID, idx.pageID, c.itemJSON, idx2.indexValue as sortval FROM perch2_content_index idx JOIN perch2_content_items c ON idx.itemID=c.itemID AND idx.itemRev=c.itemRev AND idx.regionID=c.regionID JOIN perch2_content_index idx2 ON idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev AND idx2.indexKey='_order' WHERE idx.regionID IS NULL AND idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev ) as tbl GROUP BY itemID ORDER BY sortval ASC
Using template: /templates/content/languages.html
SELECT regionKey, regionHTML FROM perch2_content_regions WHERE regionPage='/about.php' OR regionPage='*' ORDER BY regionPage DESC

For some reason this is repeated twice...

Drew McLellan

Drew McLellan 2638 points
Perch Support

So that's telling you that the page /about.php does not have a region called Languages.

Would you dispute that?

Wow yeah... somehow I managed to clobber this region: <?php perch_content('Languages');?>

This is what happens when you code at 1am.......... So... yeah, sorry to waste your time, all good now thanks.

OK, well that made it load, but obviously duplicated it, so now I removed it from page below and it works.... anyhow??

<div class="header">
        <a href="#" class="btn-menu"></a>

        <?php 
            perch_pages_navigation(array(
            'navgroup' => 'main-nav',
            ));
        ?>

        <a href="index.php" class="logo">Seibo</a>

        <nav class="nav-utilities">
            <ul class="clearfix">
                <?php 
                    PerchSystem::set_var('lang', perch_get('lang'));
                    perch_content_custom('Languages', array(
                        'template'=>'languages.html'
                    ));
                ?>
                <?php perch_content('Languages');?>
            </ul>
        </nav><!-- /.nav-utilities -->
    </div><!-- /.header -->

So is that the normal way to use perch_custom_content?? To add the target region then delete??