We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 40358
    • 40 Posts
    Hello.

    We are making an app that is sending push notifications via Modx. We handle all our internationalization using lexicons. It worked perfectly up to right about now because we have a case where we have to load multiple changes when pushing the notifications, and parsing the message based on the language for each user.

    Say user1 has lang = no and user2 has lang = en.

    How to you make it possible to send fetch lexicon entries for both languages and then get the matching string? When I try to use it in my snippets, it always defaults to english.

    // Loading
    $modx->getService('lexicon', 'modLexicon');
    $modx->lexicon->load('lang:notifications');
    
    // Trying to parse (does not work)
    $msg = $modx->lexicon('lang.title_newmessage', array('language' => $user_language));
      • 18373 ☆ A M B ☆
      • 3,141 Posts
      $modx->lexicon->load('language:namespace:topic')


      should do the trick.. e.g.
      $modx->lexicon->load('es:myapp:notifications');
      $msg = $modx->lexicon('notification_newmessage');


      Alternative, this should also work by specifying the language as the third param:

      $msg = $modx->lexicon('notification_newmessage', array('param' => 'value'), 'es');
        Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

        Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
        • 40358
        • 40 Posts
        Ah, passing it as the third param was what I wanted. I also guess there is no built in way to load all languages for a given namespace? I guess I could just open the lexicon-directory for the namespace and find all languages and loop the load-method from there.
          • 40358
          • 40 Posts
          Btw, I solved it like this:

          $languages = array_filter(glob($modx->getOption('core_path') . 'components/lang/lexicon/*'), 'is_dir');
          foreach($languages as $full_lang_path) {
          	$path_split = explode('/', $full_lang_path);
          	$lang = $path_split[count($path_split) - 1];
              $modx->lexicon->load($lang . ':lang:notifications');
          }