Thread Rating:
  • 3 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Support for multilanguage sites, Internationalization (I18N)
@mvlcek please, can you check it ? I'm stuck with this for a long time. When I disable i18n pages can be saved, but when enabled, it throws this errors and stays on changedata.php .. I tried saving that page in error (with success without i18n) but after enabling plugin, I get same error (and if it's not for this page, it's for another page..)

Code:
PHP Fatal error: Call to a member function addChild() on a non-object in /nfsmnt/hosting2_1/3/7/3776058b-7482-4c55-b5cc-bac5ad38cd70/example.com/test/plugins/i18n_navigation/save.php on line 18
PHP Warning: simplexml_load_file(): I/O warning : failed to load external entity "/nfsmnt/hosting2_1/3/7/3776058b-7482-4c55-b5cc-bac5ad38cd70/example.com/test/data/pages/zaruky-a-reklamacie.xml" in /nfsmnt/hosting2_1/3/7/3776058b-7482-4c55-b5cc-bac5ad38cd70/example.com/test/plugins/i18n_navigation/save.php on line 15
Reply
Hi,

I need help...

PHP Code:
<?php

# get correct id for plugin
$pluginName=basename(__FILE__".php");

# add in this plugin's language file
global $language;
i18n_merge($pluginName) || i18n_merge($pluginName$language); // this is not working... it's returning nothing

# some stuff here...

function get_translation($field) {
    global 
$pluginName$language;
    
i18n_merge($pluginName) || i18n_merge($pluginName$language); // <-- here $language is visible and returning correct value for current language
    
return i18n($pluginName '/' $field);
}

?>
I would like to load the corresponding language only once... not on every function call. Why $language variable is not visible when it's placed globally in file? Sorry if this is obvious but I'm not php developer...

When do this variable get set? Seems like really late that's why I can't access its value...
Reply
(2015-10-02, 06:24:03)ghoscik Wrote: When do this variable [$language] get set? Seems like really late that's why I can't access its value...

The variable $language is not yet set, when the plugin is loaded. Only after all plugins are loaded - just before the page is rendered - the plugin can determine the page and set the variable.

The solution is to lazily load the translations:
PHP Code:
...
$translation_initialized false;

function 
get_translation($field) {
    global 
$pluginName$language$translation_initialized;
    if (!
$translation_initialized) {
        
i18n_merge($pluginName) || i18n_merge($pluginName$language);
        
$translation_initialized true;
    }
    return 
i18n($pluginName '/' $field);
}
?>
I18N, I18N Search, I18N Gallery, I18N Special Pages - essential plugins for multi-language sites.
Reply
Wohoo, that's great thanks!

Just one BUT, can I do this here?

PHP Code:
<?php
$thisfile
=basename(__FILE__".php");

# add in this plugin's language file
i18n_merge($thisfile'INSERT HERE - global $language value');

# ...

function get_translation($field) { ... }

?>

and don't use i18n_merge() in function body?
Reply
Hi

I use
PHP Code:
<?php get_i18n_navigation(return_page_slug(),0,99,I18N_SHOW_LANGUAGE); ?>    
// Select language
 <?php $languages return_i18n_available_languages(); ?>
      <?php foreach ($languages as $language) { ?>
      <li  style="float:right"><a href="<?php echo htmlspecialchars(return_i18n_setlang_url($language)); ?>"><?php echo $language?></a></li>
      <?php ?>

To display only those menu entries that are available in the current language...

sample page menu
DE > home page1 page2 page3 page4
PL > home page1 page2 (page3 and page4 are not avaible in the PL language)

When choosse in menu the DE language and next Pl language , menu show correct in Pl language:
home page1 page2

When choosse in menu sample the (DE) page2 and next choosse language Pl , show not correct menu in Pl language
PL > home page1 page2 page3 page4 page3 and page4 are not avaible in PL language.
Reply
hello @mvlcek,
Mirin your work and support here.
I have used your plugins before and worked great. It still is but there is a little weird bug i have encountered yesterday:

Heres the hierarchy:
-index
-page1
--item1
...
--item6
-page2
-page3

top-level links are on the navbar, 2nd level links are on the sidebar.

problem is, using <?php get_i18n_navigation('page1',1,9); ?> on the sidebar for showing the links no matter which page, links dont get the "current" class.
using <?php get_i18n_navigation(return_page_slug(),1,9); ?> works just like it should be.

Weird part is; i used same code with same plugins on another project about 3 months ago and haven't encountered this, no problems with that one. I'm travelling back and forth between two yet unable to identify the problem.

Got any suggestions?

Visual
Reply
Bug 
Quote:Warning: simplexml_load_file(): I/O warning : failed to load external entity "site/data/pages/other.xml" in site/plugins/i18n_navigation/save.php on line 15


Notice: Trying to get property of non-object in site/plugins/i18n_navigation/save.php on line 16

Fatal error: Call to a member function addChild() on a non-object in site/plugins/i18n_navigation/save.php on line 18

@mvlcek Huh

happens always with I18N plugin enabled
Reply
Hello,

Lets assume that we have menu like

Main   Team   About   Contact

Main Team About Contact is a top level menu, About has children menu but I would like to place it before contacts

Is it possible to show first 2 (Main and Team) by any command like

<?php get_i18n_navigation(return_page_slug()); ?>

and then show about submenu by

<?php get_i18n_navigation('about',1,99); ?>

then show Contact with command like

<?php get_i18n_navigation(return_page_slug()); ?>
Reply
if you want to show child element beside root element, it becomes root element too, right ? so why your submenu items aren't put in root menu, so you can arrange it and show it like you want ?

if you still want them in submenu, you can use CSS to style submenu and items inside to be shown beside parent element and have the same size etc. so it will all look like parent links
Reply
(2015-10-22, 08:20:31)morvy Wrote: if you want to show child element beside root element, it becomes root element too, right ? so why your submenu items aren't put in root menu, so you can arrange it and show it like you want ?

if you still want them in submenu, you can use CSS to style submenu and items inside to be shown beside parent element and have the same size etc. so it will all look like parent links

Because now this sub-menu (About) is a separate <li> element in CSS with its CSS class and manipulated by JavaScript to show animated sub-menu by clicking on About.
Reply
sorry, I don't get it. so none of those solutions are acceptable for you ?
Reply
(2015-10-25, 23:16:47)morvy Wrote: sorry, I don't get it. so none of those solutions are acceptable for you ?

No, now I use this code but I can't move submenu from the end of top level menu

<nav id="main-menu" class="level-0">

<ul>
    <?php get_i18n_navigation(return_page_slug()); ?>
       <li class="menu-item-has-children"><a href="about">About</a>
   <ul class="sub-menu">
       <?php get_i18n_navigation('about',1,99); ?>
   </ul>
      </li>
</ul> 

<div class="close-button"></div>
</nav>
Reply
Hi Mvlcek or anyone that can help   

I posted here in the Themes forum some questions about doing a One  Page  theme with support for multiple langs    ..   I’m not sure if that was the right place  to post  .. ..

For this I’m using your i18n plugin  and  your I18n Gallery plugin .. I’ve  then written some code (see post) and put it in my-theme/functions.php, which extracts and stacks all backend pages together pulling them from the array $pagesArray, as per post from Carlos here.

My basic questions are  :

1.    Why can’t I access from file functions.php the set language defined in var $language  ? Is it not set yet ?   .. without this I can’t extract the pages for the set language.  Or is there another way ?

2.    The key menuOrder in $pagesArray appears only to be set for the pages in the default lang, but not for any other langs  …  Do you know why ?     ..  So I can't sort and display the pages on menu order.  Or is there another way ?    

3.    I18n Gallery plugin :  I am using the  %gallery(..)% syntax in he backend page text   ..  the caption language is only ever in the default  lang, and not the set lang. Any idea  how I can get around this ?

Appreciate any help

Aldebaran
Reply
Hey aldebaran,

I'll try to answer your first question:

Plugin authors (ideally) define plugin hooks you can hook into in order to execute your functions at a specified time.
In I18N, there's a plugin hook called theme-header (which is by the way also a default hook), which accesses the $language var (so you can be sure to access it if you hook into it). Note that you if you echo something, it will be outputted in the page's <head>.

Basically, do something like this (untested):

PHP Code:
<?php 
   
function your_function() {
     global 
$language;
     
// do something based on $language;
   
}
   
   
add_action('theme-header''your_function');
?>
Reply
(2011-07-17, 20:11:02)Connie Wrote: I need a css for the styling in IE, as the menue does not show the same as in other browsers,

[Image: ie8.jpg]

please see here
[Image: firefox5.jpg]

maybe somebody of you has a working css for the IE?

Thanks in advance,

Connie
my adds:
CSS, unfortunately, is not compatible with all browsers, you need to check code for each browser. I always check code in Mozilla Firefox, Google Chrome, Opera, Internet Explorer (v11), Safari. if it works in all, I mean it is great! unless. you have to combine. NO Feature or compilers. If they are paid and automatic ... never give 100% guarantees compilation and compliance with the standard css ...
user plugin: scroll to top
Reply
(2015-11-19, 10:26:30)Tyblitz Wrote: Hey aldebaran,

I'll try to answer your first question:

Plugin authors (ideally) define plugin hooks you can hook into in order to execute your functions at a specified time.
In I18N, there's a plugin hook called theme-header (which is by the way also a default hook), which accesses the $language var (so you can be sure to access it if you hook into it). Note that you if you echo something, it will be outputted in the page's <head>.

Basically, do something like this (untested):



PHP Code:
<?php 
   
function your_function() {
 
    global $language;
 
    // do something based on $language;
 
  }
 
  
   add_action
('theme-header''your_function');
?>

Hi Tyblitz
 
Thanks for your help   .. That’s pointed me in a better direction  !
 
Yes, you can only access a variable, here $language, after it is set/ available  … obviously !    
 
As said, I am wanting to use the functions.php file to concatenate all backend pages together but only for the set language, and then output this in the normal content area of the template, ie within the <body>   ..   
 
I am doing this at the moment by simply running the code directly from within the file  … But this is WRONG  ..  It will run at the point where the file is imported, but I do not know  / it is not defined where this import occurs. So there is no guarantee about the state of any variables at this point  ..      
 
But in the GS wiki about theme creation it does say that you can define a file functions.php to put in any custom functions that you can then call from your theme.  It says that functions.php is then imported before the start of template output   .. so you are then free to call any function defined in the file from the template.
 
So that is what I will do  .. over the weekend …  Declare a function in functions.php to concatenate all the pages into $content, and then call it instead of the normal get_page_content() from my template  at a point where the content should go as normal and  where variable $language will also be available. I will then still need to call get_page_content() to apply to the new $content any actions and filters from  plugins as normal   
 
Cheers Aldebaran
Reply
how to add a default option to: show all pages
https://dl.dropboxusercontent.com/u/4998...lpages.jpg
i want always for all users do this (show all pages default - without a clicking to plus button") it's possible?
user plugin: scroll to top
Reply
I believe I have found a bug.

If your page name contains a underscore "_", the Custom URL (Slug): input box crashes after trying to save. If you have the underscore, returning to "options+" causes other input boxes to crash.

The workaround is change underscores to dashes "-".

The fix would be to figure out why it does not like underscores, or replace underscores with dashes before saving the page data.

Thanks for the hard work Smile
[Image: crash.png]
Thanks,
jwzumwalt
(\__/)
(='.'=)
(")_(")
Reply
i18n plugin uses this underscore "_" to determine the language
Reply
I18N Version 3.3:
  • supports sorting by title in hierarchical pages view - "by title" and "hierarchical" buttons are now basically toggle buttons (@bensayers).
I18N, I18N Search, I18N Gallery, I18N Special Pages - essential plugins for multi-language sites.
Reply
mvlcek, you forgot to specify the version 3.3 of the file i18n_navigation.php
Reply
(2016-02-16, 10:30:11)Oleg06 Wrote: mvlcek, you forgot to specify the version 3.3 of the file i18n_navigation.php

Thank you, corrected in 3.3.1
I18N, I18N Search, I18N Gallery, I18N Special Pages - essential plugins for multi-language sites.
Reply
Ok, it was just a mistake!
(I tried to update 3 times... Big Grin )

Thx!
__
Contact me if you need a french translation file for your plugin.
Reply
Hey, I looked around a little but couldn't find anything on it.

How would one go about using 2 separate Tlds/domains (helgesverre.no and helgesverre.com) to determine the language of the page, both domains should be pointing to the same CMS instance, but should display the content in different languages depending on which domain it is.

Any help with this would be appreciated Smile
Web Developer
Plugins: GS Plugin Installer | Referrer Blocker | Password Protect
Reply
@HelgeSverre what about plugin that will check domain name and define language / replace constant ?
Reply




Users browsing this thread: 13 Guest(s)