[SOLVED] Gallery-related fields and language problem

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
(M)
Forum Members
Forum Members
Posts: 118
Joined: Tue Mar 18, 2008 11:43 pm

[SOLVED] Gallery-related fields and language problem

Post by (M) »

I have a problem with displaying Custom Fields from the Gallery module in different languages.
My page template has a language detection and selector. The following code works perfectly when I place it in the content

Code: Select all

{if $global_page_alias == 'home'} Nederlands {elseif $global_page_alias == 'accueil'} Frans {else} Engels {/if}
Set to Dutch I see 'Nederlands'. If I choose French in the selector I get 'Frans'.

I want language-dependent fields in the gallery for the titles and descriptions of images. In the following Gallery template I try to give the title per language.

Code: Select all

{foreach from=$images item=image}

	{if $image->isdir}
		<a class="item" href="{$image->file}" title="{$image->titlename}"><img class="img-responsive" src="{$image->thumb|escape:'url'|replace:'%2F':'/'}" alt="{$image->titlename}" /> 
		
        {foreach from=$fields item=field}
        <h3>{if $global_page_alias == 'home'} {$image->fields.categorie_titel_nl.value}
            {elseif $global_page_alias == 'accueil'} {$image->fields.categorie_titel_fr.value} 
            {else} {$image->fields.categorie_titel_en.value} {/if}</h3>
        {/foreach}
		</a>
	{else}
   <a class="group" href="{$image->file|escape:'url'|replace:'%2F':'/'}" title="{$image->comment}" rel="prettyPhoto[{$galleryid}]"><img class="img-responsive" src="{$image->thumb|escape:'url'|replace:'%2F':'/'}" alt="{$image->titlename}" /></a>
	{/if}

{/foreach}
The result is a Dutch or French title, but it will be just as much time displayed if the are Custom Fields created. I now see the title 6 times since there are 6 Custom Fields.

Does anyone have a solution to this problem?
Last edited by (M) on Tue Mar 15, 2016 11:02 pm, edited 1 time in total.
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3497
Joined: Mon Nov 28, 2011 9:29 am

Re: Gallery-related fields and language problem

Post by velden »

Of course it does:

Code: Select all

        {foreach from=$fields item=field}
        <h3>{if $global_page_alias == 'home'} {$image->fields.categorie_titel_nl.value}
            {elseif $global_page_alias == 'accueil'} {$image->fields.categorie_titel_fr.value}
            {else} {$image->fields.categorie_titel_en.value} {/if}</h3>
        {/foreach}
Note you're looping through the $fields thing (don't know what it is exactly but probably contains information about the custom fields) but you're not using it actually.

Consider not using that foreach loop but just 'call' the fields separately (as you know which fields you have created):

Something like:

Code: Select all

{foreach from=$images item=image}

  {if $image->isdir}
    <a class="item" href="{$image->file}" title="{$image->titlename}"><img class="img-responsive" src="{$image->thumb|escape:'url'|replace:'%2F':'/'}" alt="{$image->titlename}" />

    {if $global_page_alias == 'home'} 
      {$imgTitle = $image->fields.categorie_titel_nl.value}            
      {*$imgDescription = $image->fields.DESCRIPTION_nl.value*}{* <-- use your specific fieldname *}
      {* ...etc ... *}
    {elseif $global_page_alias == 'accueil'} 
      {$imgTitle = $image->fields.categorie_titel_fr.value}            
      {*$imgDescription = $image->fields.DESCRIPTION_fr.value*}{* <-- use your specific fieldname *}
      {* ...etc ... *}
    {else} 
      {$imgTitle = $image->fields.categorie_titel_en.value}            
      {*$imgDescription = $image->fields.DESCRIPTION_en.value*}{* <-- use your specific fieldname *}
      {* ...etc ... *}
    {/if}

    <h3>{$imgTitle}</h3>
    <h4>{$imgDescription}</h4>

    </a>
  {else}
    <a class="group" href="{$image->file|escape:'url'|replace:'%2F':'/'}" title="{$image->comment}" rel="prettyPhoto[{$galleryid}]"><img class="img-responsive" src="{$image->thumb|escape:'url'|replace:'%2F':'/'}" alt="{$image->titlename}" /></a>
  {/if}

{/foreach}
Last edited by velden on Wed Mar 16, 2016 8:46 am, edited 1 time in total.
Reason: Fixed typo in code
(M)
Forum Members
Forum Members
Posts: 118
Joined: Tue Mar 18, 2008 11:43 pm

Re: Gallery-related fields and language problem

Post by (M) »

Yes, this is exactly what I need. This works great.

Something little. This comment-out has a small typo at the beginning; (* ...etc ... *}

Thank you very much for your quick response.

PS. En bedankt voor de tips van afgelopen zaterdag ;-)
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3497
Joined: Mon Nov 28, 2011 9:29 am

Re: [SOLVED] Gallery-related fields and language problem

Post by velden »

Thanks. Fixed the error.
(M)
Forum Members
Forum Members
Posts: 118
Joined: Tue Mar 18, 2008 11:43 pm

Re: [SOLVED] Gallery-related fields and language problem

Post by (M) »

Partly it works with the above, but a problem occurs when gallery items been shown.

When choosing the {$imgTitle} (Title in the appropriate language) the URL changed from web address.com/nl/home.html into; webaddress.com/gallery/ gallerytilte/subgallerytitle/40.html

The used string $global_page_alias does not work anymore this way.
Is there a method to keep the URL: webaddress.com/nl/home.html ?

Or should I realize the solution to this problem in a different way?

With

Code: Select all

body id="{$global_page_alias}" 
i get a unique body id. Also when choosing a gallery item. How can I do something with that?
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3497
Joined: Mon Nov 28, 2011 9:29 am

Re: [SOLVED] Gallery-related fields and language problem

Post by velden »

Not sure if it will be easy to fix.

First I'd try to add an extra parameter to urls from within the Gallery template:

Code: Select all

{if $image->isdir}
    <a class="item" href="{$image->file}" title="{$image->titlename}"><img class="img-responsive" src="{$image->thumb|escape:'url'|replace:'%2F':'/'}?ref={$global_page_alias}" alt="{$image->titlename}" />
Then in the top of your (Gallery) template set:

Code: Select all

{if isset($smarty.get.ref)}{$global_page_alias=$smarty.get.ref}{/if}
Maybe it should be in another place (top of page template) and used with 'scope=global'.

Well, you should then think well of how you want urls to look like, and perhaps do some magic with smarty replace to generate pretty language specific module urls and use .htaccess to translate to a url parameter again.
I guess /nl/ makes more sense than /home/ to specify a language.
(M)
Forum Members
Forum Members
Posts: 118
Joined: Tue Mar 18, 2008 11:43 pm

Re: [SOLVED] Gallery-related fields and language problem

Post by (M) »

Thanx! but it don't work.
I add the extra parameter in the Gallery template.

Code: Select all

{if isset($smarty.get.ref)}{$global_page_alias=$smarty.get.ref 'scope=global'}{/if}
This in the page template en/or gallery template get no result.

In base there is one 'home'page per language and that's the Gallery for this website. I thought to do all the multi-language in the Gallery, not knowing of the URL change.
Post Reply

Return to “Modules/Add-Ons”