Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter SimonSimCity

    (@simonsimcity)

    Here’s a patch-file of what I did:

    Index: wp-content/plugins/zanto/classes/class.zwt-lang-switcher.php
    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
    ===================================================================
    --- wp-content/plugins/zanto/classes/class.zwt-lang-switcher.php	(revision )
    +++ wp-content/plugins/zanto/classes/class.zwt-lang-switcher.php	(revision )
    @@ -187,7 +187,10 @@
                     if(isset($ls_exclude_list[$trans_blog['blog_id']])){
     				   continue;
     				   }
    -                if (isset($translated_urls[$trans_blog['blog_id']])){
    +
    +                $is_missing = isset($translated_urls[$trans_blog['blog_id']]);
    +
    +                if ($is_missing){
                              $url = $translated_urls[$trans_blog['blog_id']];
     						 if(zwt_get_global_urls_info('lang_url_format', $trans_blog['blog_id'])==2){
     						    $url = $trans_network->add_url_lang($url, $trans_blog['blog_id'], 2);
    @@ -217,7 +220,7 @@
                     $country_flag_url = zwt_get_site_flags($trans_blog['lang_code']);
    
                     $zwt_ls_array[$trans_blog['lang_code']] = array('id' => $id, 'active' => $active, 'encode_url' => 0, 'native_name' => $native_name,
    -                    'language_code' => $language_code, 'translated_name' => $translated_name, 'url' => $url, 'country_flag_url' => $country_flag_url);
    +                    'language_code' => $language_code, 'translated_name' => $translated_name, 'url' => $url, 'is_missing' => $is_missing, 'country_flag_url' => $country_flag_url);
                     $id++;
                 }
                 unset($id);
    \ No newline at end of file
    Thread Starter SimonSimCity

    (@simonsimcity)

    The code I posted before also reports home-pages as untranslated … here’s a better approach:

    Index: wp-content/plugins/zanto/classes/class.zwt-lang-switcher.php
    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
    ===================================================================
    --- wp-content/plugins/zanto/classes/class.zwt-lang-switcher.php	(revision )
    +++ wp-content/plugins/zanto/classes/class.zwt-lang-switcher.php	(revision )
    @@ -187,13 +187,19 @@
                     if(isset($ls_exclude_list[$trans_blog['blog_id']])){
     				   continue;
     				   }
    -                if (isset($translated_urls[$trans_blog['blog_id']])){
    +
    +                $translation_exists = isset($translated_urls[$trans_blog['blog_id']]);
    +
    +                if ($translation_exists){
                              $url = $translated_urls[$trans_blog['blog_id']];
     						 if(zwt_get_global_urls_info('lang_url_format', $trans_blog['blog_id'])==2){
     						    $url = $trans_network->add_url_lang($url, $trans_blog['blog_id'], 2);
     						}
     					}
                     else {
    +                    if (is_front_page())
    +                        $translation_exists = true;
    +
                         if ((0==$this->ls_settings['skip_missing_trans'] && 0==$args['skip_missing']) || is_front_page()){ //link to home page
     					    $url = zwt_get_global_urls_info('site_url', $trans_blog['blog_id']);
     						$lang_url_format = zwt_get_global_urls_info('lang_url_format', $trans_blog['blog_id']);
    @@ -217,7 +223,7 @@
                     $country_flag_url = zwt_get_site_flags($trans_blog['lang_code']);
    
                     $zwt_ls_array[$trans_blog['lang_code']] = array('id' => $id, 'active' => $active, 'encode_url' => 0, 'native_name' => $native_name,
    -                    'language_code' => $language_code, 'translated_name' => $translated_name, 'url' => $url, 'country_flag_url' => $country_flag_url);
    +                    'language_code' => $language_code, 'translated_name' => $translated_name, 'url' => $url, 'translation_exists' => $translation_exists, 'country_flag_url' => $country_flag_url);
                     $id++;
                 }
                 unset($id);
    \ No newline at end of file

    Since graying out an option is more of a css/ color related thing, I thought it better to leave this as an implementation for those who opt for a custom language switcher theme.
    But I have included a filter to make this much easier, please see the
    ‘zwt_no_url’ filter in
    zanto\classes\class.zwt-lang-switcher.php on line 208

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Add option to differ between missing and existing language in lang-switcher’ is closed to new replies.