We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 45063
    • 40 Posts
    Hi,
    There is a huge problem with Lexicons in my modx project. I have few different contexts which points to different domains. Sometimes, users complaining about wrong text on some of these domains. For example, domain1 lexicon showing on domain2. Everythings fine after page refresh, but still, its a big problem. I use this gateway plugin (I put refreshCache everywhere I can to avoid this issue):

    <?php
    if ($modx->context->get('key') == 'mgr') {
            return;
    }
    
    $modx->cacheManager->refresh();
    
    switch ($_SERVER['HTTP_HOST']) {        
            case 'dev.domain1.com':
            case 'www.domain1.com':
            $modx->cacheManager->refresh();
            $modx->switchContext('web');
            break;
            case 'dev.domain2.com':
            case 'www.domain2.com':
            $modx->cacheManager->refresh();
            $modx->switchContext('context2');
            break;
    }


    I use lexicons like that:

    default.inc.php file:

    <?php
    switch ($_SERVER['HTTP_HOST']) {        
    case 'dev.domain1.com':
    case 'www.domain1.com':
    
    include_once 'lexicon1.php';
    break;
    
    case 'dev.domain2.com':
    case 'www.domain2.com':
    
    include_once 'lexicon2.php';
    break;
    
    }
    ?>


    Lexicon1 and 2.php contains simple lexicon entrys. But somehow, content is messing up from time to time.

    Any suggestions? Does $modx->cacheManager->refresh(); solves my problem?
      • 37110
      • 72 Posts
      For each context you have to add the setting cultureKey.
      Inside your lexicon directory you have all languages as subdirectories.

      lexicon/en/default.inc.php
      lexicon/nl/default.inc.php
      lexicon/de/default.inc.php
      lexicon/hu/default.inc.php

      MODX will load automatically the right lexicon for the right context.

      The problem you have the wrong lexicons is that MODX puts all the lexicons inside the cache.
        • 45063
        • 40 Posts
        Quote from: wiegers at Mar 18, 2014, 08:53 AM
        For each context you have to add the setting cultureKey.
        Inside your lexicon directory you have all languages as subdirectories.

        You are 100% right. Just figured out by myself. You see, I have three different sites, but all of them are in English. So, the there was one folder: lexicon/en/. And cultureKey was 'en' for all of them. My mistake. MODx watching for cultureKey and then, loads and caches it. When its cached - HTTP_HOST switch no longer working in default.inc.php. Hope this will solve my problem.
          • 37110
          • 72 Posts
          i don't know if its possible but maybe you could add some extra to the cultureKey

          context 1
          cultureKey = en-1

          context 2
          cultureKey = en-2

          context 3
          cultureKey = en-3

          And the directories

          lexicon/en-1/
          lexicon/en-2/
          lexicon/en-3/

            • 45063
            • 40 Posts
            Yep, I am already did that. And, by the way, $modx->cacheManager->refresh(); not needed anymore. Looks like now lexicons cached separately. Site performance went much smoothly now.