0

I have setup language and translation in Drupal8 that affects my URL for example

myurl.com/ru
myurl.com/us
myurl.com/fr

What I need to do if find out which country is being accessed so I can add a variable to the twig theme layer

This is the hook that is working fine

/**
 * Implements hook_preprocess_HOOK() for menu.html.twig.
 */
function pnc_preprocess_menu(&$variables) {
    $code_to_access_language_url = 'this is a test';
    kint($variables);
    $variables['access_translation'] = $code_to_access_language_url;
    //print $code_to_access_language_url;exit;
}

I have found that under kint() there a lot of public methods for translation but I am not sure how I access them or which one to access. I know I could regex the url, but there has to be a cleaner way to do it?

1
  • $languages = \Drupal::languageManager()->getLanguages(); – purencool Oct 3 '16 at 7:38
0

I found the answer myself.

if($variables['menu_name'] == 'navigation') {     
  $langcode = \Drupal::languageManager()->getCurrentLanguage()->getName();
  // Add the logic here.
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.