We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 25429
    • 32 Posts
    How do I go about refreshing the cache, setting the cultureKey and refreshing page when clicking a link? It would be extremely useful for using the snippet l10nTag.
      • 4172
      • 5,888 Posts
      you can set the cultureKey with a plugin at the system-event OnInitCulture

      this is part of a plugin I'm working on currently, which does switch the cultureKey and siteUrl, depending on different URLs
          if (!empty($_REQUEST['cultureKey'])) {
              $_SESSION['cultureKey'] = $_REQUEST['cultureKey'];
          }
      
          //$modx->setOption('original_site_url', $modx->getOption('site_url'));
          if (!empty($_SESSION['cultureKey'])) {
              $modx->setOption('cultureKey', $_SESSION['cultureKey']);
              //$modx->setOption('site_url', $modx->getOption('site_url') . $_SESSION['cultureKey'] . '/');
              //$modx->config['site_url'] = $modx->getOption('site_url') . $_SESSION['cultureKey'] . '/';
          }
      


      you will need to call everything, what is translated uncached.
      But you can use the getCache - snippet, for example, to build caches for every language.
      [ed. note: Bruno17 last edited this post 10 years, 3 months ago.]
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 25429
        • 32 Posts
        Thank you. I will try and figure out how I can use this. Can you tell me how I trigger OnInitCulture with a link?
          • 4172
          • 5,888 Posts
          OnInitCulture is invoked on every request. You just need to create a plugin and check the system-event-checkbox for OnInitCulture
            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 25429
            • 32 Posts
            Okay, but how do I set the cultureKey with a link if I want the same page to be served so that the snippet l10nTag can display the new language specific items (menu, headers etc) without changing the URL and sending the visitor to a different page? Thank you for clarifying!
              • 4172
              • 5,888 Posts
              you will need to send the cultureKey with the link, for example:

              <ul>
              <li><a href="[[~[[*id]]? &cultureKey=`en`]]">English</a></li>
              <li><a href="[[~[[*id]]? &cultureKey=`de`]]">Deutsch</a></li>
              </ul>
                -------------------------------

                you can buy me a beer, if you like MIGX

                http://webcmsolutions.de/migx.html

                Thanks!
                • 25429
                • 32 Posts
                This is great. I am going to report back on the result.
                  • 4172
                  • 5,888 Posts
                  I think you will not want to change your site_url, so I did comment that line out now
                    -------------------------------

                    you can buy me a beer, if you like MIGX

                    http://webcmsolutions.de/migx.html

                    Thanks!
                    • 25429
                    • 32 Posts
                    @Bruno17

                    This is absolutely flawless. Works like a charm. Many thanks! laugh

                    I needed this for a website where the editor posts blog entries and photo galleries in multipe languages on a daily bases, but does not want to devote separate sections of the website for users with given languages. Now a switch replaces all menu items and such. Great.