I am using contextual filters on the /path/langcode view, where langcode is a contextual filter. How can I get langcode in a template file?
You can get the contextual filter argument from the route match:
$variables['arg_0'] = \Drupal::routeMatch()->getParameter('arg_0');
Usually the route parameters of contextual filters are named
arg_1 etc. If it doesn't work, check the route definition of this View page with Devel (/devel/routes) or Drupal Console.
Dependent on the Twig template you might need to add a cache context as well:
$variables['#cache']['contexts'] = 'route';