Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem - One Page Theme with i18n Multiple Languages
#1
Hi all

1.    I have an existing normal Multi–Page theme which supports multiple languages (i18n plugin) and works fine, and I am in the process of converting this to a One-Page design.  But on attempting to do so I have a few problems mainly to do with working with multiple languages.. I’d appreciate any help to sort these problems  …   

2.    For the One page design I have the following general requirements

a.    A One Page solution, where all the separate pages in the backend are concatenated together into one page in the frontend, but each with an anchor tag. Each frontend menu item is an anchor href to each of these anchor tags.
b.    Just a single level frontend menu.
c.    Multi language .. with plugin i18n/i18n _base from mvlcek.  
d.    Gallery  .. with plugin I18N Gallery from mvlcek ..  also works with multi langs for the captions
e.    Contact form

3.    I have seen the solution by Carlos  here    … and have based my design on this so thanks to Carlos for that  ..  

4.    I have created the following code and placed it in file functions.php, and placed this  in my theme directory. I  Have not touched the template.php file, that is, for the content it has the standard  <?php get_page_content();  ?>

functions.php :  
Code:
<?php if(!defined('IN_GS')){ die('you cannot load this page directly.'); }

  $content = '';

  global $pagesArray;
  $pagesSorted = subval_sort($pagesArray,'title'); // or 'title', 'menu', 'url', ...

  foreach ($pagesSorted as $page)
  {
     //  Get the language of this page
     // -----------------------------
     $page_slug = $page['url'];

     // Get the position of the language suffix separator
     $lang_sep_pos = strpos($page_slug, '_');

     if ($lang_sep_pos != false)   {
        $page_lang = substr($page_slug, $lang_sep_pos + 1);
        $page_slug_base = substr($page_slug, 0, $lang_sep_pos);
     }
     else {
        $page_lang =  substr($LANG, 0,2);  // The default lang ..  eg extract the 'en' from the 'en_US'
        $page_slug_base = $page_slug;
     }

     // Now have the page language in $page_lang, eg 'en', or 'de'
     // So pull into a list those pages in the set language
     // -------------------------------------------------------



     // NOTE, for now just compare with a fixed string, and not $language  ..
     // as this does not seem to be accessable from here
     if ($page_lang == 'de')  {

        // NOW output the selected page
        // -----------------------------
        if ($page_slug_base !='index' &&  $page['menuStatus']=='Y') {
           $content .= '
           <a name="'.$page_slug_base.'"></a>
           <div class="pagecontent '.$page_slug.' ">
           '.returnPageContent($page_slug).'
           </div>
           ';
        }

     }   // End if $page_lang                      
  }  // end of for each

 


5.    Firstly I have placed the code in the functions.php file  instead of directly in the template.php file (using echoes instead of $content concatenate),  so that  the placeholder for %gallery( .. )%  works  .. as Carlos explains   .. I guess this is because the Gallery plugin then operates upon the contents of  $content by replacing the %gallery( )% tag with the desired content before being sent to the browser  ….

6.     … But I have  a few problems   … generally related  to the multi-lang :
 
a.    Sort order with ‘menuOrder’ .. 

i.   PROBLEM  : In array $pagesArray we have the page descriptors for ALL pages, ie in my case all pages in English  and all in German.  To display just the pages in the site selected language  I  filter  out those pages from  $pagesArray.  But I would like to first  sort all  wrt the ‘menuOrder’ key value.  For the English (default lang) pages this is all good.  But for the German pages this does not work … the reason ..  I quickly echoed out all the menuOrder key values and all those for the German  pages are NOT assigned .. they are all just 0. Those for the English pages are  good , they are set to 0, 1 ,2, 3, etc acc menu order.   So …
    
ii.    As a workaround I could copy the default lang menuOrder values to the other pages, using the base of the slug name as a match  .. but this is messy

iii.    QUESTION : So is there a better workaround ?  or can ‘menuOrder’ be properly rectified at source  for mult-langs ? 

iv.    As a temporary solution I am sorting on Title, by manually adding in the backend  a digit prefix to the page title to sort on. I then do not display the title in the output, but instead add a header directly in the content              
             
b.    Array $pagesArray contains all pages for all languages


i.    This is not really a problem, but so that I can display only those pages in the selected language, in the functions.php file I have implemented my own solution ..  by extracting the lang suffix off the end of the slug and comparing this with  the set language (also a problem with this see next point) ,


ii.    QUESTION :   ..  but is there a way to avoid this ?  … ie Is there  (already) a better / handier way to pull out pages of just the selected lang    …


c.    Fetching the selected language

i.    When I put my code directly in the template.php file, then var $language contains the set language   .. which I need to extract and display only those pages in that language from array $pagesArray.

ii.    PROBLEM / QUESTION : But in functions.php it looks like var $language IS NOT SET   ..  is it that the setting of  $language has not happened yet ?  .. So has anyone any idea how I access the set language from functions.php ?   ..

iii.    As a temporary measure in the code I have just fixed  the set lang to either ‘en’ or ‘de’ .. just to check the rest of the code is working  

d.    i18n Gallery plugin multi-language display

i.    PROBLEM  : When I set the website language to German, and then open the gallery, captions display in  the WRONG language, ie English (the default lang) . If I revert the site to a normal Multi page form  ( ie remove the functions.php file and revert in the backend  custom Permalink structure back to the default ) , then everything works fine .. the captions are displayed in the set lang , eg German

ii.    So there seems to be a timing / order problem  ..   in functions.php the var $content is completed. Then after functions.php has finished running, the %gallery()% tag(s) are replaced with the desired code .. but  the wrong  language  file is loaded at this time or the correct one has be incorrectly overwritten  .. .. or something ..          

iii.    QUESTION :   So can someone help me with this   ?



Many thanks to anyone who can help …

Aldebaran
Reply
#2
(2015-11-10, 22:35:27)aldebaran Wrote: Hi all

1.    I have an existing normal Multi–Page theme which supports multiple languages (i18n plugin) and works fine, and I am in the process of converting this to a One-Page design.  But on attempting to do so I have a few problems mainly to do with working with multiple languages.. I’d appreciate any help to sort these problems  …  

2.    For the One page design I have the following general requirements

a.    A One Page solution, where all the separate pages in the backend are concatenated together into one page in the frontend, but each with an anchor tag. Each frontend menu item is an anchor href to each of these anchor tags.
b.    Just a single level frontend menu.
c.    Multi language .. with plugin i18n/i18n _base from mvlcek.  
d.    Gallery  .. with plugin I18N Gallery from mvlcek ..  also works with multi langs for the captions
e.    Contact form

...

6.     … But I have  a few problems   … generally related  to the multi-lang :
 
a.    Sort order with ‘menuOrder’ .. 

Use I18N functions instead of the $pagesArray, e.g. get_i18n_structure().

(2015-11-10, 22:35:27)aldebaran Wrote: c.    Fetching the selected language

It should be available in $language during execution of the template.

(2015-11-10, 22:35:27)aldebaran Wrote: d.    i18n Gallery plugin multi-language display

Using the I18N OnePage plugin the multi-language features of the gallery should work.
I18N, I18N Search, I18N Gallery, I18N Special Pages - essential plugins for multi-language sites.
Reply




Users browsing this thread: 1 Guest(s)