• Resolved Martina Maurer

    (@la-stria)


    Hey it’s me again

    As we already discussed in a differet topic I installed a WP network with currently 3 active languages (de_DE, ch_DE and ch_FR).

    Now when I display the flags for the other languages (which I think it’s really pretty) I get two German flags on the French site (because there is no Swiss German wordpress language installation) which is absolutely not pretty :((
    As well, when my coworkers from the French speaking part of Switzerland see the French flag, they won’t be happy… The problem is that our sites don’t just have different languages but also different language locations. Maybe sometime we will create an Austrian site too, therefore there will be three German flags ^^

    I know that the custom flag path still needs the same filename of the language (de.png / fr.png) but there must be a hack to bypass that…

    Or could I create a custom language file for the two Swiss languages and the plugin would understand the difference?

    http://wordpress.org/plugins/multisite-language-switcher/

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Dennis Ploetner

    (@realloc)

    I believe that the language codes are de_DE, de_CH, fr_CH… Anyway, yesterday I had to work on a similar problem and I created a solution for that, so you could start with this snippet:

    class MslsFlexibleLink extends MslsLink {
        protected $format_string = '<img src="{src}" alt="{alt}"/>';
        public function __toString() {
            $path = get_template_directory_uri() . '/alternative-flags/';
            $temp = $this->get_arr();
            $this->format_string = str_replace( '{alt}', $temp['txt'] );
            if ( 'de_CH' != $temp['alt'] ) {
                return str_replace( '{src}',  $path . 'de_CH.png', $this->format_string );
            }
            return str_replace( '{src}',  $path . 'de_DE.png', $this->format_string );
        }
    }
    function get_flexible_link( $display ) {
        return new MslsFlexibleLink();
    }
    add_filter( 'msls_link_create', 'get_flexible_link' );

    With something like this you can than going to create your own flag-directory (which resides in the directory of the current theme) and store there the flags ‘de_DE.png’ and ‘de_CH.png’. The rest is up to you.

    Let me know if this helps.

    Cheers,
    Dennis.

    Thread Starter Martina Maurer

    (@la-stria)

    Thank you for the snippet.

    When I print_r($temp['alt']) I get following arrays for the three launguages:
    [txt] => ancotech GmbH Deutschland [src] => http://ch-fr.ancotech.com/wp-content/plugins/multisite-language-switcher/flags/de.png [alt] => de_DE

    [txt] => ancotech AG Schweiz [src] => http://ch-fr.ancotech.com/wp-content/plugins/multisite-language-switcher/flags/de.png [alt] => de_DE

    [txt] => anotech SA Suisse [src] => http://www.ancotech.de/wp-content/plugins/multisite-language-switcher/flags/fr.png [alt] => fr_FR

    There are no yx_CH languages, otherwise there wouldn’t be a problem -.- So I changed the ‘txt’ of each language (de-de, ch-de and ch-fr) and ajusted the code:

    class MslsFlexibleLink extends MslsLink {
        protected $format_string = '<img src="{src}" alt="{alt}" />';
        public function __toString() {
          $path = get_stylesheet_directory_uri() . '/images/flags/';
          $temp = $this->get_arr();
          $this->format_string = str_replace( '{alt}', $temp['txt'], $this->format_string );
          // echo $temp['alt'];
    
          if ( 'ch-de' == $temp['txt'] ) {
            return str_replace( '{src}',  $path . 'ch-de.png', $this->format_string );
          } else if ('ch-fr' == $temp['txt']) {
            return str_replace( '{src}',  $path . 'ch-fr.png', $this->format_string );
          } else if ('hu-hu' == $temp['txt']) {
            return str_replace( '{src}',  $path . 'hu-hu.png', $this->format_string );
          }else {
            return str_replace( '{src}',  $path . 'de-de.png', $this->format_string );
          }
        }
    }
    function get_flexible_link( $display ) {
        return new MslsFlexibleLink();
    }
    add_filter( 'msls_link_create', 'get_flexible_link' );

    This works for now 🙂

    While testing the snippet I found another problem 🙁 I can’t assign a page of the same language. e.g. If I connect a ch-de page to a de-de page, it won’t happen (here is only ch-fr connected but de-de not). Same happens the other way round (connect de-de to ch-de). When trying to make the connections from ch-fr it makes some strange things with the form (one field remains empty) but sometimes both sites are correctly connected (both sites are ok here vs. de-de is correct connected but the ch-de page is not the one I wanted)

    I don’t get it. Maybe it’s better to just make connections between ch-de and ch-fr and deactivate de-de.

    Plugin Author Dennis Ploetner

    (@realloc)

    I would go to /wp-content/languages and copy the files de_DE.mo + de_DE.po to de_CH.mo + de_CH.po. After that you can edit these with poEdit and activate German (Switzerland) in the General Settings.

    Thread Starter Martina Maurer

    (@la-stria)

    Ok, that’s completely new for me.

    I’ve copied de_DE.mo and de_DE.po, changed their names and uploaded them again in the same folder. I even put them into the ‘themes/<mytheme>/languages/’ folder but I don’t get ‘German (Switzerland)’ or anything like it as a language to select in WordPress.

    I don’t know what to change in the .po file with poEdit. I changed the Settings (Alt + Enter) > Project Name (German (Switzerland)) and Settings (Alt + Enter) > Language (de_CH), but this didn’t do the trick. I deleted de_CH.mo and saved de_CH.po again for a new compilation for the .mo file. Uploaded this again on the two folders but nothing changed -.-

    I’m sorry to disturb you with that 🙁

    Plugin Author Dennis Ploetner

    (@realloc)

    Yes, you’re right. This doesn’t work. Maybe this thread could be helpful: http://wordpress.stackexchange.com/questions/114461/how-to-use-both-british-and-american-english

    Thread Starter Martina Maurer

    (@la-stria)

    Thank you soo much! This was the final step.

    For everyone who’ll have a similar problem, here is my complete code to add two new languages with custom flags.

    functions.php

    if(class_exists('MslsLink')): // if the plugin isn't activated on all sites
      class MslsFlexibleLink extends MslsLink {
        protected $format_string = '<img src="{src}" alt="{alt}" />';
        public function __toString() {
          $path = get_stylesheet_directory_uri() . '/images/flags/'; // change get_stylesheet_directory_uri to get_template_directory_uri if you're not working with Child Themes
          $temp = $this->get_arr();
          $this->format_string = str_replace( '{alt}', $temp['txt'], $this->format_string );
    
          switch($temp['alt']){ // add your needed languages here
            case 'de_CH':   return str_replace( '{src}',  $path . 'ch-de.png', $this->format_string ); break;
            case 'fr_CH':   return str_replace( '{src}',  $path . 'ch-fr.png', $this->format_string ); break;
            case 'de_DE':   return str_replace( '{src}',  $path . 'de-de.png', $this->format_string ); break;
            case 'hu_HU':   return str_replace( '{src}',  $path . 'hu-hu.png', $this->format_string ); break;
            default:        return str_replace( '{src}',  $path . 'ch-de.png', $this->format_string ); break;
          }
        }
      }
    
      function get_flexible_link($display) {
        return new MslsFlexibleLink();
      }
      add_filter('msls_link_create', 'get_flexible_link');
    endif;
    
    // Use this to add more languages into the Settings-Dropdown
    function add_de_ch($output, $lang_files, $current) {
        array_unshift($output, '<option value="de_CH"'.selected($current, 'de_CH', false).'>'.__('Schweiz DE').'</option>');
        return $output;
    }
    add_filter('mu_dropdown_languages', 'add_de_ch', 10, 3);
    
    function add_fr_ch( $output, $lang_files, $current) {
        array_unshift($output, '<option value="fr_CH"'.selected($current, 'fr_CH', false).'>'.__('Schweiz FR').'</option>');
        return $output;
    }
    add_filter('mu_dropdown_languages', 'add_fr_ch', 10, 3);

    The language files .mo and .po are in the normal language folder ‘/wp-content/languages/’

    Plugin Author Dennis Ploetner

    (@realloc)

    Very good!!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Custom Flags: Swiss German / German’ is closed to new replies.