code: @Override
      public Locale getLocaleForResource(CmsObject cms, CmsResource resource, List<Locale> availableLocales) {
  
          Locale result;
          List<Locale> defaultLocales = OpenCms.getLocaleManager().getDefaultLocales(cms, resource);
          List<Locale> locales = availableLocales;
          if ((locales == null) || (locales.size() == 0)) {
              locales = defaultLocales;
          }
          result = OpenCms.getLocaleManager().getBestMatchingLocale(getLocale(), defaultLocales, locales);
          return result;
      }
docs: Returns the language locale for the given resource in this index.<p>
  
  @param cms the current OpenCms user context
  @param resource the resource to check
  @param availableLocales a list of locales supported by the resource
  
  @return the language locale for the given resource in this index