code: public static Locale getLocaleFromPath(String sitePath) {
  
          Locale result = null;
          if (sitePath.indexOf("/") == 0) {
              sitePath = sitePath.substring(1);
          }
          if (sitePath.length() > 1) {
              String localePrefix;
              if (!sitePath.contains("/")) {
                  // this may be the case for paths pointing to the root folder of a site
                  // check for parameters
                  int separator = -1;
                  int param = sitePath.indexOf("?");
                  int hash = sitePath.indexOf("#");
                  if (param >= 0) {
                      if (hash != 0) {
                          separator = param < hash ? param : hash;
                      } else {
                          separator = param;
                      }
                  } else {
                      separator = hash;
                  }
                  if (separator >= 0) {
                      localePrefix = sitePath.substring(0, separator);
                  } else {
                      localePrefix = sitePath;
                  }
              } else {
                  localePrefix = sitePath.substring(0, sitePath.indexOf("/"));
              }
              Locale locale = CmsLocaleManager.getLocale(localePrefix);
              if (localePrefix.equals(locale.toString())
                  && OpenCms.getLocaleManager().getAvailableLocales().contains(locale)) {
                  result = locale;
              }
          }
          return result;
      }
docs: Reads the locale from the first path element.<p>
  
  @param sitePath the site path with the locale prefix
  
  @return the locale or <code>null</code> if no matching locale was found