Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Try Vanilla Forums Cloud product

Change banner's language

Hello,

I'm starting a forum that will be used in more than one language. How can I serve a different banner depending on the locale used by the user ?
I installed the Multilingual plug-in and the french locales so far.

BTW: is it me or the forum doesn't detect the user's preferred language set in the web browser ?

Comments

  • peregrineperegrine MVP
    edited November 2015

    in vanilla 2.1 you could do this (perhaps the same thing if 2.2 doesn't change it for you).

    you could make a request on Github to make it translateable.

    you might be able to replace function with a bootstrap config file.

    or you request A core change via github ...

    to replace the Logo Function in /library/core/class.theme.php

    to (use the translation T )

       public static function Logo() {
          $Logo = C('Garden.Logo');
          if ($Logo) {
             $Logo = ltrim($Logo, '/');
             // Fix the logo path.
             if (StringBeginsWith($Logo, 'uploads/'))
                $Logo = substr($Logo, strlen('uploads/'));
          }
          // make it translateable below.
          $Title = T(C('Garden.Title', 'Title'));
          echo $Logo ? Img(Gdn_Upload::Url($Logo), array('alt' => $Title)) : $Title;
       }
    

    with the above change ....

    then you could change your config.php to

    $Configuration['Garden']['Title'] = 'BannerTitle';

    then you would need to add the definition to each of your locales

    e.g. in the French Locale

    $Definition['BannerTitle'] = "Ze Banner Title";
    

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

    vrijvlinder
  • peregrineperegrine MVP
    edited November 2015

    in vanilla 2.2 you could make a feature request for translation to be added to right side config statements similar to above since the function has changed.

    you could add a T before all of the C( functions
    and do something similar as above and change the respective config statement in config.php

    public static function logo($Properties = array()) {
            $Logo = C('Garden.Logo');
    
            if ($Logo) {
                $Logo = ltrim($Logo, '/');
    
                // Fix the logo path.
                if (stringBeginsWith($Logo, 'uploads/')) {
                    $Logo = substr($Logo, strlen('uploads/'));
                }
    
                // Set optional title text.
                if (empty($Properties['title']) && C('Garden.LogoTitle')) {
                    $Properties['title'] = C('Garden.LogoTitle');
                }
            }
    
            // Use the site title as alt if none was given.
            $Title = C('Garden.Title', 'Title');
            if (empty($Properties['alt'])) {
                $Properties['alt'] = $Title;
            }
    
            echo $Logo ? Img(Gdn_Upload::url($Logo), $Properties) : $Title;
        }
    

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

    jackmaessenvrijvlinderBleistivt
  • hgtonighthgtonight ∞ · New Moderator
    edited November 2015

    You could hook into the app startup, check the local and change the config option in memory.

    public function gdn_locale_afterSet_handler($sender) {
        switch ($sender->Locale) {
            case 'en':
                saveToConfig('Garden.Logo', 'english_logo.png', array('Save' => false));
                break;
            case 'fr':
                saveToConfig('Garden.Logo', 'french_logo.png', array('Save' => false));
                break;
            default:
                // do nothing
                break;
        }
    }
    

    Tested as working in 2.2. You will need to put your logos in the upload path, but this makes you not need to overwrite core files. You could also set the site title (Garden.Title) config based on the locale set.

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

    jackmaessenBleistivt
  • peregrineperegrine MVP
    edited November 2015

    Seems like if you are going to have a multilingual forum. Things should be translateable via locales and not need more plugins for the Title itself. Perhaps better in core. similar to issue a while back for need of user translateable categories.

    they were amenable here for categories:
    http://vanillaforums.org/discussion/28130/translating-category-names
    https://github.com/vanilla/vanilla/issues/2159
    https://github.com/vanilla/vanilla/commit/f476a4744303a34379989466a6c748c321b6bad8

    similar core change in future version of vanilla could be done for banners one would think.

    with regards to your logo image method, a good possiblity until core is amended.

    perhaps you could mitigate need for case statement

    (not tested).

    use same hook and replace entire switch with ...

    $localeAbbrev = $sender->Locale . "logo.png";
    saveToConfig('Garden.Logo', $localeAbbrev, array('Save' => false));

    then you wouldn't need revisit method to update when adding a new locale.

    and name all images

    frlogo.png
    enlogo.png
    logo.png - the default.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • Thank you all for all those solutions. I hoped I missed a configuration that would do that, I guess it's not that simple :)
    I'll try to ask for the feature on github, it's not very urgent and I don't really have time to dive into vanilla's code.

Sign In or Register to comment.